From 20098134812d505f27fbd0f5c391dcec10297b3f Mon Sep 17 00:00:00 2001 From: William Swanson Date: Fri, 3 Jan 2025 13:46:50 -0800 Subject: [PATCH] Add a unit test for fetching addresses --- .../currency/wallet/currency-wallet.test.ts | 44 +++++++++++++++++++ test/fake/fake-currency-plugin.ts | 7 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/test/core/currency/wallet/currency-wallet.test.ts b/test/core/currency/wallet/currency-wallet.test.ts index bdf69c36..c801bde8 100644 --- a/test/core/currency/wallet/currency-wallet.test.ts +++ b/test/core/currency/wallet/currency-wallet.test.ts @@ -83,6 +83,50 @@ describe('currency wallets', function () { expect(account.currencyConfig.fakecoin).equals(wallet.currencyConfig) }) + it('has addresses', async function () { + const { wallet, config } = await makeFakeCurrencyWallet() + await config.changeUserSettings({ balance: 30 }) + + expect(await wallet.getReceiveAddress({ tokenId: null })).deep.equals({ + legacyAddress: 'fakelegacy', + legacyNativeBalance: undefined, + nativeBalance: '30', + publicAddress: 'fakeaddress', + segwitAddress: 'fakesegwit', + segwitNativeBalance: undefined, + + nativeAmount: '0', + metadata: { + bizId: 0, + category: '', + exchangeAmount: {}, + name: '', + notes: '' + } + }) + + const addresses = (await wallet.getAddresses({ tokenId: null })).sort( + (a, b) => a.addressType.localeCompare(b.addressType) + ) + expect(addresses).deep.equals([ + { + addressType: 'legacyAddress', + nativeBalance: undefined, + publicAddress: 'fakelegacy' + }, + { + addressType: 'publicAddress', + nativeBalance: '30', + publicAddress: 'fakeaddress' + }, + { + addressType: 'segwitAddress', + nativeBalance: undefined, + publicAddress: 'fakesegwit' + } + ]) + }) + it('triggers callbacks', async function () { const log = makeAssertLog() const { wallet, config } = await makeFakeCurrencyWallet() diff --git a/test/fake/fake-currency-plugin.ts b/test/fake/fake-currency-plugin.ts index 0bb9bcc3..ae9c635a 100644 --- a/test/fake/fake-currency-plugin.ts +++ b/test/fake/fake-currency-plugin.ts @@ -254,7 +254,12 @@ class FakeCurrencyEngine implements EdgeCurrencyEngine { async getFreshAddress( opts: EdgeGetReceiveAddressOptions ): Promise { - return { publicAddress: 'fakeaddress' } + return { + publicAddress: 'fakeaddress', + nativeBalance: this.state.balance.toString(), + segwitAddress: 'fakesegwit', + legacyAddress: 'fakelegacy' + } } async addGapLimitAddresses(addresses: string[]): Promise {}