UNPKG

@ledgerhq/coin-aptos

Version:
218 lines 7.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const getResourceAddress_1 = require("../../logic/getResourceAddress"); const constants_1 = require("../../constants"); const getCoinAndAmounts_1 = require("../../logic/getCoinAndAmounts"); describe("getResourceAddress", () => { it("should return coin name from the change", () => { const change = { type: "write_resource", data: { type: constants_1.APTOS_COIN_CHANGE, data: { withdraw_events: { guid: { id: { addr: "0x11", creation_num: "2", }, }, }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x11", creation_number: "2", }, type: "0x1::coin::WithdrawEvent", }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventCoinAddress); expect(result).toEqual(constants_1.APTOS_ASSET_ID); }); it("should return null for not finding the valid coin in change", () => { const change = { type: "write_resource", data: { type: constants_1.APTOS_COIN_CHANGE, data: { withdraw_events: { guid: { id: { addr: "0x12", creation_num: "2", }, }, }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x11", creation_number: "1", }, type: "0x1::coin::WithdrawEvent", }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventCoinAddress); expect(result).toBe(null); }); it("should return null for not finding the event name in change", () => { const change = { type: "write_resource", data: { type: constants_1.APTOS_COIN_CHANGE, data: { other_events: { guid: { id: { addr: "0x12", creation_num: "2", }, }, }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x11", creation_number: "1", }, type: "0x1::coin::WithdrawEvent", }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventCoinAddress); expect(result).toBe(null); }); it("should return fungible asset address", () => { const change = { type: "write_resource", address: "0xsomeaddress", data: { type: constants_1.APTOS_FUNGIBLE_STORE, data: { metadata: { inner: "0xassetaddress", }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x0", creation_number: "0", }, type: "0x1::fungible_asset::Deposit", data: { amount: "100", store: "0xsomeaddress", }, }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventFAAddress); expect(result).toEqual("0xassetaddress"); }); it("should return null address instead of fungible asset when wrong type", () => { const change = { type: "write_resource", address: "0xsomeaddress", data: { type: constants_1.APTOS_COIN_CHANGE, data: { metadata: { inner: "0xassetaddress", }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x0", creation_number: "0", }, type: "0x1::fungible_asset::Deposit", data: { amount: "100", store: "0xsomeaddress", }, }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventFAAddress); expect(result).toEqual(null); }); it("should return null address instead of fungible asset when wrong event address", () => { const change = { type: "write_resource", address: "0xsomeaddress", data: { type: constants_1.APTOS_FUNGIBLE_STORE, data: { metadata: { inner: "0xassetaddress", }, }, }, }; const tx = { hash: "0x123", block: { hash: "0xabc", height: 1 }, timestamp: "1000000", sequence_number: "1", version: "1", changes: [change], }; const event = { guid: { account_address: "0x0", creation_number: "0", }, type: "0x1::fungible_asset::Deposit", data: { amount: "100", store: "0xwrongaddress", }, }; const result = (0, getResourceAddress_1.getResourceAddress)(tx, event, "withdraw_events", getCoinAndAmounts_1.getEventFAAddress); expect(result).toEqual(null); }); }); //# sourceMappingURL=getResourceAddress.unit.test.js.map