Skip to content

Commit

Permalink
fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Jul 9, 2024
1 parent 70efa36 commit 614ac52
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions src/__test__/e2e/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
fetchBip44ChangeAddresses,
fetchBtcLegacyAddresses,
fetchBtcSegwitAddresses,
fetchByDerivationPath,
fetchAddressesByDerivationPath,
fetchSolanaAddresses,
pair,
signBtcLegacyTx,
Expand All @@ -21,7 +21,7 @@ import {
} from '../../api';
import { HARDENED_OFFSET } from '../../constants';
import { BTC_PURPOSE_P2SH_P2WPKH, BTC_TESTNET_COIN } from '../utils/helpers';
import { dexlabProgram } from './signing/__mocks__/programs';
import { dexlabProgram } from './signing/solana/__mocks__/programs';
import {
addAddressTags,
fetchAddressTags,
Expand Down Expand Up @@ -200,65 +200,87 @@ describe('API', () => {
});
});

describe('fetchByDerivationPath', () => {
describe('fetchAddressesByDerivationPath', () => {
test('fetch single specific address', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/0");
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/0",
);
expect(addresses).toHaveLength(1);
console.log(addresses[0]);
expect(addresses[0]).toBeTruthy();
});

test('fetch multiple addresses with wildcard', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/X", {
n: 5,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 5,
},
);
console.log(addresses[0]);
expect(addresses).toHaveLength(5);
addresses.forEach((address) => expect(address).toBeTruthy());
});

test('fetch addresses with offset', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/X", {
n: 3,
startPathIndex: 10,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 3,
startPathIndex: 10,
},
);
console.log(addresses[0]);
expect(addresses).toHaveLength(3);
addresses.forEach((address) => expect(address).toBeTruthy());
});

test('fetch addresses with lowercase x wildcard', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/x", {
n: 2,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/x",
{
n: 2,
},
);
expect(addresses).toHaveLength(2);
addresses.forEach((address) => expect(address).toBeTruthy());
});

test('fetch addresses with wildcard in middle of path', async () => {
const addresses = await fetchByDerivationPath("44'/60'/X'/0/0", {
n: 3,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/X'/0/0",
{
n: 3,
},
);
expect(addresses).toHaveLength(3);
addresses.forEach((address) => expect(address).toBeTruthy());
});

test('error on invalid derivation path', async () => {
await expect(fetchByDerivationPath('invalid/path')).rejects.toThrow();
await expect(
fetchAddressesByDerivationPath('invalid/path'),
).rejects.toThrow();
});

test('fetch single address when n=1 with wildcard', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/X", {
n: 1,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 1,
},
);
expect(addresses).toHaveLength(1);
expect(addresses[0]).toBeTruthy();
});

test('fetch no addresses when n=0', async () => {
const addresses = await fetchByDerivationPath("44'/60'/0'/0/X", {
n: 0,
});
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 0,
},
);
expect(addresses).toHaveLength(0);
});
});
Expand Down

0 comments on commit 614ac52

Please sign in to comment.