test-ic-wallet-middleware-icrc
Version:
Ic middleware wallet ICRC protocol
78 lines (77 loc) • 4.08 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 getIcrcAllowanceCacheHandler_1 = require("../../../../internalHandlers/icrcCacheDataHandlers/allowances/getIcrcAllowanceCacheHandler/getIcrcAllowanceCacheHandler");
const repositories_1 = require("../../../../repositories");
const types_1 = require("../../../../types");
describe("Unit GetIcrcAllowanceCacheHandler getAssetAllowance tests", () => {
const testData = [
{
name: "GetIcrcAllowance force = false",
input: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
spenderPrincipal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
spenderSubId: types_1.SubAccountId.parseFromString("0x1"),
loadType: common_1.LoadType.Cache
},
data: {
cacheData: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: "0x1",
spenderPrincipal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
spenderSubId: "0x1",
amount: BigInt(1000000),
expiration: undefined,
}
},
result: common_1.FormResult.success({
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x1"),
spenderPrincipal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
spenderSubId: types_1.SubAccountId.parseFromString("0x1"),
amount: BigInt(1000000),
expiration: undefined,
})
},
{
name: "GetIcrcAllowance force = true",
input: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x0"),
spenderPrincipal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
spenderSubId: types_1.SubAccountId.parseFromString("0x0"),
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined
},
result: common_1.FormResult.success({
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
subAccountId: types_1.SubAccountId.parseFromString("0x0"),
spenderPrincipal: "xqknu-lpemp-tx4sq-ovbp4-2cf7s-z3was-f374m-l3mui-6zh7u-qdna6-fae",
spenderSubId: types_1.SubAccountId.parseFromString("0x0"),
amount: BigInt(0),
expiration: undefined,
})
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = new common_1.IdentifierService();
const cacheStorage = new repositories_1.AllowanceLocalCache();
cacheStorage.getAllowance = jest.fn().mockReturnValue(test.data.cacheData);
cacheStorage.updateOrAddAllowance = 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 getIcrcAllowanceCacheHandler_1.GetIcrcAllowanceCacheHandler(logger, identifierService, cacheStorage);
const result = await getIcrcAllowanceHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});