test-ic-wallet-middleware-icrc
Version:
Ic middleware wallet ICRC protocol
80 lines (79 loc) • 3.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const agent_1 = require("@dfinity/agent");
const principal_1 = require("@dfinity/principal");
const common_1 = require("@ic-wallet-middleware/common");
const mockLogger_1 = require("../../../../__tests_utils/mockLogger");
const getAllowanceSubAccountBalanceCacheHandler_1 = require("../../../../internalHandlers/icrcCacheDataHandlers/allowances/getAllowanceSubAccountBalanceCacheHandler/getAllowanceSubAccountBalanceCacheHandler");
const repositories_1 = require("../../../../repositories");
const types_1 = require("../../../../types");
describe("Unit GetAllowanceSubAccountBalanceCacheHandler tests", () => {
const testData = [
{
name: "getAllowanceSubAccountBalance force = false",
input: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
principal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
loadType: common_1.LoadType.Cache
},
data: {
cacheData: {
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
balance: BigInt(10000),
}
},
result: common_1.FormResult.success({
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
balance: BigInt(10000),
})
},
{
name: "getAllowanceSubAccountBalance force = false",
input: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
principal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined
},
result: common_1.FormResult.success({
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
balance: BigInt(0),
})
},
{
name: "getAllowanceSubAccountBalance force = true",
input: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x0"),
principal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined
},
result: common_1.FormResult.success({
subAccountId: types_1.SubAccountId.parseFromString("0x0"),
balance: BigInt(6021973),
})
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = new common_1.IdentifierService();
const cacheStorage = new repositories_1.AssetLocalCache();
cacheStorage.getSubAccountById = jest.fn().mockReturnValue(test.data.cacheData);
cacheStorage.setSubAccount = jest.fn().mockReturnValue(undefined);
identifierService.getAgent = jest.fn().mockReturnValue(new agent_1.HttpAgent());
identifierService.getPrincipal = jest.fn().mockReturnValue(principal_1.Principal.fromText("gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe"));
const logger = new mockLogger_1.MockLogger();
const getIcrcAllowanceHandler = new getAllowanceSubAccountBalanceCacheHandler_1.GetAllowanceSubAccountBalanceCacheHandler(logger, identifierService, cacheStorage);
const result = await getIcrcAllowanceHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});