Skip to content

Commit a5430ca

Browse files
committed
Added tests for the iscoinspendable method
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
1 parent b4dec0c commit a5430ca

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/application/services/WalletService.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,34 @@ describe('WalletService Integration', () => {
7878
// Try to load a non-existent wallet
7979
await expect(WalletService.loadWallet('nonexistent')).rejects.toThrow('Wallet Not Found');
8080
});
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+
});
81111
});

0 commit comments

Comments
 (0)