diff --git a/packages/use-wallet/src/__tests__/wallets/kmd.test.ts b/packages/use-wallet/src/__tests__/wallets/kmd.test.ts index 4550d27e..b73b4578 100644 --- a/packages/use-wallet/src/__tests__/wallets/kmd.test.ts +++ b/packages/use-wallet/src/__tests__/wallets/kmd.test.ts @@ -407,4 +407,34 @@ describe('KmdWallet', () => { }) }) }) + + describe('getPassword', () => { + it('should return empty string password when set', async () => { + // Mock prompt to return empty string + global.prompt = vi.fn().mockReturnValue('') + + // First call to connect will set the empty password + mockKmd.listKeys.mockResolvedValueOnce({ addresses: [account1.address] }) + await wallet.connect() + + // Second call to connect should reuse the empty password + mockKmd.listKeys.mockResolvedValueOnce({ addresses: [account1.address] }) + await wallet.connect() + + // Prompt should only be called once + expect(global.prompt).toHaveBeenCalledTimes(1) + expect(mockKmd.initWalletHandle).toHaveBeenCalledWith(mockWallet.id, '') + }) + + it('should handle null from cancelled prompt', async () => { + // Mock prompt to return null (user cancelled) + global.prompt = vi.fn().mockReturnValue(null) + + mockKmd.listKeys.mockResolvedValueOnce({ addresses: [account1.address] }) + await wallet.connect() + + expect(global.prompt).toHaveBeenCalledTimes(1) + expect(mockKmd.initWalletHandle).toHaveBeenCalledWith(mockWallet.id, '') + }) + }) })