From 0b4acac7360f50d56325b4bcb497b97efb2087e5 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:36:44 +0000 Subject: [PATCH 01/18] test: create account support functions --- packages/coin-support-utils/package.json | 7 +- .../src/createAccount/schemes.ts | 10 +- .../__fixtures__/index.ts | 6 + .../__fixtures__/types.ts | 16 +++ .../__fixtures__/valid.ts | 53 ++++++++ .../01.createDerivationPathGenerator/index.ts | 14 ++ .../__fixtures__/index.ts | 6 + .../__fixtures__/types.ts | 17 +++ .../__fixtures__/valid.ts | 127 ++++++++++++++++++ .../index.ts | 12 ++ .../__fixtures__/index.ts | 6 + .../__fixtures__/types.ts | 15 +++ .../__fixtures__/valid.ts | 23 ++++ .../03.createAccountNameGenerator/index.ts | 13 ++ .../tests/01.createAccount/index.text | 56 ++++++++ .../tests/__fixtures__/accounts.ts | 43 ++++++ .../coin-support-utils/tests/__mocks__/app.ts | 9 ++ .../tests/__mocks__/createAccountParams.ts | 29 ++++ .../coin-support-utils/tests/__mocks__/db.ts | 7 + .../tests/__mocks__/index.ts | 4 + .../tests/__mocks__/observer.ts | 5 + 21 files changed, 469 insertions(+), 9 deletions(-) create mode 100644 packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts create mode 100644 packages/coin-support-utils/tests/01.createAccount/index.text create mode 100644 packages/coin-support-utils/tests/__fixtures__/accounts.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/app.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/createAccountParams.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/db.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/index.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/observer.ts diff --git a/packages/coin-support-utils/package.json b/packages/coin-support-utils/package.json index ef33dbe45..0aebad0e2 100644 --- a/packages/coin-support-utils/package.json +++ b/packages/coin-support-utils/package.json @@ -9,13 +9,14 @@ "scripts": { "lint": "eslint --ext .ts,tsx,js,jsx src/ --fix", "lint:check": "eslint --ext .ts,tsx,js,jsx src/", - "pretty": "prettier --write \"src/**/*.ts?(x)\"", - "pretty:check": "prettier --check \"src/**/*.ts?(x)\"", + "pretty": "prettier --write \"src/**/*.ts?(x)\" \"tests/**/*.ts?(x)\"", + "pretty:check": "prettier --check \"src/**/*.ts?(x)\" \"tests/**/*.ts?(x)\"", "build": "rimraf dist && pnpm build:esm && pnpm build:cjs", "build:cjs": "tsc -p tsconfig_cjs.json", "build:esm": "tsc -p tsconfig.json", "build:dirty": "pnpm build:esm", - "pre-commit": "lint-staged" + "pre-commit": "lint-staged", + "test": "jest" }, "devDependencies": { "@cypherock/eslint-config": "workspace:^", diff --git a/packages/coin-support-utils/src/createAccount/schemes.ts b/packages/coin-support-utils/src/createAccount/schemes.ts index 2d077ed6d..bc2f9b3bb 100644 --- a/packages/coin-support-utils/src/createAccount/schemes.ts +++ b/packages/coin-support-utils/src/createAccount/schemes.ts @@ -1,5 +1,4 @@ import { - ICreateAccountParams, IDerivationPathGenerator, IDerivationScheme, } from '@cypherock/coin-support-interfaces'; @@ -8,6 +7,8 @@ import { IAccount } from '@cypherock/db-interfaces'; export const createDerivationPathGenerator = (basePath: string): IDerivationPathGenerator => (existingDerivationPaths, limit) => { + if (!basePath.includes('i')) return []; + const derivationPaths: { derivationPath: string; index: number }[] = []; let startIndex = 0; @@ -23,22 +24,19 @@ export const createDerivationPathGenerator = }); } - if (!basePath.includes('i')) break; - startIndex += 1; } return derivationPaths; }; -export interface IGenerateDerivationPathsPerSchemeParams - extends ICreateAccountParams { +export interface IGenerateDerivationPathsPerSchemeParams { derivationPathSchemes: Record; limit: number; existingAccounts: IAccount[]; } -export const generateDerivationPathsPerScheme = async ( +export const generateDerivationPathsPerScheme = ( params: IGenerateDerivationPathsPerSchemeParams, ) => { const { derivationPathSchemes, limit, existingAccounts } = params; diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts new file mode 100644 index 000000000..c48db1d6b --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts @@ -0,0 +1,16 @@ +export interface DerivationPathGeneratorTestCases { + name: string; + input: { + basePath: string; + existingDerivationPaths: string[]; + limit: number; + }; + output: { + derivationPath: string; + index: number; + }[]; +} + +export interface IFixtures { + valid: DerivationPathGeneratorTestCases[]; +} diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts new file mode 100644 index 000000000..2c20f6b80 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts @@ -0,0 +1,53 @@ +import { DerivationPathGeneratorTestCases } from './types'; + +export const valid: DerivationPathGeneratorTestCases[] = [ + { + name: 'should generate derivation path from zero index', + input: { + basePath: "m/44'/0'/0'/0/i", + existingDerivationPaths: [], + limit: 3, + }, + output: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/44'/0'/0'/0/1", + index: 1, + }, + { + derivationPath: "m/44'/0'/0'/0/2", + index: 2, + }, + ], + }, + { + name: 'should generate derivation path excluding existing derivation path', + input: { + basePath: "m/44'/0'/0'/0/i", + existingDerivationPaths: ["m/44'/0'/0'/0/1"], + limit: 2, + }, + output: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/44'/0'/0'/0/2", + index: 2, + }, + ], + }, + { + name: 'should return empty array if basePath does not include i', + input: { + basePath: "m/44'/0'/0'/0/0", + existingDerivationPaths: [], + limit: 2, + }, + output: [], + }, +]; diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts new file mode 100644 index 000000000..4879c352d --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts @@ -0,0 +1,14 @@ +import { describe, test } from '@jest/globals'; +import { createDerivationPathGenerator } from '../../../src/createAccount'; +import { fixtures } from './__fixtures__'; + +describe('01. Create Derivation Path Generator', () => { + fixtures.valid.forEach(({ name, input, output }) => { + test(name, () => { + const generator = createDerivationPathGenerator(input.basePath); + const result = generator(input.existingDerivationPaths, input.limit); + expect(generator).toBeInstanceOf(Function); + expect(result).toStrictEqual(output); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts new file mode 100644 index 000000000..d328ea78f --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts @@ -0,0 +1,17 @@ +import { IGenerateDerivationPathsPerSchemeParams } from '../../../../src/createAccount'; + +export interface DerivationPathPerSchemeGeneratorTestCases { + name: string; + input: IGenerateDerivationPathsPerSchemeParams; + output: Record< + string, + { + derivationPath: string; + index: number; + }[] + >; +} + +export interface IFixtures { + valid: DerivationPathPerSchemeGeneratorTestCases[]; +} diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts new file mode 100644 index 000000000..c8a1ee88e --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts @@ -0,0 +1,127 @@ +import { createDerivationPathGenerator } from '../../../../src/createAccount'; +import { accounts } from '../../../__fixtures__/accounts'; +import { DerivationPathPerSchemeGeneratorTestCases } from './types'; + +export const valid: DerivationPathPerSchemeGeneratorTestCases[] = [ + { + name: 'should generate derivation paths from index zero', + input: { + derivationPathSchemes: { + legacy: { + threshold: 2, + newAccountLimit: 0, // this is getting ignored + name: 'legacy', + generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), + }, + }, + limit: 4, + existingAccounts: [], + }, + output: { + legacy: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/44'/0'/0'/0/1", + index: 1, + }, + { + derivationPath: "m/44'/0'/0'/0/2", + index: 2, + }, + { + derivationPath: "m/44'/0'/0'/0/3", + index: 3, + }, + ], + }, + }, + { + name: 'should generate derivation paths from index zero with multiple schemes', + input: { + derivationPathSchemes: { + legacy: { + name: 'legacy', + generator: createDerivationPathGenerator("m/44'/0'/i'"), + threshold: 2, + newAccountLimit: 0, // this is getting ignored + }, + segwit: { + name: 'segwit', + generator: createDerivationPathGenerator(`m/49'/0'/i'`), + threshold: 2, + newAccountLimit: 0, // this is getting ignored + }, + }, + limit: 4, + existingAccounts: [], + }, + output: { + legacy: [ + { + derivationPath: "m/44'/0'/0'", + index: 0, + }, + { + derivationPath: "m/44'/0'/1'", + index: 1, + }, + ], + segwit: [ + { + derivationPath: "m/49'/0'/0'", + index: 0, + }, + { + derivationPath: "m/49'/0'/1'", + index: 1, + }, + ], + }, + }, + { + name: 'should generate derivation paths from index zero with multiple schemes ignoring existing accounts', + input: { + derivationPathSchemes: { + legacy: { + name: 'legacy', + generator: createDerivationPathGenerator("m/44'/0'/i'"), + threshold: 2, + newAccountLimit: 0, // this is getting ignored + }, + segwit: { + name: 'segwit', + generator: createDerivationPathGenerator(`m/49'/0'/i'`), + threshold: 2, + newAccountLimit: 0, // this is getting ignored + }, + }, + limit: 4, + existingAccounts: accounts, + }, + output: { + legacy: [ + { + derivationPath: "m/44'/0'/1'", + index: 1, + }, + { + derivationPath: "m/44'/0'/2'", + index: 2, + }, + ], + segwit: [ + { + derivationPath: "m/49'/0'/0'", + index: 0, + }, + { + derivationPath: "m/49'/0'/1'", + index: 1, + }, + ], + }, + }, +]; diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts new file mode 100644 index 000000000..35c2182bd --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts @@ -0,0 +1,12 @@ +import { describe, test } from '@jest/globals'; +import { fixtures } from './__fixtures__'; +import { generateDerivationPathsPerScheme } from '../../../src'; + +describe('02. Generate Derivation Path Per Scheme', () => { + fixtures.valid.forEach(({ name, input, output }) => { + test(name, () => { + const result = generateDerivationPathsPerScheme(input); + expect(result).toStrictEqual(output); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts new file mode 100644 index 000000000..3d01d61a6 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts @@ -0,0 +1,15 @@ +import { IAccount } from '@cypherock/db-interfaces'; + +export interface AccountNameGeneratorTestCases { + name: string; + input: { + coinName: string; + schemeName: string; + existingAccounts: IAccount[]; + }; + output: string; +} + +export interface IFixtures { + valid: AccountNameGeneratorTestCases[]; +} diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts new file mode 100644 index 000000000..2db6c3071 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts @@ -0,0 +1,23 @@ +import { accounts } from '../../../__fixtures__/accounts'; +import { AccountNameGeneratorTestCases } from './types'; + +export const valid: AccountNameGeneratorTestCases[] = [ + { + name: 'should generate derivation paths from index zero', + input: { + coinName: 'Bitcoin', + schemeName: 'legacy', + existingAccounts: [], + }, + output: 'Bitcoin 1', + }, + { + name: 'should generate derivation paths from index zero', + input: { + coinName: 'Bitcoin', + schemeName: 'legacy', + existingAccounts: accounts, + }, + output: 'Bitcoin 2', + }, +]; diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts new file mode 100644 index 000000000..d0e3024a5 --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts @@ -0,0 +1,13 @@ +import { describe, test } from '@jest/globals'; +import { createAccountNameGenerator } from '../../../src'; +import { fixtures } from './__fixtures__'; + +describe('createAccountNameGenerator', () => { + fixtures.valid.forEach(({ name, input, output }) => { + test(name, () => { + const generator = createAccountNameGenerator(input.coinName); + const result = generator(input.schemeName, input.existingAccounts); + expect(result).toBe(output); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/01.createAccount/index.text b/packages/coin-support-utils/tests/01.createAccount/index.text new file mode 100644 index 000000000..c68cf119a --- /dev/null +++ b/packages/coin-support-utils/tests/01.createAccount/index.text @@ -0,0 +1,56 @@ +import { describe, test } from '@jest/globals'; +// import { testDatabase } from '../__helpers__/db'; +// import { IDatabase } from '@cypherock/db-interfaces'; +import { IDeviceConnection } from '@cypherock/sdk-interfaces'; +import { createDerivationPathGenerator, makeCreateAccountsObservable } from '../../src/createAccount'; +import { createAccountParams, db } from '../__mocks__'; +// import { mockObserver } from '../__mocks__'; +import { Observer } from 'rxjs'; +import { ICreateAccountEvent } from '@cypherock/coin-support-interfaces'; + +describe('createAccount', () => { + // let db: IDatabase; + let connection: IDeviceConnection = {} as any; + + beforeEach(async () => { + // await testDatabase.create(); + // db = testDatabase.db!; + }); + + afterEach(async () => { + // await testDatabase.destroy(); + jest.clearAllMocks(); + jest.resetAllMocks(); + }); + + // describe('makeCreateAccountsObservable', () => { + // test('should create accounts', done => { + // const params = createAccountParams(db, connection); + // const createAccountsObservable = makeCreateAccountsObservable(params); + + // const observer: Observer = { + // next: data => { + // // next actions + // }, + // complete: () => { + // expect(true).toBe(true); + // done(); + // }, + // error: err => { + // throw err; + // }, + // }; + + // createAccountsObservable.subscribe(observer); + + // // await new Promise(resolve => { + // // mockObserver.complete.mockReturnValue(() => resolve()); + // // mockObserver.error.mockReturnValue(() => resolve()); + // // }); + + // // expect(mockObserver.next).toHaveBeenCalledTimes(1); + // // expect(mockObserver.complete).toHaveBeenCalledTimes(1); + // // expect(mockObserver.error).not.toHaveBeenCalled(); + // }); + // }); +}); diff --git a/packages/coin-support-utils/tests/__fixtures__/accounts.ts b/packages/coin-support-utils/tests/__fixtures__/accounts.ts new file mode 100644 index 000000000..ed19b4fd2 --- /dev/null +++ b/packages/coin-support-utils/tests/__fixtures__/accounts.ts @@ -0,0 +1,43 @@ +import { IAccount } from '@cypherock/db-interfaces'; + +export const accounts: IAccount[] = [ + { + name: 'Bitcoin 1', + xpubOrAddress: '', + balance: '0', + unit: 'BTC', + derivationPath: "m/84'/0'/0'", + type: 'account', + familyId: 'bitcoin', + assetId: 'bitcoin', + parentAssetId: 'bitcoin', + walletId: + 'c372af88f64e0a40439f97ee98a3a0a03e9b2ac348b464d0cab7f32ee8482298', + derivationScheme: 'nativeSegwit', + __version: 0, + __id: 'da51cef8-aa25-4667-b2da-9b4ef78dcee2', + extraData: { + unconfirmedBalance: '0', + derivationScheme: 'nativeSegwit', + }, + }, + { + name: 'Bitcoin 1', + xpubOrAddress: '', + balance: '20000', + unit: 'BTC', + derivationPath: "m/44'/0'/0'", + type: 'account', + familyId: 'bitcoin', + assetId: 'bitcoin', + parentAssetId: 'bitcoin', + walletId: '', + derivationScheme: 'legacy', + __version: 0, + __id: '54d86310-66e1-4ca5-ae6a-d7b6cd671eba', + extraData: { + unconfirmedBalance: '0', + derivationScheme: 'legacy', + }, + }, +]; diff --git a/packages/coin-support-utils/tests/__mocks__/app.ts b/packages/coin-support-utils/tests/__mocks__/app.ts new file mode 100644 index 000000000..59869e6fe --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/app.ts @@ -0,0 +1,9 @@ +import { jest } from '@jest/globals'; + +export interface TestApp { + abort: () => Promise; +} + +export const testApp: TestApp = { + abort: jest.fn(() => Promise.resolve()), +}; diff --git a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts new file mode 100644 index 000000000..75c14f2b0 --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts @@ -0,0 +1,29 @@ +import { IDatabase } from '@cypherock/db-interfaces'; +import { IMakeCreateAccountsObservableParams } from '../../src/createAccount'; +import { TestApp, testApp } from './app'; +import { IDeviceConnection } from '@cypherock/sdk-interfaces'; + +export const createAccountParams = ( + db: IDatabase, + connection: IDeviceConnection, +): IMakeCreateAccountsObservableParams => ({ + createApp: jest.fn().mockResolvedValue(testApp), + derivationPathSchemes: { + legacy: { + threshold: 2, + newAccountLimit: 3, + name: 'ac1', + generator: jest.fn(), + }, + }, + derivationPathLimit: 10, + getBalanceAndTxnCount: jest + .fn() + .mockResolvedValue({ balance: '0', txnCount: 0 }), + getAddressesFromDevice: jest.fn(), + createAccountFromAddress: jest.fn().mockResolvedValue({}), + coinId: 'testCoin', + walletId: 'testWallet', + db, + connection, +}); diff --git a/packages/coin-support-utils/tests/__mocks__/db.ts b/packages/coin-support-utils/tests/__mocks__/db.ts new file mode 100644 index 000000000..70a894640 --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/db.ts @@ -0,0 +1,7 @@ +import { IDatabase } from '@cypherock/db-interfaces'; + +export const db: IDatabase = { + account: { + getAll: jest.fn(() => []), + }, +} as any; diff --git a/packages/coin-support-utils/tests/__mocks__/index.ts b/packages/coin-support-utils/tests/__mocks__/index.ts new file mode 100644 index 000000000..7546b0191 --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/index.ts @@ -0,0 +1,4 @@ +export * from './app'; +export * from './createAccountParams'; +export * from './observer'; +export * from './db'; diff --git a/packages/coin-support-utils/tests/__mocks__/observer.ts b/packages/coin-support-utils/tests/__mocks__/observer.ts new file mode 100644 index 000000000..b1e62422d --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/observer.ts @@ -0,0 +1,5 @@ +export const mockObserver = { + next: jest.fn(), + error: jest.fn(), + complete: jest.fn(), +}; From 66fcdb3fe94cf67899e7f2b884cd6783178902d4 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Sat, 13 Apr 2024 06:59:07 +0000 Subject: [PATCH 02/18] fix: undo createDerivationPathGenerator logic --- .../src/createAccount/schemes.ts | 4 ++-- .../__fixtures__/valid.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/coin-support-utils/src/createAccount/schemes.ts b/packages/coin-support-utils/src/createAccount/schemes.ts index bc2f9b3bb..a9b911ad2 100644 --- a/packages/coin-support-utils/src/createAccount/schemes.ts +++ b/packages/coin-support-utils/src/createAccount/schemes.ts @@ -7,8 +7,6 @@ import { IAccount } from '@cypherock/db-interfaces'; export const createDerivationPathGenerator = (basePath: string): IDerivationPathGenerator => (existingDerivationPaths, limit) => { - if (!basePath.includes('i')) return []; - const derivationPaths: { derivationPath: string; index: number }[] = []; let startIndex = 0; @@ -24,6 +22,8 @@ export const createDerivationPathGenerator = }); } + if (!basePath.includes('i')) break; + startIndex += 1; } diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts index 2c20f6b80..fca6041b1 100644 --- a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts @@ -42,12 +42,26 @@ export const valid: DerivationPathGeneratorTestCases[] = [ ], }, { - name: 'should return empty array if basePath does not include i', + name: 'should return basePath if it does not include i', input: { basePath: "m/44'/0'/0'/0/0", existingDerivationPaths: [], limit: 2, }, + output: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + ], + }, + { + name: 'should return return empty array if base path is alreadty derived and it does not include i', + input: { + basePath: "m/44'/0'/0'/0/0", + existingDerivationPaths: ["m/44'/0'/0'/0/0"], + limit: 2, + }, output: [], }, ]; From 12ed23d69fecf0b44b70ce240c2f093d3dc29851 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Sat, 13 Apr 2024 07:03:05 +0000 Subject: [PATCH 03/18] test: added name generator test for random schemeName --- .../03.createAccountNameGenerator/__fixtures__/valid.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts index 2db6c3071..7db335fb5 100644 --- a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts @@ -20,4 +20,13 @@ export const valid: AccountNameGeneratorTestCases[] = [ }, output: 'Bitcoin 2', }, + { + name: 'should generate derivation paths from index zero', + input: { + coinName: 'Bitcoin', + schemeName: 'something random', + existingAccounts: accounts, + }, + output: 'Bitcoin 1', + }, ]; From 58a7f5a79ab04624d66d594be5d52dc56292071d Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 15 Apr 2024 09:25:02 +0000 Subject: [PATCH 04/18] test: mapDerivationPath, generate Address Per Scheme --- .../src/createAccount/generateAddresses.ts | 4 +- .../__fixtures__/index.ts | 0 .../__fixtures__/types.ts | 9 + .../__fixtures__/valid.ts | 19 ++ .../01.common/01.mapDerivationPath/index.ts | 12 ++ .../tests/01.createAccount/index.text | 56 ----- .../__fixtures__/index.ts | 0 .../__fixtures__/types.ts | 0 .../__fixtures__/valid.ts | 0 .../01.createDerivationPathGenerator/index.ts | 0 .../__fixtures__/index.ts | 0 .../__fixtures__/types.ts | 0 .../__fixtures__/valid.ts | 0 .../index.ts | 0 .../__fixtures__/index.ts | 6 + .../__fixtures__/types.ts | 0 .../__fixtures__/valid.ts | 0 .../03.createAccountNameGenerator/index.ts | 0 .../__fixtures__/derivationPathAddressMap.ts | 13 ++ .../__fixtures__/index.ts | 6 + .../__fixtures__/types.ts | 24 +++ .../__fixtures__/valid.ts | 204 ++++++++++++++++++ .../__mocks__/getAddressesFromDevice.ts | 12 ++ .../__mocks__/index.ts | 1 + .../04.generateAddressesPerScheme/index.ts | 22 ++ 25 files changed, 330 insertions(+), 58 deletions(-) rename packages/coin-support-utils/tests/{01.createAccount/01.createDerivationPathGenerator => 01.common/01.mapDerivationPath}/__fixtures__/index.ts (100%) create mode 100644 packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/01.common/01.mapDerivationPath/index.ts delete mode 100644 packages/coin-support-utils/tests/01.createAccount/index.text rename packages/coin-support-utils/tests/{01.createAccount/02.generateDerivationPathPerScheme => 02.createAccount/01.createDerivationPathGenerator}/__fixtures__/index.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/01.createDerivationPathGenerator/__fixtures__/types.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/01.createDerivationPathGenerator/__fixtures__/valid.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/01.createDerivationPathGenerator/index.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount/03.createAccountNameGenerator => 02.createAccount/02.generateDerivationPathPerScheme}/__fixtures__/index.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/02.generateDerivationPathPerScheme/__fixtures__/types.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/02.generateDerivationPathPerScheme/__fixtures__/valid.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/02.generateDerivationPathPerScheme/index.ts (100%) create mode 100644 packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/03.createAccountNameGenerator/__fixtures__/types.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/03.createAccountNameGenerator/__fixtures__/valid.ts (100%) rename packages/coin-support-utils/tests/{01.createAccount => 02.createAccount}/03.createAccountNameGenerator/index.ts (100%) create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts diff --git a/packages/coin-support-utils/src/createAccount/generateAddresses.ts b/packages/coin-support-utils/src/createAccount/generateAddresses.ts index cd30ed054..44ab2566b 100644 --- a/packages/coin-support-utils/src/createAccount/generateAddresses.ts +++ b/packages/coin-support-utils/src/createAccount/generateAddresses.ts @@ -30,7 +30,7 @@ export interface IGenerateAddressesPerSchemeParams export async function generateAddressesPerScheme( params: IGenerateAddressesPerSchemeParams, ) { - const { derivationPathsPerScheme } = params; + const { derivationPathsPerScheme, getAddressesFromDevice } = params; const allDerivationPaths = Object.values(derivationPathsPerScheme).reduce( (a, b) => [...a, ...b], [], @@ -40,7 +40,7 @@ export async function generateAddressesPerScheme( index: startIndex, })); - const addresses = await params.getAddressesFromDevice({ + const addresses = await getAddressesFromDevice({ ...params, derivationPaths: mappedDerivationPaths, }); diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts rename to packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/index.ts diff --git a/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/types.ts b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/types.ts new file mode 100644 index 000000000..05274fc89 --- /dev/null +++ b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/types.ts @@ -0,0 +1,9 @@ +export interface MapDerivationPathTestCases { + name: string; + input: string; + output: number[]; +} + +export interface IFixtures { + valid: MapDerivationPathTestCases[]; +} diff --git a/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/valid.ts b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/valid.ts new file mode 100644 index 000000000..37b9135b1 --- /dev/null +++ b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/__fixtures__/valid.ts @@ -0,0 +1,19 @@ +import { MapDerivationPathTestCases } from './types'; + +export const valid: MapDerivationPathTestCases[] = [ + { + name: 'should map derivation path with single index', + input: "m/44'", + output: [2147483692], + }, + { + name: 'should map derivation path with multiple index', + input: "m/44'/0'/0'/0/0", + output: [2147483692, 2147483648, 2147483648, 0, 0], + }, + { + name: 'should map derivation path with multiple index without m prefix', + input: "44'/0'/0'/0/0", + output: [2147483692, 2147483648, 2147483648, 0, 0], + }, +]; diff --git a/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/index.ts b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/index.ts new file mode 100644 index 000000000..9113bed7e --- /dev/null +++ b/packages/coin-support-utils/tests/01.common/01.mapDerivationPath/index.ts @@ -0,0 +1,12 @@ +import { describe, test } from '@jest/globals'; +import { fixtures } from './__fixtures__'; +import { mapDerivationPath } from '../../../src'; + +describe('mapDerivationPath', () => { + fixtures.valid.forEach(({ name, input, output }) => { + test(name, () => { + const result = mapDerivationPath(input); + expect(result).toStrictEqual(output); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/01.createAccount/index.text b/packages/coin-support-utils/tests/01.createAccount/index.text deleted file mode 100644 index c68cf119a..000000000 --- a/packages/coin-support-utils/tests/01.createAccount/index.text +++ /dev/null @@ -1,56 +0,0 @@ -import { describe, test } from '@jest/globals'; -// import { testDatabase } from '../__helpers__/db'; -// import { IDatabase } from '@cypherock/db-interfaces'; -import { IDeviceConnection } from '@cypherock/sdk-interfaces'; -import { createDerivationPathGenerator, makeCreateAccountsObservable } from '../../src/createAccount'; -import { createAccountParams, db } from '../__mocks__'; -// import { mockObserver } from '../__mocks__'; -import { Observer } from 'rxjs'; -import { ICreateAccountEvent } from '@cypherock/coin-support-interfaces'; - -describe('createAccount', () => { - // let db: IDatabase; - let connection: IDeviceConnection = {} as any; - - beforeEach(async () => { - // await testDatabase.create(); - // db = testDatabase.db!; - }); - - afterEach(async () => { - // await testDatabase.destroy(); - jest.clearAllMocks(); - jest.resetAllMocks(); - }); - - // describe('makeCreateAccountsObservable', () => { - // test('should create accounts', done => { - // const params = createAccountParams(db, connection); - // const createAccountsObservable = makeCreateAccountsObservable(params); - - // const observer: Observer = { - // next: data => { - // // next actions - // }, - // complete: () => { - // expect(true).toBe(true); - // done(); - // }, - // error: err => { - // throw err; - // }, - // }; - - // createAccountsObservable.subscribe(observer); - - // // await new Promise(resolve => { - // // mockObserver.complete.mockReturnValue(() => resolve()); - // // mockObserver.error.mockReturnValue(() => resolve()); - // // }); - - // // expect(mockObserver.next).toHaveBeenCalledTimes(1); - // // expect(mockObserver.complete).toHaveBeenCalledTimes(1); - // // expect(mockObserver.error).not.toHaveBeenCalled(); - // }); - // }); -}); diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts rename to packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/index.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts rename to packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/types.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts rename to packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/__fixtures__/valid.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts b/packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/01.createDerivationPathGenerator/index.ts rename to packages/coin-support-utils/tests/02.createAccount/01.createDerivationPathGenerator/index.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts rename to packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/index.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts rename to packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/types.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts rename to packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/02.generateDerivationPathPerScheme/index.ts rename to packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/index.ts diff --git a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts rename to packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts rename to packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts diff --git a/packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts similarity index 100% rename from packages/coin-support-utils/tests/01.createAccount/03.createAccountNameGenerator/index.ts rename to packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts new file mode 100644 index 000000000..d99652f5b --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts @@ -0,0 +1,13 @@ +import { mapDerivationPath } from '../../../../src'; + +export const derivationPathAddressMap = new Map([ + [mapDerivationPath("m/44'/0'/0'/0/0"), 'address_44_0_0_0_0'], + [mapDerivationPath("m/44'/0'/0'/0/1"), 'address_44_0_0_0_1'], + [mapDerivationPath("m/44'/0'/0'/0/2"), 'address_44_0_0_0_2'], + [mapDerivationPath("m/84'/0'/0'/0/0"), 'address_84_0_0_0_0'], + [mapDerivationPath("m/84'/0'/0'/0/1"), 'address_84_0_0_0_1'], + [mapDerivationPath("m/84'/0'/0'/0/2"), 'address_84_0_0_0_2'], + [mapDerivationPath("m/49'/0'/0'/0/0"), 'address_49_0_0_0_0'], + [mapDerivationPath("m/49'/0'/0'/0/1"), 'address_49_0_0_0_1'], + [mapDerivationPath("m/49'/0'/0'/0/2"), 'address_49_0_0_0_2'], +]); diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/types.ts new file mode 100644 index 000000000..b81e8876e --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/types.ts @@ -0,0 +1,24 @@ +export interface AddressesPerSchemeGeneratorTestCases { + name: string; + input: { + derivationPathsPerScheme: Record< + string, + { + derivationPath: string; + index: number; + }[] + >; + }; + output: Record< + string, + { + address: string; + derivationPath: string; + index: number; + }[] + >; +} + +export interface IFixtures { + valid: AddressesPerSchemeGeneratorTestCases[]; +} diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts new file mode 100644 index 000000000..dd4ce9d22 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts @@ -0,0 +1,204 @@ +import { mapDerivationPath } from '../../../../src'; +import { derivationPathAddressMap } from './derivationPathAddressMap'; +import { AddressesPerSchemeGeneratorTestCases } from './types'; + +export const valid: AddressesPerSchemeGeneratorTestCases[] = [ + { + name: 'should generate addresses with one scheme, derivation path and one index', + input: { + derivationPathsPerScheme: { + legacy: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + ], + }, + }, + output: { + legacy: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/44'/0'/0'/0/0"), + )!, + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + ], + }, + }, + { + name: 'should generate addresses per scheme with one derivation path and one index', + input: { + derivationPathsPerScheme: { + legacy: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + ], + nativeSegwit: [ + { + derivationPath: "m/84'/0'/0'/0/0", + index: 0, + }, + ], + segwit: [ + { + derivationPath: "m/49'/0'/0'/0/0", + index: 0, + }, + ], + }, + }, + output: { + legacy: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/44'/0'/0'/0/0"), + )!, + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + ], + nativeSegwit: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/84'/0'/0'/0/0"), + )!, + derivationPath: "m/84'/0'/0'/0/0", + index: 0, + }, + ], + segwit: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/49'/0'/0'/0/0"), + )!, + derivationPath: "m/49'/0'/0'/0/0", + index: 0, + }, + ], + }, + }, + { + name: 'should generate addresses per scheme with multiple derivation paths and indexes', + input: { + derivationPathsPerScheme: { + legacy: [ + { + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/44'/0'/0'/0/1", + index: 1, + }, + { + derivationPath: "m/44'/0'/0'/0/2", + index: 2, + }, + ], + nativeSegwit: [ + { + derivationPath: "m/84'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/84'/0'/0'/0/1", + index: 1, + }, + { + derivationPath: "m/84'/0'/0'/0/2", + index: 2, + }, + ], + segwit: [ + { + derivationPath: "m/49'/0'/0'/0/0", + index: 0, + }, + { + derivationPath: "m/49'/0'/0'/0/1", + index: 1, + }, + { + derivationPath: "m/49'/0'/0'/0/2", + index: 2, + }, + ], + }, + }, + output: { + legacy: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/44'/0'/0'/0/0"), + )!, + derivationPath: "m/44'/0'/0'/0/0", + index: 0, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/44'/0'/0'/0/1"), + )!, + derivationPath: "m/44'/0'/0'/0/1", + index: 1, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/44'/0'/0'/0/2"), + )!, + derivationPath: "m/44'/0'/0'/0/2", + index: 2, + }, + ], + nativeSegwit: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/84'/0'/0'/0/0"), + )!, + derivationPath: "m/84'/0'/0'/0/0", + index: 0, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/84'/0'/0'/0/1"), + )!, + derivationPath: "m/84'/0'/0'/0/1", + index: 1, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/84'/0'/0'/0/2"), + )!, + derivationPath: "m/84'/0'/0'/0/2", + index: 2, + }, + ], + segwit: [ + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/49'/0'/0'/0/0"), + )!, + derivationPath: "m/49'/0'/0'/0/0", + index: 0, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/49'/0'/0'/0/1"), + )!, + derivationPath: "m/49'/0'/0'/0/1", + index: 1, + }, + { + address: derivationPathAddressMap.get( + mapDerivationPath("m/49'/0'/0'/0/2"), + )!, + derivationPath: "m/49'/0'/0'/0/2", + index: 2, + }, + ], + }, + }, +]; diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts new file mode 100644 index 000000000..609aec2a6 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts @@ -0,0 +1,12 @@ +import { IGetAddressesFromDeviceParams } from '../../../../src'; +import { TestApp } from '../../../__mocks__'; +import { derivationPathAddressMap } from '../__fixtures__/derivationPathAddressMap'; + +export const getAddressesFromDeviceMock = jest.fn( + async ({ + derivationPaths, + }: IGetAddressesFromDeviceParams): Promise => + derivationPaths.map( + ({ derivationPath }) => derivationPathAddressMap.get(derivationPath)!, + ), +); diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts new file mode 100644 index 000000000..efba42360 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts @@ -0,0 +1 @@ +export * from './getAddressesFromDevice'; diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts new file mode 100644 index 000000000..ff98a1215 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts @@ -0,0 +1,22 @@ +import { describe, test } from '@jest/globals'; + +import { fixtures } from './__fixtures__'; +import { TestApp } from '../../__mocks__'; +import { + IGenerateAddressesPerSchemeParams, + generateAddressesPerScheme, +} from '../../../src'; +import { getAddressesFromDeviceMock } from './__mocks__'; + +describe('04. Generate Addresses Per Scheme', () => { + fixtures.valid.forEach(({ name, input, output }) => { + test(name, async () => { + const params: IGenerateAddressesPerSchemeParams = { + derivationPathsPerScheme: input.derivationPathsPerScheme, + getAddressesFromDevice: getAddressesFromDeviceMock, + } as any; + const result = await generateAddressesPerScheme(params); + expect(result).toStrictEqual(output); + }); + }); +}); From 37847048650a650f1fb296b1da16cad1e0dac8fd Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:07:45 +0000 Subject: [PATCH 05/18] test: makeCreateAccountsObservable --- .../__fixtures__/valid.ts | 2 +- .../__fixtures__/valid.ts | 2 +- .../__fixtures__/derivationPathAddressMap.ts | 13 ---- .../__fixtures__/valid.ts | 54 +++++----------- .../__mocks__/getAddressesFromDevice.ts | 12 ---- .../__mocks__/index.ts | 1 - .../04.generateAddressesPerScheme/index.ts | 3 +- .../__fixtures__/index.ts | 6 ++ .../__fixtures__/types.ts | 7 +++ .../__fixtures__/valid.ts | 7 +++ .../05.makeCreateAccountsObservable/index.ts | 47 ++++++++++++++ .../__fixtures__/derivationPathAddressMap.ts | 26 ++++++++ .../tests/__fixtures__/index.ts | 2 + .../__fixtures__/{accounts.ts => wallet.ts} | 27 +++++--- .../tests/__mocks__/createAccountParams.ts | 61 +++++++++++-------- .../tests/__mocks__/createApp.ts | 7 +++ .../tests/__mocks__/getAddressesFromDevice.ts | 12 ++++ .../tests/__mocks__/getBalanceAndTxnCount.ts | 7 +++ .../tests/__mocks__/index.ts | 5 +- 19 files changed, 194 insertions(+), 107 deletions(-) delete mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts delete mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts delete mode 100644 packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts create mode 100644 packages/coin-support-utils/tests/__fixtures__/derivationPathAddressMap.ts create mode 100644 packages/coin-support-utils/tests/__fixtures__/index.ts rename packages/coin-support-utils/tests/__fixtures__/{accounts.ts => wallet.ts} (64%) create mode 100644 packages/coin-support-utils/tests/__mocks__/createApp.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts create mode 100644 packages/coin-support-utils/tests/__mocks__/getBalanceAndTxnCount.ts diff --git a/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts index c8a1ee88e..b24de612f 100644 --- a/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts @@ -1,5 +1,5 @@ import { createDerivationPathGenerator } from '../../../../src/createAccount'; -import { accounts } from '../../../__fixtures__/accounts'; +import { accounts } from '../../../__fixtures__'; import { DerivationPathPerSchemeGeneratorTestCases } from './types'; export const valid: DerivationPathPerSchemeGeneratorTestCases[] = [ diff --git a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts index 7db335fb5..72bc93725 100644 --- a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts @@ -1,4 +1,4 @@ -import { accounts } from '../../../__fixtures__/accounts'; +import { accounts } from '../../../__fixtures__'; import { AccountNameGeneratorTestCases } from './types'; export const valid: AccountNameGeneratorTestCases[] = [ diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts deleted file mode 100644 index d99652f5b..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/derivationPathAddressMap.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { mapDerivationPath } from '../../../../src'; - -export const derivationPathAddressMap = new Map([ - [mapDerivationPath("m/44'/0'/0'/0/0"), 'address_44_0_0_0_0'], - [mapDerivationPath("m/44'/0'/0'/0/1"), 'address_44_0_0_0_1'], - [mapDerivationPath("m/44'/0'/0'/0/2"), 'address_44_0_0_0_2'], - [mapDerivationPath("m/84'/0'/0'/0/0"), 'address_84_0_0_0_0'], - [mapDerivationPath("m/84'/0'/0'/0/1"), 'address_84_0_0_0_1'], - [mapDerivationPath("m/84'/0'/0'/0/2"), 'address_84_0_0_0_2'], - [mapDerivationPath("m/49'/0'/0'/0/0"), 'address_49_0_0_0_0'], - [mapDerivationPath("m/49'/0'/0'/0/1"), 'address_49_0_0_0_1'], - [mapDerivationPath("m/49'/0'/0'/0/2"), 'address_49_0_0_0_2'], -]); diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts index dd4ce9d22..8a70c340f 100644 --- a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__fixtures__/valid.ts @@ -1,5 +1,5 @@ import { mapDerivationPath } from '../../../../src'; -import { derivationPathAddressMap } from './derivationPathAddressMap'; +import { getAddressFromPath } from '../../../__fixtures__/derivationPathAddressMap'; import { AddressesPerSchemeGeneratorTestCases } from './types'; export const valid: AddressesPerSchemeGeneratorTestCases[] = [ @@ -18,9 +18,7 @@ export const valid: AddressesPerSchemeGeneratorTestCases[] = [ output: { legacy: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/44'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/44'/0'/0'/0/0"))!, derivationPath: "m/44'/0'/0'/0/0", index: 0, }, @@ -54,27 +52,21 @@ export const valid: AddressesPerSchemeGeneratorTestCases[] = [ output: { legacy: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/44'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/44'/0'/0'/0/0"))!, derivationPath: "m/44'/0'/0'/0/0", index: 0, }, ], nativeSegwit: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/84'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/84'/0'/0'/0/0"))!, derivationPath: "m/84'/0'/0'/0/0", index: 0, }, ], segwit: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/49'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/49'/0'/0'/0/0"))!, derivationPath: "m/49'/0'/0'/0/0", index: 0, }, @@ -132,69 +124,51 @@ export const valid: AddressesPerSchemeGeneratorTestCases[] = [ output: { legacy: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/44'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/44'/0'/0'/0/0"))!, derivationPath: "m/44'/0'/0'/0/0", index: 0, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/44'/0'/0'/0/1"), - )!, + address: getAddressFromPath(mapDerivationPath("m/44'/0'/0'/0/1"))!, derivationPath: "m/44'/0'/0'/0/1", index: 1, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/44'/0'/0'/0/2"), - )!, + address: getAddressFromPath(mapDerivationPath("m/44'/0'/0'/0/2"))!, derivationPath: "m/44'/0'/0'/0/2", index: 2, }, ], nativeSegwit: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/84'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/84'/0'/0'/0/0"))!, derivationPath: "m/84'/0'/0'/0/0", index: 0, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/84'/0'/0'/0/1"), - )!, + address: getAddressFromPath(mapDerivationPath("m/84'/0'/0'/0/1"))!, derivationPath: "m/84'/0'/0'/0/1", index: 1, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/84'/0'/0'/0/2"), - )!, + address: getAddressFromPath(mapDerivationPath("m/84'/0'/0'/0/2"))!, derivationPath: "m/84'/0'/0'/0/2", index: 2, }, ], segwit: [ { - address: derivationPathAddressMap.get( - mapDerivationPath("m/49'/0'/0'/0/0"), - )!, + address: getAddressFromPath(mapDerivationPath("m/49'/0'/0'/0/0"))!, derivationPath: "m/49'/0'/0'/0/0", index: 0, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/49'/0'/0'/0/1"), - )!, + address: getAddressFromPath(mapDerivationPath("m/49'/0'/0'/0/1"))!, derivationPath: "m/49'/0'/0'/0/1", index: 1, }, { - address: derivationPathAddressMap.get( - mapDerivationPath("m/49'/0'/0'/0/2"), - )!, + address: getAddressFromPath(mapDerivationPath("m/49'/0'/0'/0/2"))!, derivationPath: "m/49'/0'/0'/0/2", index: 2, }, diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts deleted file mode 100644 index 609aec2a6..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/getAddressesFromDevice.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IGetAddressesFromDeviceParams } from '../../../../src'; -import { TestApp } from '../../../__mocks__'; -import { derivationPathAddressMap } from '../__fixtures__/derivationPathAddressMap'; - -export const getAddressesFromDeviceMock = jest.fn( - async ({ - derivationPaths, - }: IGetAddressesFromDeviceParams): Promise => - derivationPaths.map( - ({ derivationPath }) => derivationPathAddressMap.get(derivationPath)!, - ), -); diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts deleted file mode 100644 index efba42360..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/__mocks__/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './getAddressesFromDevice'; diff --git a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts index ff98a1215..c4a30743e 100644 --- a/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts +++ b/packages/coin-support-utils/tests/02.createAccount/04.generateAddressesPerScheme/index.ts @@ -1,12 +1,11 @@ import { describe, test } from '@jest/globals'; import { fixtures } from './__fixtures__'; -import { TestApp } from '../../__mocks__'; +import { TestApp, getAddressesFromDeviceMock } from '../../__mocks__'; import { IGenerateAddressesPerSchemeParams, generateAddressesPerScheme, } from '../../../src'; -import { getAddressesFromDeviceMock } from './__mocks__'; describe('04. Generate Addresses Per Scheme', () => { fixtures.valid.forEach(({ name, input, output }) => { diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts new file mode 100644 index 000000000..9dab336a9 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts @@ -0,0 +1,6 @@ +import { IFixtures } from './types'; +import { valid } from './valid'; + +export const fixtures: IFixtures = { + valid, +}; diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts new file mode 100644 index 000000000..ab7775345 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts @@ -0,0 +1,7 @@ +export interface MakeCreateAccountsObservableTestCase { + name: string; +} + +export interface IFixtures { + valid: MakeCreateAccountsObservableTestCase[]; +} diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts new file mode 100644 index 000000000..f23daa2cc --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts @@ -0,0 +1,7 @@ +import { MakeCreateAccountsObservableTestCase } from './types'; + +export const valid: MakeCreateAccountsObservableTestCase[] = [ + { + name: 'should run test without timeout', + }, +]; diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts new file mode 100644 index 000000000..162c956b3 --- /dev/null +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts @@ -0,0 +1,47 @@ +import { ICreateAccountEvent } from '@cypherock/coin-support-interfaces'; +import { describe, test } from '@jest/globals'; +import { Observer } from 'rxjs'; +import { makeCreateAccountsObservable } from '../../../src'; +import { createAccountParams } from '../../__mocks__'; +import { fixtures } from './__fixtures__'; + +describe('makeCreateAccountsObservable', () => { + afterEach(() => { + jest.clearAllMocks(); + jest.resetAllMocks(); + }); + + fixtures.valid.forEach(({ name }) => { + test(name, done => { + const params = createAccountParams(); + const createAccountsObservable = makeCreateAccountsObservable(params); + + const observer: Observer = { + next: () => { + // next actions + }, + complete: () => { + expect(true).toBe(true); + done(); + }, + error: err => { + throw err; + }, + }; + + createAccountsObservable.subscribe(observer); + + // for (let i = 0; i < 10; i++) { + // } + + // await new Promise(resolve => { + // mockObserver.complete.mockReturnValue(() => resolve()); + // mockObserver.error.mockReturnValue(() => resolve()); + // }); + + // expect(mockObserver.next).toHaveBeenCalledTimes(1); + // expect(mockObserver.complete).toHaveBeenCalledTimes(1); + // expect(mockObserver.error).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/__fixtures__/derivationPathAddressMap.ts b/packages/coin-support-utils/tests/__fixtures__/derivationPathAddressMap.ts new file mode 100644 index 000000000..8001f126f --- /dev/null +++ b/packages/coin-support-utils/tests/__fixtures__/derivationPathAddressMap.ts @@ -0,0 +1,26 @@ +import { mapDerivationPath } from '../../src'; + +const derivationPathAddressMap = new Map(); + +const pathAddressList = [ + ["m/44'/0'/0'/0/0", 'address_44_0_0_0_0'], + ["m/44'/0'/0'/0/1", 'address_44_0_0_0_1'], + ["m/44'/0'/0'/0/2", 'address_44_0_0_0_2'], + ["m/84'/0'/0'/0/0", 'address_84_0_0_0_0'], + ["m/84'/0'/0'/0/1", 'address_84_0_0_0_1'], + ["m/84'/0'/0'/0/2", 'address_84_0_0_0_2'], + ["m/49'/0'/0'/0/0", 'address_49_0_0_0_0'], + ["m/49'/0'/0'/0/1", 'address_49_0_0_0_1'], + ["m/49'/0'/0'/0/2", 'address_49_0_0_0_2'], +]; + +const putPathAddressEntry = (path: string, address: string) => { + derivationPathAddressMap.set(mapDerivationPath(path).join('#'), address); +}; + +pathAddressList.forEach(([path, address]) => { + putPathAddressEntry(path, address); +}); + +export const getAddressFromPath = (path: number[]) => + derivationPathAddressMap.get(path.join('#')); diff --git a/packages/coin-support-utils/tests/__fixtures__/index.ts b/packages/coin-support-utils/tests/__fixtures__/index.ts new file mode 100644 index 000000000..72b6885ea --- /dev/null +++ b/packages/coin-support-utils/tests/__fixtures__/index.ts @@ -0,0 +1,2 @@ +export * from './derivationPathAddressMap'; +export * from './wallet'; diff --git a/packages/coin-support-utils/tests/__fixtures__/accounts.ts b/packages/coin-support-utils/tests/__fixtures__/wallet.ts similarity index 64% rename from packages/coin-support-utils/tests/__fixtures__/accounts.ts rename to packages/coin-support-utils/tests/__fixtures__/wallet.ts index ed19b4fd2..3f64fc8da 100644 --- a/packages/coin-support-utils/tests/__fixtures__/accounts.ts +++ b/packages/coin-support-utils/tests/__fixtures__/wallet.ts @@ -1,5 +1,15 @@ import { IAccount } from '@cypherock/db-interfaces'; +export const walletId = + 'c372af88f64e0a40439f97ee98a3a0a03e9b2ac348b464d0cab7f32ee8482298'; +export const assetId = { + bitcoin: 'bitcoin', +}; + +export const familyId = { + bitcoin: 'bitcoin', +}; + export const accounts: IAccount[] = [ { name: 'Bitcoin 1', @@ -8,11 +18,10 @@ export const accounts: IAccount[] = [ unit: 'BTC', derivationPath: "m/84'/0'/0'", type: 'account', - familyId: 'bitcoin', - assetId: 'bitcoin', - parentAssetId: 'bitcoin', - walletId: - 'c372af88f64e0a40439f97ee98a3a0a03e9b2ac348b464d0cab7f32ee8482298', + familyId: familyId.bitcoin, + assetId: assetId.bitcoin, + parentAssetId: assetId.bitcoin, + walletId, derivationScheme: 'nativeSegwit', __version: 0, __id: 'da51cef8-aa25-4667-b2da-9b4ef78dcee2', @@ -28,10 +37,10 @@ export const accounts: IAccount[] = [ unit: 'BTC', derivationPath: "m/44'/0'/0'", type: 'account', - familyId: 'bitcoin', - assetId: 'bitcoin', - parentAssetId: 'bitcoin', - walletId: '', + familyId: familyId.bitcoin, + assetId: assetId.bitcoin, + parentAssetId: assetId.bitcoin, + walletId, derivationScheme: 'legacy', __version: 0, __id: '54d86310-66e1-4ca5-ae6a-d7b6cd671eba', diff --git a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts index 75c14f2b0..2d78f22c7 100644 --- a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts +++ b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts @@ -1,29 +1,36 @@ -import { IDatabase } from '@cypherock/db-interfaces'; -import { IMakeCreateAccountsObservableParams } from '../../src/createAccount'; -import { TestApp, testApp } from './app'; -import { IDeviceConnection } from '@cypherock/sdk-interfaces'; +import { + IMakeCreateAccountsObservableParams, + createDerivationPathGenerator, +} from '../../src/createAccount'; +import { TestApp } from './app'; +import { db, getAddressesFromDeviceMock } from '.'; +import { createAppMock } from './createApp'; +import { getBalanceAndTxnCountMock } from './getBalanceAndTxnCount'; -export const createAccountParams = ( - db: IDatabase, - connection: IDeviceConnection, -): IMakeCreateAccountsObservableParams => ({ - createApp: jest.fn().mockResolvedValue(testApp), - derivationPathSchemes: { - legacy: { - threshold: 2, - newAccountLimit: 3, - name: 'ac1', - generator: jest.fn(), +export const createAccountParams = + (): IMakeCreateAccountsObservableParams => ({ + createApp: createAppMock, + derivationPathSchemes: { + legacy: { + name: 'legacy', + generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), + threshold: 2, + newAccountLimit: 0, + }, + segwit: { + name: 'segwit', + generator: createDerivationPathGenerator(`m/49'/0'/0'/0/i`), + threshold: 2, + newAccountLimit: 0, + }, }, - }, - derivationPathLimit: 10, - getBalanceAndTxnCount: jest - .fn() - .mockResolvedValue({ balance: '0', txnCount: 0 }), - getAddressesFromDevice: jest.fn(), - createAccountFromAddress: jest.fn().mockResolvedValue({}), - coinId: 'testCoin', - walletId: 'testWallet', - db, - connection, -}); + derivationPathLimit: 2, + getBalanceAndTxnCount: getBalanceAndTxnCountMock, + getAddressesFromDevice: getAddressesFromDeviceMock, + createAccountFromAddress: jest.fn().mockResolvedValue({}), + coinId: 'testCoin', + walletId: 'testWallet', + db, + connection: {} as any, + waitInMSBetweenEachAccountAPI: 1, + }); diff --git a/packages/coin-support-utils/tests/__mocks__/createApp.ts b/packages/coin-support-utils/tests/__mocks__/createApp.ts new file mode 100644 index 000000000..407265d3b --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/createApp.ts @@ -0,0 +1,7 @@ +import { jest } from '@jest/globals'; +import { IMakeCreateAccountsObservableParams } from '../../src'; +import { TestApp, testApp } from '.'; + +export const createAppMock = jest + .fn['createApp']>() + .mockResolvedValue(testApp); diff --git a/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts b/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts new file mode 100644 index 000000000..8d3539364 --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts @@ -0,0 +1,12 @@ +import { IGetAddressesFromDeviceParams } from '../../src'; +import { TestApp } from '.'; +import { getAddressFromPath } from '../__fixtures__/derivationPathAddressMap'; + +export const getAddressesFromDeviceMock = jest.fn( + async ({ + derivationPaths, + }: IGetAddressesFromDeviceParams): Promise => + derivationPaths.map( + ({ derivationPath }) => getAddressFromPath(derivationPath)!, + ), +); diff --git a/packages/coin-support-utils/tests/__mocks__/getBalanceAndTxnCount.ts b/packages/coin-support-utils/tests/__mocks__/getBalanceAndTxnCount.ts new file mode 100644 index 000000000..2fd6e61bc --- /dev/null +++ b/packages/coin-support-utils/tests/__mocks__/getBalanceAndTxnCount.ts @@ -0,0 +1,7 @@ +import { jest } from '@jest/globals'; +import { IMakeCreateAccountsObservableParams } from '../../src'; +import { TestApp } from '.'; + +export const getBalanceAndTxnCountMock = jest + .fn['getBalanceAndTxnCount']>() + .mockResolvedValue({ balance: '0', txnCount: 0 }); diff --git a/packages/coin-support-utils/tests/__mocks__/index.ts b/packages/coin-support-utils/tests/__mocks__/index.ts index 7546b0191..715530bc5 100644 --- a/packages/coin-support-utils/tests/__mocks__/index.ts +++ b/packages/coin-support-utils/tests/__mocks__/index.ts @@ -1,4 +1,7 @@ export * from './app'; -export * from './createAccountParams'; export * from './observer'; export * from './db'; +export * from './getAddressesFromDevice'; +export * from './getBalanceAndTxnCount'; +export * from './createApp'; +export * from './createAccountParams'; From 8d6857437881a7814a99aec093e69c5a42fd53f7 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Tue, 16 Apr 2024 09:47:32 +0000 Subject: [PATCH 06/18] test: improved branch coverage --- .../src/createAccount/schemes.ts | 13 +++++------- .../__fixtures__/valid.ts | 12 +++++++++++ .../__fixtures__/types.ts | 4 ++-- .../__fixtures__/valid.ts | 20 +++++++++---------- .../03.createAccountNameGenerator/index.ts | 6 ++++-- .../tests/__fixtures__/wallet.ts | 15 ++++++++++++++ 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/packages/coin-support-utils/src/createAccount/schemes.ts b/packages/coin-support-utils/src/createAccount/schemes.ts index a9b911ad2..52c4f5455 100644 --- a/packages/coin-support-utils/src/createAccount/schemes.ts +++ b/packages/coin-support-utils/src/createAccount/schemes.ts @@ -43,11 +43,11 @@ export const generateDerivationPathsPerScheme = ( const existingDerivationPaths = existingAccounts.map(e => e.derivationPath); - const derivationSchemeNames = Object.keys(derivationPathSchemes).filter( - n => !!derivationPathSchemes[n], - ); + const derivationSchemes = Object.entries(derivationPathSchemes).filter( + ([, value]) => value !== undefined, + ) as [string, IDerivationScheme][]; const pathLimitPerDerivationScheme = Math.floor( - limit / derivationSchemeNames.length, + limit / derivationSchemes.length, ); const derivedPathsPerScheme: Record< @@ -56,10 +56,7 @@ export const generateDerivationPathsPerScheme = ( > = {}; const derivedPaths: string[] = []; - for (const schemeName of derivationSchemeNames) { - const derivationPathSchemeDetails = derivationPathSchemes[schemeName]; - if (!derivationPathSchemeDetails) continue; - + for (const [schemeName, derivationPathSchemeDetails] of derivationSchemes) { const paths = derivationPathSchemeDetails.generator( // This is done because there can be overlapping derivation paths // between different schemes diff --git a/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts index b24de612f..c8a3ca1cf 100644 --- a/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/02.createAccount/02.generateDerivationPathPerScheme/__fixtures__/valid.ts @@ -38,6 +38,17 @@ export const valid: DerivationPathPerSchemeGeneratorTestCases[] = [ ], }, }, + { + name: 'should ignore undefined derivation path scheme', + input: { + derivationPathSchemes: { + legacy: undefined, + }, + limit: 4, + existingAccounts: [], + }, + output: {}, + }, { name: 'should generate derivation paths from index zero with multiple schemes', input: { @@ -97,6 +108,7 @@ export const valid: DerivationPathPerSchemeGeneratorTestCases[] = [ threshold: 2, newAccountLimit: 0, // this is getting ignored }, + somethingRandom: undefined, }, limit: 4, existingAccounts: accounts, diff --git a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts index 3d01d61a6..0facb59a4 100644 --- a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts +++ b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/types.ts @@ -4,10 +4,10 @@ export interface AccountNameGeneratorTestCases { name: string; input: { coinName: string; - schemeName: string; existingAccounts: IAccount[]; + schemeNames: string[]; }; - output: string; + output: string[]; } export interface IFixtures { diff --git a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts index 72bc93725..d3054b1f3 100644 --- a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts +++ b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/__fixtures__/valid.ts @@ -3,30 +3,30 @@ import { AccountNameGeneratorTestCases } from './types'; export const valid: AccountNameGeneratorTestCases[] = [ { - name: 'should generate derivation paths from index zero', + name: 'should generate derivation paths from index zero for same scheme', input: { coinName: 'Bitcoin', - schemeName: 'legacy', + schemeNames: ['legacy', 'legacy'], existingAccounts: [], }, - output: 'Bitcoin 1', + output: ['Bitcoin 1', 'Bitcoin 2'], }, { - name: 'should generate derivation paths from index zero', + name: 'should generate derivation paths from index zero for different schemes', input: { coinName: 'Bitcoin', - schemeName: 'legacy', - existingAccounts: accounts, + schemeNames: ['legacy', 'taproot', 'nativeSegwit', 'nativeSegwit'], + existingAccounts: [], }, - output: 'Bitcoin 2', + output: ['Bitcoin 1', 'Bitcoin 1', 'Bitcoin 1', 'Bitcoin 2'], }, { - name: 'should generate derivation paths from index zero', + name: 'should generate derivation paths filtering existing accounts for different schemes', input: { coinName: 'Bitcoin', - schemeName: 'something random', + schemeNames: ['legacy', 'something random'], existingAccounts: accounts, }, - output: 'Bitcoin 1', + output: ['Bitcoin 2', 'Bitcoin 1'], }, ]; diff --git a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts index d0e3024a5..01cf313f7 100644 --- a/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts +++ b/packages/coin-support-utils/tests/02.createAccount/03.createAccountNameGenerator/index.ts @@ -6,8 +6,10 @@ describe('createAccountNameGenerator', () => { fixtures.valid.forEach(({ name, input, output }) => { test(name, () => { const generator = createAccountNameGenerator(input.coinName); - const result = generator(input.schemeName, input.existingAccounts); - expect(result).toBe(output); + input.schemeNames.forEach((schemeName, i) => { + const result = generator(schemeName, input.existingAccounts); + expect(result).toBe(output[i]); + }); }); }); }); diff --git a/packages/coin-support-utils/tests/__fixtures__/wallet.ts b/packages/coin-support-utils/tests/__fixtures__/wallet.ts index 3f64fc8da..d7d91028f 100644 --- a/packages/coin-support-utils/tests/__fixtures__/wallet.ts +++ b/packages/coin-support-utils/tests/__fixtures__/wallet.ts @@ -30,6 +30,21 @@ export const accounts: IAccount[] = [ derivationScheme: 'nativeSegwit', }, }, + { + name: 'Bitcoin 1', + xpubOrAddress: '', + balance: '0', + unit: 'BTC', + derivationPath: "m/86'/0'/0'", + type: 'account', + familyId: familyId.bitcoin, + assetId: assetId.bitcoin, + parentAssetId: assetId.bitcoin, + walletId, + derivationScheme: 'taproot', + __version: 0, + __id: 'da51cef8-aa25-4667-b2da-9b4ef78dcee3', + }, { name: 'Bitcoin 1', xpubOrAddress: '', From b8999ec80b9957c4b737d90898526bf1f0acffb5 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:40:00 +0000 Subject: [PATCH 07/18] test: improved makeCreateAccountsObservable test --- .../src/createAccount/createAccount.ts | 15 ++-- .../src/createAccount/schemes.ts | 1 + .../05.makeCreateAccountsObservable/index.ts | 69 ++++++++++++++----- .../tests/__mocks__/createAccountParams.ts | 57 +++++++-------- .../coin-support-utils/tests/__mocks__/db.ts | 5 +- 5 files changed, 91 insertions(+), 56 deletions(-) diff --git a/packages/coin-support-utils/src/createAccount/createAccount.ts b/packages/coin-support-utils/src/createAccount/createAccount.ts index b627545fe..2947119a2 100644 --- a/packages/coin-support-utils/src/createAccount/createAccount.ts +++ b/packages/coin-support-utils/src/createAccount/createAccount.ts @@ -77,16 +77,15 @@ export function makeCreateAccountsObservable< assetId: params.coinId, }); - const derivationPathsPerScheme = await generateDerivationPathsPerScheme( - { - ...params, - limit: params.derivationPathLimit, - existingAccounts, - }, - ); - if (finished) return; + const derivationPathsPerScheme = generateDerivationPathsPerScheme({ + ...params, + limit: params.derivationPathLimit, + existingAccounts, + }); app = await params.createApp(params.connection); + if (finished) return; + const addressesPerScheme = await generateAddressesPerScheme({ ...params, app, diff --git a/packages/coin-support-utils/src/createAccount/schemes.ts b/packages/coin-support-utils/src/createAccount/schemes.ts index 52c4f5455..53dadbcae 100644 --- a/packages/coin-support-utils/src/createAccount/schemes.ts +++ b/packages/coin-support-utils/src/createAccount/schemes.ts @@ -46,6 +46,7 @@ export const generateDerivationPathsPerScheme = ( const derivationSchemes = Object.entries(derivationPathSchemes).filter( ([, value]) => value !== undefined, ) as [string, IDerivationScheme][]; + const pathLimitPerDerivationScheme = Math.floor( limit / derivationSchemes.length, ); diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts index 162c956b3..39d4215cd 100644 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts @@ -2,46 +2,77 @@ import { ICreateAccountEvent } from '@cypherock/coin-support-interfaces'; import { describe, test } from '@jest/globals'; import { Observer } from 'rxjs'; import { makeCreateAccountsObservable } from '../../../src'; -import { createAccountParams } from '../../__mocks__'; +import { createAccountParams, db } from '../../__mocks__'; import { fixtures } from './__fixtures__'; describe('makeCreateAccountsObservable', () => { + beforeAll(() => { + jest.useFakeTimers(); + }); + afterEach(() => { jest.clearAllMocks(); jest.resetAllMocks(); }); + afterAll(() => { + jest.useRealTimers(); + }); + fixtures.valid.forEach(({ name }) => { test(name, done => { - const params = createAccountParams(); + // mocks + db.account.getAll.mockResolvedValue([]); + + const waitInMSBetweenEachAccountAPI: number | undefined = 250; + + const params = createAccountParams(db, waitInMSBetweenEachAccountAPI); const createAccountsObservable = makeCreateAccountsObservable(params); + const derivationSchemeCount = Object.values( + params.derivationPathSchemes, + ).filter(Boolean).length; + + const totalThreshold = Object.values(params.derivationPathSchemes).reduce( + (acc, scheme) => acc + (scheme?.threshold ?? 0), + 0, + ); + + const newAccountsCount = Math.min( + totalThreshold, + Math.floor(params.derivationPathLimit / derivationSchemeCount) * + derivationSchemeCount, + ); + + // expect.assertions(newAccountsCount + 6) + const observer: Observer = { - next: () => { - // next actions + next: value => { + console.log(value); + if (value.type === 'Account') { + expect(value.account).toBeDefined(); + } }, complete: () => { - expect(true).toBe(true); + expect(db.account.getAll).toHaveBeenCalledTimes(1); + expect(params.createApp).toHaveBeenCalledTimes(1); + expect(params.getAddressesFromDevice).toHaveBeenCalledTimes(1); + expect(params.getBalanceAndTxnCount).toHaveBeenCalledTimes( + newAccountsCount, + ); + expect(params.createAccountFromAddress).toHaveBeenCalledTimes( + newAccountsCount, + ); done(); }, - error: err => { - throw err; - }, + error: done, }; createAccountsObservable.subscribe(observer); - // for (let i = 0; i < 10; i++) { - // } - - // await new Promise(resolve => { - // mockObserver.complete.mockReturnValue(() => resolve()); - // mockObserver.error.mockReturnValue(() => resolve()); - // }); - - // expect(mockObserver.next).toHaveBeenCalledTimes(1); - // expect(mockObserver.complete).toHaveBeenCalledTimes(1); - // expect(mockObserver.error).not.toHaveBeenCalled(); + for (let i = 0; i < newAccountsCount; i += 1) { + jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); + } }); }); }); diff --git a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts index 2d78f22c7..e8d96c811 100644 --- a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts +++ b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts @@ -3,34 +3,37 @@ import { createDerivationPathGenerator, } from '../../src/createAccount'; import { TestApp } from './app'; -import { db, getAddressesFromDeviceMock } from '.'; +import { getAddressesFromDeviceMock } from '.'; import { createAppMock } from './createApp'; import { getBalanceAndTxnCountMock } from './getBalanceAndTxnCount'; +import { IDatabase } from '@cypherock/db-interfaces'; -export const createAccountParams = - (): IMakeCreateAccountsObservableParams => ({ - createApp: createAppMock, - derivationPathSchemes: { - legacy: { - name: 'legacy', - generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), - threshold: 2, - newAccountLimit: 0, - }, - segwit: { - name: 'segwit', - generator: createDerivationPathGenerator(`m/49'/0'/0'/0/i`), - threshold: 2, - newAccountLimit: 0, - }, +export const createAccountParams = ( + db: IDatabase, + waitInMSBetweenEachAccountAPI?: number, +): IMakeCreateAccountsObservableParams => ({ + createApp: createAppMock, + derivationPathSchemes: { + legacy: { + name: 'legacy', + generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), + threshold: 2, + newAccountLimit: 0, }, - derivationPathLimit: 2, - getBalanceAndTxnCount: getBalanceAndTxnCountMock, - getAddressesFromDevice: getAddressesFromDeviceMock, - createAccountFromAddress: jest.fn().mockResolvedValue({}), - coinId: 'testCoin', - walletId: 'testWallet', - db, - connection: {} as any, - waitInMSBetweenEachAccountAPI: 1, - }); + segwit: { + name: 'segwit', + generator: createDerivationPathGenerator(`m/49'/0'/0'/0/i`), + threshold: 2, + newAccountLimit: 0, + }, + }, + derivationPathLimit: 4, + getBalanceAndTxnCount: getBalanceAndTxnCountMock, + getAddressesFromDevice: getAddressesFromDeviceMock, + createAccountFromAddress: jest.fn().mockResolvedValue({}), + coinId: 'testCoin', + walletId: 'testWallet', + db, + connection: {} as any, + waitInMSBetweenEachAccountAPI, +}); diff --git a/packages/coin-support-utils/tests/__mocks__/db.ts b/packages/coin-support-utils/tests/__mocks__/db.ts index 70a894640..75c7701d1 100644 --- a/packages/coin-support-utils/tests/__mocks__/db.ts +++ b/packages/coin-support-utils/tests/__mocks__/db.ts @@ -1,7 +1,8 @@ import { IDatabase } from '@cypherock/db-interfaces'; +import { jest } from '@jest/globals'; -export const db: IDatabase = { +export const db: jest.MockedObject = { account: { - getAll: jest.fn(() => []), + getAll: jest.fn(), }, } as any; From da86830a7875af48407659574ca77c2e2288a8c4 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:32:54 +0530 Subject: [PATCH 08/18] test: makeCreateAccountsObservable --- .../05.makeCreateAccountsObservable/index.ts | 179 ++++++++++++------ .../tests/__mocks__/createAccountParams.ts | 11 +- .../tests/__mocks__/getAddressesFromDevice.ts | 16 +- 3 files changed, 137 insertions(+), 69 deletions(-) diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts index 39d4215cd..e20e0b2f7 100644 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts @@ -1,15 +1,23 @@ import { ICreateAccountEvent } from '@cypherock/coin-support-interfaces'; import { describe, test } from '@jest/globals'; -import { Observer } from 'rxjs'; +import { Observer, Subscription } from 'rxjs'; import { makeCreateAccountsObservable } from '../../../src'; -import { createAccountParams, db } from '../../__mocks__'; -import { fixtures } from './__fixtures__'; +import { + createAccountParams, + createAppMock, + db, + testApp, +} from '../../__mocks__'; describe('makeCreateAccountsObservable', () => { beforeAll(() => { jest.useFakeTimers(); }); + beforeEach(() => { + jest.restoreAllMocks(); + }); + afterEach(() => { jest.clearAllMocks(); jest.resetAllMocks(); @@ -19,60 +27,117 @@ describe('makeCreateAccountsObservable', () => { jest.useRealTimers(); }); - fixtures.valid.forEach(({ name }) => { - test(name, done => { - // mocks - db.account.getAll.mockResolvedValue([]); - - const waitInMSBetweenEachAccountAPI: number | undefined = 250; - - const params = createAccountParams(db, waitInMSBetweenEachAccountAPI); - const createAccountsObservable = makeCreateAccountsObservable(params); - - const derivationSchemeCount = Object.values( - params.derivationPathSchemes, - ).filter(Boolean).length; - - const totalThreshold = Object.values(params.derivationPathSchemes).reduce( - (acc, scheme) => acc + (scheme?.threshold ?? 0), - 0, - ); - - const newAccountsCount = Math.min( - totalThreshold, - Math.floor(params.derivationPathLimit / derivationSchemeCount) * - derivationSchemeCount, - ); - - // expect.assertions(newAccountsCount + 6) - - const observer: Observer = { - next: value => { - console.log(value); - if (value.type === 'Account') { - expect(value.account).toBeDefined(); - } - }, - complete: () => { - expect(db.account.getAll).toHaveBeenCalledTimes(1); - expect(params.createApp).toHaveBeenCalledTimes(1); - expect(params.getAddressesFromDevice).toHaveBeenCalledTimes(1); - expect(params.getBalanceAndTxnCount).toHaveBeenCalledTimes( - newAccountsCount, - ); - expect(params.createAccountFromAddress).toHaveBeenCalledTimes( - newAccountsCount, - ); - done(); - }, - error: done, - }; - - createAccountsObservable.subscribe(observer); - - for (let i = 0; i < newAccountsCount; i += 1) { - jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); - } + test('should create new accounts', done => { + db.account.getAll.mockResolvedValue([]); + + const waitInMSBetweenEachAccountAPI: number | undefined = 250; + + const params = createAccountParams(db, waitInMSBetweenEachAccountAPI); + const createAccountsObservable = makeCreateAccountsObservable(params); + + const derivationSchemeCount = Object.values( + params.derivationPathSchemes, + ).filter(Boolean).length; + + const totalNewAccountLimit = Object.values( + params.derivationPathSchemes, + ).reduce((acc, scheme) => acc + (scheme?.newAccountLimit ?? 0), 0); + + const newAccountsCount = Math.min( + totalNewAccountLimit, + Math.floor(params.derivationPathLimit / derivationSchemeCount) * + derivationSchemeCount, + ); + + expect.assertions(newAccountsCount + 5); + + const observer: Observer = { + next: value => { + if (value.type === 'Account') { + expect(value.account).toBeDefined(); + } + }, + complete: () => { + expect(db.account.getAll).toHaveBeenCalledTimes(1); + expect(params.createApp).toHaveBeenCalledTimes(1); + expect(params.getAddressesFromDevice).toHaveBeenCalledTimes(1); + expect(params.getBalanceAndTxnCount).toHaveBeenCalledTimes( + newAccountsCount, + ); + expect(params.createAccountFromAddress).toHaveBeenCalledTimes( + newAccountsCount, + ); + done(); + }, + error: done, + }; + + createAccountsObservable.subscribe(observer); + + for (let i = 0; i < newAccountsCount; i += 1) { + jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); + } + }); + + test('should unsubscribe', done => { + let subscription: Subscription | undefined; + db.account.getAll.mockResolvedValue([]); + + const waitInMSBetweenEachAccountAPI: number | undefined = 250; + + const params = createAccountParams(db, waitInMSBetweenEachAccountAPI); + + createAppMock.mockImplementation(async () => { + subscription?.unsubscribe(); + return testApp; }); + + const createAccountsObservable = makeCreateAccountsObservable(params); + + const derivationSchemeCount = Object.values( + params.derivationPathSchemes, + ).filter(Boolean).length; + + const totalNewAccountLimit = Object.values( + params.derivationPathSchemes, + ).reduce((acc, scheme) => acc + (scheme?.newAccountLimit ?? 0), 0); + + const newAccountsCount = Math.min( + totalNewAccountLimit, + Math.floor(params.derivationPathLimit / derivationSchemeCount) * + derivationSchemeCount, + ); + + expect.assertions(5); + + const observer: Observer = { + next: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + complete: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + error: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + }; + + subscription = createAccountsObservable.subscribe(observer); + + setTimeout(() => { + expect(db.account.getAll).toHaveBeenCalledTimes(1); + expect(params.createApp).toHaveBeenCalledTimes(1); + expect(params.getAddressesFromDevice).toHaveBeenCalledTimes(0); + expect(params.getBalanceAndTxnCount).toHaveBeenCalledTimes(0); + expect(params.createAccountFromAddress).toHaveBeenCalledTimes(0); + done(); + }, 0); + + for (let i = 0; i < newAccountsCount; i += 1) { + jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); + } }); }); diff --git a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts index e8d96c811..196429faa 100644 --- a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts +++ b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts @@ -1,12 +1,12 @@ +import { IDatabase } from '@cypherock/db-interfaces'; +import { getAddressesFromDeviceMock } from '.'; import { IMakeCreateAccountsObservableParams, createDerivationPathGenerator, } from '../../src/createAccount'; import { TestApp } from './app'; -import { getAddressesFromDeviceMock } from '.'; import { createAppMock } from './createApp'; import { getBalanceAndTxnCountMock } from './getBalanceAndTxnCount'; -import { IDatabase } from '@cypherock/db-interfaces'; export const createAccountParams = ( db: IDatabase, @@ -18,16 +18,17 @@ export const createAccountParams = ( name: 'legacy', generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), threshold: 2, - newAccountLimit: 0, + newAccountLimit: 2, }, + nativeSegwit: undefined, segwit: { name: 'segwit', generator: createDerivationPathGenerator(`m/49'/0'/0'/0/i`), threshold: 2, - newAccountLimit: 0, + newAccountLimit: 2, }, }, - derivationPathLimit: 4, + derivationPathLimit: 2, getBalanceAndTxnCount: getBalanceAndTxnCountMock, getAddressesFromDevice: getAddressesFromDeviceMock, createAccountFromAddress: jest.fn().mockResolvedValue({}), diff --git a/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts b/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts index 8d3539364..4a7a47de9 100644 --- a/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts +++ b/packages/coin-support-utils/tests/__mocks__/getAddressesFromDevice.ts @@ -1,12 +1,14 @@ -import { IGetAddressesFromDeviceParams } from '../../src'; import { TestApp } from '.'; +import { IGetAddressesFromDeviceParams } from '../../src'; import { getAddressFromPath } from '../__fixtures__/derivationPathAddressMap'; +export const getAddressesFromDeviceImplementation = async ({ + derivationPaths, +}: IGetAddressesFromDeviceParams): Promise => + derivationPaths.map( + ({ derivationPath }) => getAddressFromPath(derivationPath)!, + ); + export const getAddressesFromDeviceMock = jest.fn( - async ({ - derivationPaths, - }: IGetAddressesFromDeviceParams): Promise => - derivationPaths.map( - ({ derivationPath }) => getAddressFromPath(derivationPath)!, - ), + getAddressesFromDeviceImplementation, ); From b20ec448b3ac62e5d2f19c8246dc8e39f04e36b8 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:50:12 +0530 Subject: [PATCH 09/18] test: don't run coin-support-utils test --- packages/coin-support-utils/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/coin-support-utils/package.json b/packages/coin-support-utils/package.json index 0aebad0e2..cf818fb5e 100644 --- a/packages/coin-support-utils/package.json +++ b/packages/coin-support-utils/package.json @@ -15,8 +15,7 @@ "build:cjs": "tsc -p tsconfig_cjs.json", "build:esm": "tsc -p tsconfig.json", "build:dirty": "pnpm build:esm", - "pre-commit": "lint-staged", - "test": "jest" + "pre-commit": "lint-staged" }, "devDependencies": { "@cypherock/eslint-config": "workspace:^", From 06d03a6d1a7ceaa021caeee22a1ace838fd3eae0 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:22:14 +0530 Subject: [PATCH 10/18] test: undo don't run coin-support-utils test --- packages/coin-support-utils/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/coin-support-utils/package.json b/packages/coin-support-utils/package.json index cf818fb5e..0aebad0e2 100644 --- a/packages/coin-support-utils/package.json +++ b/packages/coin-support-utils/package.json @@ -15,7 +15,8 @@ "build:cjs": "tsc -p tsconfig_cjs.json", "build:esm": "tsc -p tsconfig.json", "build:dirty": "pnpm build:esm", - "pre-commit": "lint-staged" + "pre-commit": "lint-staged", + "test": "jest" }, "devDependencies": { "@cypherock/eslint-config": "workspace:^", From a1bd014c327341718a76ce88898c5e8fcd0aecb6 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:41:24 +0530 Subject: [PATCH 11/18] ci: changed ubuntu version to 22.04 --- .github/workflows/build-early.yml | 6 +++--- .github/workflows/build-prerelease.yml | 6 +++--- .github/workflows/build-release.yml | 6 +++--- .github/workflows/npm-release.yml | 2 +- .github/workflows/test-e2e.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-early.yml b/.github/workflows/build-early.yml index 7ffc485c8..c4287d4f4 100644 --- a/.github/workflows/build-early.yml +++ b/.github/workflows/build-early.yml @@ -21,7 +21,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: @@ -77,7 +77,7 @@ jobs: run: pnpm test build-linux: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [integrity-check] strategy: @@ -302,7 +302,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/build-prerelease.yml b/.github/workflows/build-prerelease.yml index 70cf76ef2..7f5b2b890 100644 --- a/.github/workflows/build-prerelease.yml +++ b/.github/workflows/build-prerelease.yml @@ -15,7 +15,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: @@ -89,7 +89,7 @@ jobs: git push origin ${{ inputs.ref }} build-linux: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [integrity-check] strategy: @@ -296,7 +296,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index c65f3ee0f..089aab194 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -15,7 +15,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: @@ -86,7 +86,7 @@ jobs: git push origin ${{ inputs.ref }} build-linux: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [integrity-check] strategy: @@ -293,7 +293,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml index 30a98d546..00897ec32 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/npm-release.yml @@ -14,7 +14,7 @@ env: jobs: npm-release: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 99cace3c7..46df6b3ff 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -22,7 +22,7 @@ env: jobs: test-e2e: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 timeout-minutes: 30 strategy: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0974bba2..9beda9586 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ env: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 timeout-minutes: 30 strategy: From 0a395840ce0663b5bb00f4a8a6e884115c45e1b2 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:55:26 +0530 Subject: [PATCH 12/18] ci: undo changed ubuntu version to 22.04 --- .github/workflows/build-early.yml | 6 +++--- .github/workflows/build-prerelease.yml | 6 +++--- .github/workflows/build-release.yml | 6 +++--- .github/workflows/npm-release.yml | 2 +- .github/workflows/test-e2e.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-early.yml b/.github/workflows/build-early.yml index c4287d4f4..7ffc485c8 100644 --- a/.github/workflows/build-early.yml +++ b/.github/workflows/build-early.yml @@ -21,7 +21,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: @@ -77,7 +77,7 @@ jobs: run: pnpm test build-linux: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [integrity-check] strategy: @@ -302,7 +302,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/build-prerelease.yml b/.github/workflows/build-prerelease.yml index 7f5b2b890..70cf76ef2 100644 --- a/.github/workflows/build-prerelease.yml +++ b/.github/workflows/build-prerelease.yml @@ -15,7 +15,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: @@ -89,7 +89,7 @@ jobs: git push origin ${{ inputs.ref }} build-linux: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [integrity-check] strategy: @@ -296,7 +296,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 089aab194..c65f3ee0f 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -15,7 +15,7 @@ env: jobs: integrity-check: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: @@ -86,7 +86,7 @@ jobs: git push origin ${{ inputs.ref }} build-linux: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [integrity-check] strategy: @@ -293,7 +293,7 @@ jobs: retention-days: 1 publish-build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: [build-win, build-linux, build-macos] strategy: diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml index 00897ec32..30a98d546 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/npm-release.yml @@ -14,7 +14,7 @@ env: jobs: npm-release: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 46df6b3ff..99cace3c7 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -22,7 +22,7 @@ env: jobs: test-e2e: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest timeout-minutes: 30 strategy: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9beda9586..b0974bba2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ env: jobs: test: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest timeout-minutes: 30 strategy: From fcec4909b22c89745e21c1fa4db55f3110749117 Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 22 Apr 2024 01:45:28 +0530 Subject: [PATCH 13/18] chore: skip turbo cache for test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e4c95436..b801616a0 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pretty:root:check": "prettier --check scripts *.json", "lint:check": "turbo run lint:check --no-daemon", "pretty:check": "pnpm pretty:root:check && turbo run pretty:check --no-daemon", - "test": "cross-env NODE_ENV=test turbo run test --no-daemon && pnpm aggregate:report", + "test": "cross-env NODE_ENV=test turbo run test --force --no-daemon && pnpm aggregate:report", "aggregate:report": "cross-env NODE_ENV=test node scripts/aggregateReport.js", "e2e": "turbo run e2e --no-daemon", "pre-commit": "turbo run pre-commit --concurrency=1 --no-daemon", From 89b8a070b8aa15f2a2c68f48cc0ae2d98452cfaf Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:24:13 +0530 Subject: [PATCH 14/18] chore: undo skip turbo cache for test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b801616a0..2e4c95436 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pretty:root:check": "prettier --check scripts *.json", "lint:check": "turbo run lint:check --no-daemon", "pretty:check": "pnpm pretty:root:check && turbo run pretty:check --no-daemon", - "test": "cross-env NODE_ENV=test turbo run test --force --no-daemon && pnpm aggregate:report", + "test": "cross-env NODE_ENV=test turbo run test --no-daemon && pnpm aggregate:report", "aggregate:report": "cross-env NODE_ENV=test node scripts/aggregateReport.js", "e2e": "turbo run e2e --no-daemon", "pre-commit": "turbo run pre-commit --concurrency=1 --no-daemon", From 0c640f316ecb887d64a8bf6e556fa36f3b794d68 Mon Sep 17 00:00:00 2001 From: jhasuraj01 <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:57:46 +0530 Subject: [PATCH 15/18] test: removed unwanted files and imporved branch coverage --- .../__fixtures__/index.ts | 6 -- .../__fixtures__/types.ts | 7 -- .../__fixtures__/valid.ts | 7 -- .../05.makeCreateAccountsObservable/index.ts | 69 ++++++++++++++++++- .../tests/__mocks__/createAccountParams.ts | 13 ++-- 5 files changed, 76 insertions(+), 26 deletions(-) delete mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts delete mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts delete mode 100644 packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts deleted file mode 100644 index 9dab336a9..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IFixtures } from './types'; -import { valid } from './valid'; - -export const fixtures: IFixtures = { - valid, -}; diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts deleted file mode 100644 index ab7775345..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface MakeCreateAccountsObservableTestCase { - name: string; -} - -export interface IFixtures { - valid: MakeCreateAccountsObservableTestCase[]; -} diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts deleted file mode 100644 index f23daa2cc..000000000 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/__fixtures__/valid.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { MakeCreateAccountsObservableTestCase } from './types'; - -export const valid: MakeCreateAccountsObservableTestCase[] = [ - { - name: 'should run test without timeout', - }, -]; diff --git a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts index e20e0b2f7..5b99d27ba 100644 --- a/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts +++ b/packages/coin-support-utils/tests/02.createAccount/05.makeCreateAccountsObservable/index.ts @@ -6,9 +6,14 @@ import { createAccountParams, createAppMock, db, + getAddressesFromDeviceImplementation, + getAddressesFromDeviceMock, testApp, } from '../../__mocks__'; +/** + * @todo Increase branch coverage + */ describe('makeCreateAccountsObservable', () => { beforeAll(() => { jest.useFakeTimers(); @@ -79,7 +84,7 @@ describe('makeCreateAccountsObservable', () => { } }); - test('should unsubscribe', done => { + test('should unsubscribe after creating app', done => { let subscription: Subscription | undefined; db.account.getAll.mockResolvedValue([]); @@ -140,4 +145,66 @@ describe('makeCreateAccountsObservable', () => { jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); } }); + + test('should unsubscribe after generating address from device', done => { + let subscription: Subscription | undefined; + db.account.getAll.mockResolvedValue([]); + + const waitInMSBetweenEachAccountAPI: number | undefined = 250; + + const params = createAccountParams(db, waitInMSBetweenEachAccountAPI); + + getAddressesFromDeviceMock.mockImplementation(async (...args) => { + subscription?.unsubscribe(); + return getAddressesFromDeviceImplementation(...args); + }); + + const createAccountsObservable = makeCreateAccountsObservable(params); + + const derivationSchemeCount = Object.values( + params.derivationPathSchemes, + ).filter(Boolean).length; + + const totalNewAccountLimit = Object.values( + params.derivationPathSchemes, + ).reduce((acc, scheme) => acc + (scheme?.newAccountLimit ?? 0), 0); + + const newAccountsCount = Math.min( + totalNewAccountLimit, + Math.floor(params.derivationPathLimit / derivationSchemeCount) * + derivationSchemeCount, + ); + + expect.assertions(5); + + const observer: Observer = { + next: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + complete: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + error: () => { + // shouldn't reach here + expect(true).toBe(false); + }, + }; + + subscription = createAccountsObservable.subscribe(observer); + + setTimeout(() => { + expect(db.account.getAll).toHaveBeenCalledTimes(1); + expect(params.createApp).toHaveBeenCalledTimes(1); + expect(params.getAddressesFromDevice).toHaveBeenCalledTimes(1); + expect(params.getBalanceAndTxnCount).toHaveBeenCalledTimes(0); + expect(params.createAccountFromAddress).toHaveBeenCalledTimes(0); + done(); + }, 0); + + for (let i = 0; i < newAccountsCount; i += 1) { + jest.advanceTimersByTimeAsync(waitInMSBetweenEachAccountAPI ?? 500); + } + }); }); diff --git a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts index 196429faa..36d14d9ea 100644 --- a/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts +++ b/packages/coin-support-utils/tests/__mocks__/createAccountParams.ts @@ -11,24 +11,27 @@ import { getBalanceAndTxnCountMock } from './getBalanceAndTxnCount'; export const createAccountParams = ( db: IDatabase, waitInMSBetweenEachAccountAPI?: number, + thresholdPerScheme?: number, + newAccountLimitPerScheme?: number, + derivationPathLimit?: number, ): IMakeCreateAccountsObservableParams => ({ createApp: createAppMock, derivationPathSchemes: { legacy: { name: 'legacy', generator: createDerivationPathGenerator("m/44'/0'/0'/0/i"), - threshold: 2, - newAccountLimit: 2, + threshold: thresholdPerScheme ?? 2, + newAccountLimit: newAccountLimitPerScheme ?? 2, }, nativeSegwit: undefined, segwit: { name: 'segwit', generator: createDerivationPathGenerator(`m/49'/0'/0'/0/i`), - threshold: 2, - newAccountLimit: 2, + threshold: thresholdPerScheme ?? 2, + newAccountLimit: newAccountLimitPerScheme ?? 2, }, }, - derivationPathLimit: 2, + derivationPathLimit: derivationPathLimit ?? 2, getBalanceAndTxnCount: getBalanceAndTxnCountMock, getAddressesFromDevice: getAddressesFromDeviceMock, createAccountFromAddress: jest.fn().mockResolvedValue({}), From 0777687923bf1977d84a4d212dc306251b16a75f Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:20:59 +0530 Subject: [PATCH 16/18] chore: skip turbo cache for test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e4c95436..b801616a0 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pretty:root:check": "prettier --check scripts *.json", "lint:check": "turbo run lint:check --no-daemon", "pretty:check": "pnpm pretty:root:check && turbo run pretty:check --no-daemon", - "test": "cross-env NODE_ENV=test turbo run test --no-daemon && pnpm aggregate:report", + "test": "cross-env NODE_ENV=test turbo run test --force --no-daemon && pnpm aggregate:report", "aggregate:report": "cross-env NODE_ENV=test node scripts/aggregateReport.js", "e2e": "turbo run e2e --no-daemon", "pre-commit": "turbo run pre-commit --concurrency=1 --no-daemon", From 66181f2f1cccd61dfa459aef6e9495633da34d0d Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:50:18 +0530 Subject: [PATCH 17/18] chore: undo skip turbo cache for test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b801616a0..2e4c95436 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "pretty:root:check": "prettier --check scripts *.json", "lint:check": "turbo run lint:check --no-daemon", "pretty:check": "pnpm pretty:root:check && turbo run pretty:check --no-daemon", - "test": "cross-env NODE_ENV=test turbo run test --force --no-daemon && pnpm aggregate:report", + "test": "cross-env NODE_ENV=test turbo run test --no-daemon && pnpm aggregate:report", "aggregate:report": "cross-env NODE_ENV=test node scripts/aggregateReport.js", "e2e": "turbo run e2e --no-daemon", "pre-commit": "turbo run pre-commit --concurrency=1 --no-daemon", From 4d478bd652265f70befb0ef13f8759228e950dbe Mon Sep 17 00:00:00 2001 From: Suraj Jha <44930179+jhasuraj01@users.noreply.github.com> Date: Tue, 23 Apr 2024 06:51:12 +0000 Subject: [PATCH 18/18] test: initiated db operation tests --- .../01.getUniqueAccountQuery/index.ts | 20 +++++++++++++++++ .../__fixtures__/index.ts | 0 .../02.getAccountAndCoin/__fixtures__/type.ts | 22 +++++++++++++++++++ .../__fixtures__/valid.ts | 0 .../01.account/02.getAccountAndCoin/index.ts | 5 +++++ .../__fixtures__/index.ts | 0 .../__fixtures__/type.ts | 3 +++ .../__fixtures__/valid.ts | 0 .../03.insertAccountIfNotExists/index.ts | 5 +++++ .../__fixtures__/index.ts | 0 .../__fixtures__/type.ts | 3 +++ .../__fixtures__/valid.ts | 0 .../04.insertOrUpdateAccounts/index.ts | 5 +++++ .../05.updateAccount/__fixtures__/index.ts | 0 .../05.updateAccount/__fixtures__/type.ts | 3 +++ .../05.updateAccount/__fixtures__/valid.ts | 0 .../01.account/05.updateAccount/index.ts | 5 +++++ .../06.hideAccount/__fixtures__/index.ts | 0 .../06.hideAccount/__fixtures__/type.ts | 3 +++ .../06.hideAccount/__fixtures__/valid.ts | 0 .../03.db/01.account/06.hideAccount/index.ts | 5 +++++ .../__fixtures__/index.ts | 0 .../__fixtures__/type.ts | 3 +++ .../__fixtures__/valid.ts | 0 .../index.ts | 5 +++++ 25 files changed, 87 insertions(+) create mode 100644 packages/coin-support-utils/tests/03.db/01.account/01.getUniqueAccountQuery/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/index.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/type.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/valid.ts create mode 100644 packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/index.ts diff --git a/packages/coin-support-utils/tests/03.db/01.account/01.getUniqueAccountQuery/index.ts b/packages/coin-support-utils/tests/03.db/01.account/01.getUniqueAccountQuery/index.ts new file mode 100644 index 000000000..12a11870b --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/01.getUniqueAccountQuery/index.ts @@ -0,0 +1,20 @@ +import { describe, test } from '@jest/globals'; +import { accounts } from '../../../__fixtures__'; +import { getUniqueAccountQuery } from '../../../../src'; + +describe('getUniqueAccountQuery', () => { + test('should return a query object with the unique fields of the account', () => { + accounts.forEach(account => { + const accountQuery = getUniqueAccountQuery(account); + expect(accountQuery).toBeTruthy(); + expect(accountQuery.walletId).toBe(account.walletId); + expect(accountQuery.assetId).toBe(account.assetId); + expect(accountQuery.familyId).toBe(account.familyId); + expect(accountQuery.parentAccountId).toBe(account.parentAccountId); + expect(accountQuery.parentAssetId).toBe(account.parentAssetId); + expect(accountQuery.type).toBe(account.type); + expect(accountQuery.derivationPath).toBe(account.derivationPath); + expect(accountQuery.derivationScheme).toBe(account.derivationScheme); + }); + }); +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/type.ts new file mode 100644 index 000000000..fe09bd20e --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/type.ts @@ -0,0 +1,22 @@ +import { IAccount } from '@cypherock/db-interfaces'; + +type CoinType = any; + +export interface GetAccountAndCoinTestCase { + input: { + accountId: string; + db: { + account: IAccount[]; + }; + coinList: Record; + }; + output: { + account: IAccount; + parentAccount: IAccount; + coin: Exclude; + }; +} + +export interface IFixtures { + valid: GetAccountAndCoinTestCase[]; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/index.ts b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/index.ts new file mode 100644 index 000000000..40a75afb4 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/02.getAccountAndCoin/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('getAccountAndCoin', () => { + // getAccountAndCoin +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/type.ts new file mode 100644 index 000000000..f540aad11 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/type.ts @@ -0,0 +1,3 @@ +export interface IFixtures { + valid: any; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/index.ts b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/index.ts new file mode 100644 index 000000000..8fc7e8342 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/03.insertAccountIfNotExists/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('insertAccountIfNotExists', () => { + // insertAccountIfNotExists +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/type.ts new file mode 100644 index 000000000..f540aad11 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/type.ts @@ -0,0 +1,3 @@ +export interface IFixtures { + valid: any; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/index.ts b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/index.ts new file mode 100644 index 000000000..ea27c031b --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/04.insertOrUpdateAccounts/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('insertOrUpdateAccounts', () => { + // insertOrUpdateAccounts +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/type.ts new file mode 100644 index 000000000..f540aad11 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/type.ts @@ -0,0 +1,3 @@ +export interface IFixtures { + valid: any; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/index.ts b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/index.ts new file mode 100644 index 000000000..5327f401f --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/05.updateAccount/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('updateAccount', () => { + // updateAccount +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/type.ts new file mode 100644 index 000000000..f540aad11 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/type.ts @@ -0,0 +1,3 @@ +export interface IFixtures { + valid: any; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/index.ts b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/index.ts new file mode 100644 index 000000000..ae2decf10 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/06.hideAccount/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('hideAccount', () => { + // hideAccount +}); diff --git a/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/index.ts b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/type.ts b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/type.ts new file mode 100644 index 000000000..f540aad11 --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/type.ts @@ -0,0 +1,3 @@ +export interface IFixtures { + valid: any; +} diff --git a/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/valid.ts b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/__fixtures__/valid.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/index.ts b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/index.ts new file mode 100644 index 000000000..eb3065f4e --- /dev/null +++ b/packages/coin-support-utils/tests/03.db/01.account/07.unhideOrInsertAccountIfNotExists/index.ts @@ -0,0 +1,5 @@ +import { describe } from '@jest/globals'; + +describe('unhideOrInsertAccountIfNotExists', () => { + // unhideOrInsertAccountIfNotExists +});