@@ -78,4 +78,34 @@ describe('WalletService Integration', () => {
78
78
// Try to load a non-existent wallet
79
79
await expect ( WalletService . loadWallet ( 'nonexistent' ) ) . rejects . toThrow ( 'Wallet Not Found' ) ;
80
80
} ) ;
81
+
82
+ describe ( 'isCoinSpendable' , ( ) => {
83
+ const coinId = Buffer . from ( 'aabbcc' , 'hex' ) ;
84
+ let peer : any ;
85
+
86
+ beforeEach ( ( ) => {
87
+ peer = {
88
+ isCoinSpent : jest . fn ( ) ,
89
+ } ;
90
+ } ) ;
91
+
92
+ it ( 'should return true if peer.isCoinSpent resolves true' , async ( ) => {
93
+ peer . isCoinSpent . mockResolvedValue ( true ) ;
94
+ const result = await WalletService . isCoinSpendable ( peer , coinId ) ;
95
+ expect ( result ) . toBe ( true ) ;
96
+ expect ( peer . isCoinSpent ) . toHaveBeenCalledWith ( coinId , expect . any ( Number ) , expect . any ( Buffer ) ) ;
97
+ } ) ;
98
+
99
+ it ( 'should return false if peer.isCoinSpent resolves false' , async ( ) => {
100
+ peer . isCoinSpent . mockResolvedValue ( false ) ;
101
+ const result = await WalletService . isCoinSpendable ( peer , coinId ) ;
102
+ expect ( result ) . toBe ( false ) ;
103
+ } ) ;
104
+
105
+ it ( 'should return false if peer.isCoinSpent throws' , async ( ) => {
106
+ peer . isCoinSpent . mockRejectedValue ( new Error ( 'fail' ) ) ;
107
+ const result = await WalletService . isCoinSpendable ( peer , coinId ) ;
108
+ expect ( result ) . toBe ( false ) ;
109
+ } ) ;
110
+ } ) ;
81
111
} ) ;
0 commit comments