Skip to content

Commit

Permalink
Add a unit test for fetching addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed Jan 3, 2025
1 parent b5ccc96 commit 2009813
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
44 changes: 44 additions & 0 deletions test/core/currency/wallet/currency-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion test/fake/fake-currency-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ class FakeCurrencyEngine implements EdgeCurrencyEngine {
async getFreshAddress(
opts: EdgeGetReceiveAddressOptions
): Promise<EdgeFreshAddress> {
return { publicAddress: 'fakeaddress' }
return {
publicAddress: 'fakeaddress',
nativeBalance: this.state.balance.toString(),
segwitAddress: 'fakesegwit',
legacyAddress: 'fakelegacy'
}
}

async addGapLimitAddresses(addresses: string[]): Promise<void> {}
Expand Down

0 comments on commit 2009813

Please sign in to comment.