@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
114 lines (113 loc) • 5.38 kB
JavaScript
;
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 hplRemotesCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplRemotesCacheDataHandler/hplRemotesCacheDataHandler");
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: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined,
service: {
remotes: [{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(1)
}
}]
}
},
result: common_1.FormResult.success({
remotes: [{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(1)
}
}]
})
},
{
name: "get accounts state from cache",
input: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Cache
},
data: {
cacheData: {
remotes: [
{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(0)
}
}
]
},
service: undefined
},
result: common_1.FormResult.success({
remotes: [{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(0)
}
}]
})
},
{
name: "get accounts state from cache, cache is empty",
input: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined,
service: {
remotes: [{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(1),
}
}]
}
},
result: common_1.FormResult.success({
remotes: [{
accountId: BigInt(0),
remoteId: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
remoteInfo: {
ft: BigInt(1),
}
}]
})
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = await (0, seedToIdentity_1.phraseToIdentifierService)("hair guilt comic still lesson helmet glare material avocado venue giggle essence");
const hplDataCacheRepository = new repositories_1.HplDataCacheRepository();
hplDataCacheRepository.getHplDataByCanisterId = jest.fn().mockReturnValue(test.data.cacheData);
hplDataCacheRepository.setHplData = jest.fn().mockReturnValue(undefined);
const logger = new mockLogger_1.MockLogger();
const hplRemoteAccountsStateCacheDataHandler = new hplRemotesCacheDataHandler_1.HplRemotesCacheDataHandler(logger, identifierService, hplDataCacheRepository, mockConstrains_1.mockCanisterService);
hplRemoteAccountsStateCacheDataHandler.getExternalData = jest.fn().mockReturnValue(test.data.service);
const result = await hplRemoteAccountsStateCacheDataHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});