UNPKG

@ic-wallet-kit/hpl

Version:
112 lines (111 loc) 5.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const principal_1 = require("@dfinity/principal"); const mockConstrains_1 = require("../../../__tests_utils/mockConstrains"); const mockLogger_1 = require("../../../__tests_utils/mockLogger"); const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity"); const hplRemoteAccountsStateCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplRemoteAccountsStateCacheDataHandler/hplRemoteAccountsStateCacheDataHandler"); const repositories_1 = require("../../../repositories"); const common_1 = require("@ic-wallet-kit/common"); describe("Unit HplVirtualAccountsStateCacheDataHandler tests", () => { const testData = [ { name: "get accounts state from canister", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(0), remoteAccounts: [{ idRange: [principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"), BigInt(0), []] }], loadType: common_1.LoadType.Full }, data: { cacheData: undefined, }, result: common_1.FormResult.success([]) }, { name: "get accounts state from canister force = true, update cache", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(0), remoteAccounts: [{ idRange: [principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"), BigInt(0), []] }], loadType: common_1.LoadType.Full }, data: { cacheData: [{ remoteAccountId: BigInt(0), remotePrincipal: "lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe", accountState: { ft: BigInt(0), }, time: BigInt(1), }], }, result: common_1.FormResult.success([]) }, { name: "get accounts state from cache", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(0), remoteAccounts: [{ idRange: [principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"), BigInt(0), []] }], loadType: common_1.LoadType.Cache }, data: { cacheData: [{ remoteAccountId: BigInt(0), remotePrincipal: "lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe", accountState: { ft: BigInt(1), }, time: BigInt(0), }], }, result: common_1.FormResult.success([{ accountState: { ft: BigInt(1) }, remoteAccountId: BigInt(0), remotePrincipal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"), time: BigInt(0) }]) }, { name: "get accounts state from cache, cache is empty", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(0), remoteAccounts: [{ idRange: [principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"), BigInt(0), []] }], loadType: common_1.LoadType.Cache }, data: { cacheData: undefined, }, result: common_1.FormResult.success([]) } ]; for (let test of testData) { it(test.name, async () => { jest.restoreAllMocks(); const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("test"); const cacheRepository = new repositories_1.HplStateCacheRepository(); cacheRepository.getHplRemoteAccountState = jest.fn().mockReturnValue(test.data.cacheData); cacheRepository.setHplRemoteAccountState = jest.fn().mockReturnValue(undefined); const logger = new mockLogger_1.MockLogger(); const hplRemoteAccountsStateCacheDataHandler = new hplRemoteAccountsStateCacheDataHandler_1.HplRemoteAccountsStateCacheDataHandler(logger, identifierService, cacheRepository, mockConstrains_1.mockCanisterService); const result = await hplRemoteAccountsStateCacheDataHandler.handle(test.input); expect(result).toEqual(test.result); }, 10000); } });