|
3 | 3 | type KeyringRequest, |
4 | 4 | type KeyringResponse, |
5 | 5 | KeyringClient, |
| 6 | + KeyringRpcMethod, |
6 | 7 | } from '.'; // Import from `index.ts` to test the public API |
7 | 8 |
|
8 | 9 | describe('KeyringClient', () => { |
@@ -84,6 +85,63 @@ describe('KeyringClient', () => { |
84 | 85 | }); |
85 | 86 | }); |
86 | 87 |
|
| 88 | + describe('getAccountBalances', () => { |
| 89 | + it('returns a valid response', async () => { |
| 90 | + const assets = ['bip122:000000000019d6689c085ae165831e93/slip44:0']; |
| 91 | + const id = '1617ea08-d4b6-48bf-ba83-901ef1e45ed7'; |
| 92 | + const expectedResponse = { |
| 93 | + [assets[0] as string]: { |
| 94 | + amount: '1234', |
| 95 | + unit: 'sat', |
| 96 | + }, |
| 97 | + }; |
| 98 | + |
| 99 | + mockSender.send.mockResolvedValue(expectedResponse); |
| 100 | + const balances = await keyring.getAccountBalances(id, assets); |
| 101 | + |
| 102 | + expect(mockSender.send).toHaveBeenCalledWith({ |
| 103 | + jsonrpc: '2.0', |
| 104 | + id: expect.any(String), |
| 105 | + method: `${KeyringRpcMethod.GetAccountBalances}`, |
| 106 | + params: { id, assets }, |
| 107 | + }); |
| 108 | + |
| 109 | + expect(balances).toStrictEqual(expectedResponse); |
| 110 | + }); |
| 111 | + |
| 112 | + it('throws an error because the amount has the wrong type', async () => { |
| 113 | + const assets = ['bip122:000000000019d6689c085ae165831e93/slip44:0']; |
| 114 | + const id = '1617ea08-d4b6-48bf-ba83-901ef1e45ed7'; |
| 115 | + const expectedResponse = { |
| 116 | + [assets[0] as string]: { |
| 117 | + amount: 1234, // Should be a `StringNumber` |
| 118 | + unit: 'sat', |
| 119 | + }, |
| 120 | + }; |
| 121 | + |
| 122 | + mockSender.send.mockResolvedValue(expectedResponse); |
| 123 | + await expect(keyring.getAccountBalances(id, assets)).rejects.toThrow( |
| 124 | + 'At path: bip122:000000000019d6689c085ae165831e93/slip44:0.amount -- Expected a value of type `StringNumber`, but received: `1234`', |
| 125 | + ); |
| 126 | + }); |
| 127 | + |
| 128 | + it("throws an error because the amount isn't a StringNumber", async () => { |
| 129 | + const assets = ['bip122:000000000019d6689c085ae165831e93/slip44:0']; |
| 130 | + const id = '1617ea08-d4b6-48bf-ba83-901ef1e45ed7'; |
| 131 | + const expectedResponse = { |
| 132 | + [assets[0] as string]: { |
| 133 | + amount: 'not-a-string-number', // Should be a `StringNumber` |
| 134 | + unit: 'sat', |
| 135 | + }, |
| 136 | + }; |
| 137 | + |
| 138 | + mockSender.send.mockResolvedValue(expectedResponse); |
| 139 | + await expect(keyring.getAccountBalances(id, assets)).rejects.toThrow( |
| 140 | + 'At path: bip122:000000000019d6689c085ae165831e93/slip44:0.amount -- Expected a value of type `StringNumber`, but received: `"not-a-string-number"`', |
| 141 | + ); |
| 142 | + }); |
| 143 | + }); |
| 144 | + |
87 | 145 | describe('filterAccountChains', () => { |
88 | 146 | it('should send a request to filter the chains supported by an account and return the response', async () => { |
89 | 147 | const id = '49116980-0712-4fa5-b045-e4294f1d440e'; |
|
0 commit comments