Skip to content

Commit

Permalink
test: add acount tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirvolek committed Jul 22, 2021
1 parent 1811860 commit 035df3e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/badge-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/BlockFrostAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { API_URLS } from './config';
import { AxiosInstance } from 'axios';

import { deriveAddress, getAccount } from './account';

import {
accounts,
accountsDelegations,
Expand Down Expand Up @@ -878,6 +880,24 @@ class BlockFrostAPI {
*
*/
txSubmit = txSubmit;

/**
* deriveAddress
*
* @param hash
* @returns xxx
*
*/
deriveAddress = deriveAddress;

/**
* txSubmit
*
* @param hash
* @returns xxx
*
*/
getAccount = getAccount;
}

export { BlockFrostAPI };
2 changes: 1 addition & 1 deletion src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ADDRESS_GAP_LIMIT } from '../config';
export const deriveAddress = (
publicKey: string,
addressIndex: number,
type = 1 | 0,
type: 0 | 1,
): { address: string; path: string } => {
const accountKey = Bip32PublicKey.from_bytes(Buffer.from(publicKey, 'hex'));
const utxoPubKey = accountKey.derive(type).derive(addressIndex);
Expand Down
39 changes: 39 additions & 0 deletions test/fixtures/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const deriveAddressFixtures = [
{
publicKey:
'6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2',
index: 0,
type: 0,
response: {
address:
'addr1q8u5ktsj5zsmhvwv0ep9zuhfu39x3wyt9wxjnsn3cagsyy59ckxhkvuc5xj49rw6zrp443wlygmhv8gwcu38jk6ms6usrmcafl',
path: "m/1852'/1815'/0'/0/0",
},
},
{
publicKey:
'6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2',
index: 1,
type: 0,
response: {
address:
'addr1qxnthyxq8x9lv95h74k5av3sy3yzljr56ttxu4lggv8qstv9ckxhkvuc5xj49rw6zrp443wlygmhv8gwcu38jk6ms6us8mueja',
path: "m/1852'/1815'/0'/0/1",
},
},
] as const;

export const getAccountFixtures = [
{
publicKey:
'6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2',
type: 0,
response: '',
},
{
publicKey:
'6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2',
type: 1,
response: '',
},
] as const;
25 changes: 25 additions & 0 deletions test/tests/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SDK } from '../../utils';
import {
deriveAddressFixtures,
// getAccountFixtures,
} from '../../fixtures/account';

describe('account', () => {
deriveAddressFixtures.forEach(fixture => {
test(fixture.toString(), () => {
const response = SDK.deriveAddress(
fixture.publicKey,
fixture.index,
fixture.type,
);
expect(response).toMatchObject(fixture.response);
});
});

// getAccountFixtures.forEach(fixture => {
// test(fixture.toString(), async () => {
// const response = await SDK.getAccount(fixture.publicKey, fixture.type);
// expect(response).toMatchObject(fixture.response);
// });
// });
});

0 comments on commit 035df3e

Please sign in to comment.