@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
125 lines (124 loc) • 4.81 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mockConstrains_1 = require("../../../__tests_utils/mockConstrains");
const mockLogger_1 = require("../../../__tests_utils/mockLogger");
const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity");
const hplFtSuppliesStateCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplFtSuppliesStateCacheDataHandler/hplFtSuppliesStateCacheDataHandler");
const repositories_1 = require("../../../repositories");
const common_1 = require("@ic-wallet-kit/common");
describe("Unit HplFtSuppliesStateCacheDataHandler tests", () => {
const testData = [
{
name: "get accounts state from canister",
input: {
accountCount: BigInt(0),
ftAssetCount: BigInt(1),
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined,
serviceData: [
{
assetId: BigInt(100),
ftSupply: BigInt(11015),
},
{
assetId: BigInt(122),
ftSupply: BigInt(21015),
}
]
},
result: common_1.FormResult.success([
{
assetId: BigInt(100),
ftSupply: BigInt(11015),
},
{
assetId: BigInt(122),
ftSupply: BigInt(21015),
}
])
},
{
name: "get accounts state from cache",
input: {
accountCount: BigInt(0),
ftAssetCount: BigInt(40),
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: common_1.LoadType.Cache
},
data: {
cacheData: [
{
assetId: BigInt(0),
ftSupply: BigInt(21015),
},
{
assetId: BigInt(1),
ftSupply: BigInt(10000200000000),
}
]
},
result: common_1.FormResult.success([
{
assetId: BigInt(0),
ftSupply: BigInt(21015),
},
{
assetId: BigInt(1),
ftSupply: BigInt(10000200000000),
}
])
},
{
name: "get accounts state from cache, cache is empty",
input: {
accountCount: BigInt(1),
ftAssetCount: BigInt(1),
virtualAccountCount: BigInt(1),
remoteAccounts: [],
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined,
serviceData: [
{
assetId: BigInt(2100),
ftSupply: BigInt(211015),
},
{
assetId: BigInt(3122),
ftSupply: BigInt(321015),
}
]
},
result: common_1.FormResult.success([
{
assetId: BigInt(2100),
ftSupply: BigInt(211015),
},
{
assetId: BigInt(3122),
ftSupply: BigInt(321015),
}
])
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("testUser2345234");
const cacheRepository = new repositories_1.HplStateCacheRepository();
cacheRepository.getHplFtSuppliesState = jest.fn().mockReturnValue(test.data.cacheData);
cacheRepository.setHplFtSuppliesState = jest.fn().mockImplementation(() => { });
const logger = new mockLogger_1.MockLogger();
const hplFtSuppliesStateCacheDataHandler = new hplFtSuppliesStateCacheDataHandler_1.HplFtSuppliesStateCacheDataHandler(logger, identifierService, cacheRepository, mockConstrains_1.mockCanisterService);
hplFtSuppliesStateCacheDataHandler.getExternalData = jest.fn().mockReturnValue(test.data.serviceData);
const result = await hplFtSuppliesStateCacheDataHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});