Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/bitcoin/bitcoind/bitcoindService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ describe('BitcoindService', () => {
mockProto.generateToAddress = jest.fn().mockResolvedValue(['blockhash1']);
});

// Adding Test case for selecting default wallet and not create a new one
it('should initialize the client with an explicit empty wallet path', () => {
Comment on lines 33 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test asserts wrong behavior

This test only verifies that BitcoinCore was constructed with wallet: '', but it doesn’t prove the reported multi-wallet issue is fixed (and it bakes in behavior that can be incorrect if the empty-name wallet doesn’t exist). As written, it will still pass even if wallet-scoped RPCs fail at runtime due to missing "" wallet. A more reliable test would mock listWallets() to return non-empty wallets and assert the service targets an actually-existing wallet, or assert that createDefaultWallet() is invoked/ensures the wallet exists before calling wallet-scoped RPCs.

bitcoindService.createClient(node);
// getInst() retrieves the first instance of BitcoinCore created
// We check if it was initialized with the 'wallet' property set to ''
expect(mockBitcoin).toHaveBeenCalledWith(
expect.objectContaining({
wallet: '',
}),
);
});

it('should create a default wallet', async () => {
mockProto.listWallets = jest.fn().mockResolvedValue([]);
await bitcoindService.createDefaultWallet(node);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bitcoin/bitcoind/bitcoindService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class BitcoindService implements BitcoinService {
host: `http://127.0.0.1:${node.ports.rpc}`,
username: bitcoinCredentials.user,
password: bitcoinCredentials.pass,
// default wallet to resolve multi-wallet conflict
wallet: '',
logger: this.log(),
// use a long timeout due to the time it takes to mine a lot of blocks
timeout: 5 * 60 * 1000,
Expand Down