Skip to content

Commit

Permalink
Merge pull request #561 from GridPlus/nb/fix-api-tests
Browse files Browse the repository at this point in the history
fix api tests
  • Loading branch information
netbonus authored Jul 9, 2024
2 parents 70efa36 + b6fc3b3 commit 1f50d75
Showing 1 changed file with 46 additions and 27 deletions.
73 changes: 46 additions & 27 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,84 @@ 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,
});
console.log(addresses[0]);
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 5,
},
);
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,
});
console.log(addresses[0]);
const addresses = await fetchAddressesByDerivationPath(
"44'/60'/0'/0/X",
{
n: 3,
startPathIndex: 10,
},
);
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 1f50d75

Please sign in to comment.