Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Introduce a way to ignore preload data in dataset tests (#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakim authored and lambertkevin committed Apr 11, 2022
1 parent bc5e632 commit 2089d2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/__tests__/test-helpers/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export function testBridge<T extends Transaction>(
scanAccounts,
FIXME_ignoreAccountFields,
FIXME_ignoreOperationFields,
FIXME_ignorePreloadFields,
} = currencyData;
test("functions are defined", () => {
expect(typeof bridge.scanAccounts).toBe("function");
Expand All @@ -170,18 +171,21 @@ export function testBridge<T extends Transaction>(
});
test("preload and rehydrate", async () => {
const data1 = await bridge.preload(currency);
bridge.hydrate(data1, currency);
const data1filtered = omit(data1, FIXME_ignorePreloadFields || []);

if (data1) {
const serialized1 = JSON.parse(JSON.stringify(data1));
bridge.hydrate(data1filtered, currency);

if (data1filtered) {
const serialized1 = JSON.parse(JSON.stringify(data1filtered));
bridge.hydrate(serialized1, currency);
expect(serialized1).toBeDefined();
const data2 = await bridge.preload(currency);
const data2filtered = omit(data2, FIXME_ignorePreloadFields || []);

if (data2) {
bridge.hydrate(data2, currency);
expect(data1).toMatchObject(data2);
const serialized2 = JSON.parse(JSON.stringify(data2));
if (data2filtered) {
bridge.hydrate(data2filtered, currency);
expect(data1filtered).toMatchObject(data2filtered);
const serialized2 = JSON.parse(JSON.stringify(data2filtered));
expect(serialized1).toMatchObject(serialized2);
bridge.hydrate(serialized2, currency);
}
Expand Down
3 changes: 3 additions & 0 deletions src/families/solana/test-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const zero = new BigNumber(0);

const solana: CurrenciesData<Transaction> = {
scanAccounts: [scanAccounts1],
// FIXME Ordering of validators must be always the same, for this test to be stable:
// https://github.com/LedgerHQ/ledger-live-common/blob/develop/src/__tests__/test-helpers/bridge.ts#L171-L188
FIXME_ignorePreloadFields: ["validators"],
accounts: [
{
raw: makeAccount(testOnChainData.fundedSenderAddress),
Expand Down
2 changes: 2 additions & 0 deletions src/families/solana/validator-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,7 @@ export async function getValidators(
return undefined;
};

// FIXME Ordering of validators must be always the same, for this test to be stable:
// https://github.com/LedgerHQ/ledger-live-common/blob/develop/src/__tests__/test-helpers/bridge.ts#L171-L188
return compact(allRawValidators.map(tryFromRawValidator));
}
1 change: 1 addition & 0 deletions src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type ExpectFn = (...args: Array<any>) => any;
export type CurrenciesData<T extends Transaction> = {
FIXME_ignoreAccountFields?: string[];
FIXME_ignoreOperationFields?: string[];
FIXME_ignorePreloadFields?: string[];
mockDeviceOptions?: any;
scanAccounts?: Array<{
name: string;
Expand Down

0 comments on commit 2089d2d

Please sign in to comment.