UNPKG

@ledgerhq/live-common

Version:
95 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("@ledgerhq/coin-aptos/constants"); const store_1 = require("@ledgerhq/live-wallet/store"); const DataModel_1 = require("./DataModel"); const account_1 = require("./account"); const config_1 = require("./config"); const index_1 = require("@ledgerhq/coin-framework/crypto-assets/index"); jest.mock("./config", () => ({ getCurrencyConfiguration: jest.fn(), })); const opRetentionStategy = (maxDaysOld, keepFirst) => (op, index) => index < keepFirst || Date.now() - op.date.getTime() < 1000 * 60 * 60 * 24 * maxDaysOld; const schema = { migrations: [raw => raw], decode: (raw) => [(0, account_1.fromAccountRaw)(raw), (0, store_1.accountRawToAccountUserData)(raw)], encode: ([account, userData]) => (0, account_1.toAccountRaw)({ ...account, operations: account.operations.filter(opRetentionStategy(366, 500)), }, userData), }; const cryptoOrgAccount = { data: { currencyId: "crypto_org", }, version: 1, }; const aptosAccount = { data: { currencyId: "aptos", freshAddressPath: constants_1.APTOS_NON_HARDENED_DERIVATION_PATH, }, version: 1, }; const evmAccount = { data: { currencyId: "ethereum", operations: [ { id: "op_evm_001", }, { id: "op_evm_002", nftOperations: [{ id: "op_evm_nft_001" }], }, ], }, version: 1, }; describe("DataModel", () => { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions (0, index_1.setCryptoAssetsStore)({ findTokenById: (_) => undefined, findTokenByAddressInCurrency: (_, __) => undefined, }); test("createDataModel for crypto.org account", () => { const migratedCryptoOrgAccount = (0, DataModel_1.createDataModel)(schema).decode(cryptoOrgAccount); expect(migratedCryptoOrgAccount.length).toBeGreaterThan(0); const migratedCryptoOrgAccountRaw = migratedCryptoOrgAccount.at(0); expect(migratedCryptoOrgAccountRaw.cosmosResources).toBeDefined(); }); test("createDataModel for aptos account", () => { const migratedAptosAccount = (0, DataModel_1.createDataModel)(schema).decode(aptosAccount); expect(migratedAptosAccount.length).toBeGreaterThan(0); const migratedAptosAccountRaw = migratedAptosAccount.at(0); expect(migratedAptosAccountRaw.freshAddressPath).toEqual(constants_1.APTOS_HARDENED_DERIVATION_PATH); }); describe("test for shownNfts true", () => { beforeAll(() => { config_1.getCurrencyConfiguration.mockReturnValue({ showNfts: true, }); }); test("evm account", () => { const data = (0, DataModel_1.createDataModel)(schema).decode(evmAccount); const account = data.at(0); expect(account.operations).toEqual([ expect.objectContaining({ id: "op_evm_001" }), expect.objectContaining({ id: "op_evm_002" }), ]); }); }); describe("test for shownNfts false", () => { beforeAll(() => { config_1.getCurrencyConfiguration.mockReturnValue({ showNfts: false, }); }); test("evm account", () => { const data = (0, DataModel_1.createDataModel)(schema).decode(evmAccount); const account = data.at(0); expect(account.operations).toEqual([expect.objectContaining({ id: "op_evm_001" })]); }); }); }); //# sourceMappingURL=DataModel.test.js.map