UNPKG

@ledgerhq/coin-aptos

Version:
186 lines 7.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const bignumber_js_1 = __importDefault(require("bignumber.js")); const getCoinAndAmounts_1 = require("../../logic/getCoinAndAmounts"); const constants_1 = require("../../constants"); describe("getCoinAndAmounts", () => { it("should calculate the correct legacy coins amounts for withdraw and deposit events", () => { const tx = { events: [ { type: "0x1::coin::WithdrawEvent", guid: { account_address: "0x11", creation_number: "1", }, data: { amount: "100", }, }, { type: "0x1::coin::DepositEvent", guid: { account_address: "0x11", creation_number: "2", }, data: { amount: "50", }, }, ], changes: [ { type: "write_resource", data: { type: constants_1.APTOS_COIN_CHANGE, data: { withdraw_events: { guid: { id: { addr: "0x11", creation_num: "1", }, }, }, deposit_events: { guid: { id: { addr: "0x11", creation_num: "2", }, }, }, }, }, }, ], }; const address = "0x11"; const result = (0, getCoinAndAmounts_1.getCoinAndAmounts)(tx, address); expect(result.amount_in).toEqual(new bignumber_js_1.default(50)); expect(result.amount_out).toEqual(new bignumber_js_1.default(100)); expect(result.coin_id).toEqual(constants_1.APTOS_ASSET_ID); }); it("should calculate the correct fungible asset amounts for withdraw and deposit events", () => { const tx = { events: [ { type: "0x1::fungible_asset::Withdraw", guid: { account_address: "0x11", creation_number: "1", }, data: { amount: "100", store: "0x22", }, }, { type: "0x1::fungible_asset::Deposit", guid: { account_address: "0x11", creation_number: "2", }, data: { amount: "50", store: "0x33", }, }, ], changes: [ { type: "write_resource", address: "0x22", data: { type: constants_1.APTOS_FUNGIBLE_STORE, data: { metadata: { inner: "0x44", }, transfer_events: { guid: { id: { addr: "0x11", creation_num: "2", }, }, }, }, }, }, { type: "write_resource", address: "0x22", data: { type: constants_1.APTOS_OBJECT_CORE, data: { owner: "0x11", transfer_events: { guid: { id: { addr: "0x22", creation_num: "2", }, }, }, }, }, }, { type: "write_resource", data: { type: constants_1.APTOS_COIN_CHANGE, data: { withdraw_events: { guid: { id: { addr: "0x11", creation_num: "1", }, }, }, deposit_events: { guid: { id: { addr: "0x11", creation_num: "2", }, }, }, }, }, }, ], }; const address = "0x11"; const result = (0, getCoinAndAmounts_1.getCoinAndAmounts)(tx, address); expect(result.amount_in).toEqual(new bignumber_js_1.default(0)); expect(result.amount_out).toEqual(new bignumber_js_1.default(100)); expect(result.coin_id).toEqual("0x44"); }); it("should handle transactions with other events", () => { const tx = { events: [ { type: "0x1::coin::OtherEvent", guid: { account_address: "0x11", creation_number: "1", }, data: { amount: "100", }, }, ], }; const address = "0x1"; const result = (0, getCoinAndAmounts_1.getCoinAndAmounts)(tx, address); expect(result.amount_in).toEqual(new bignumber_js_1.default(0)); expect(result.amount_out).toEqual(new bignumber_js_1.default(0)); expect(result.coin_id).toEqual(null); }); }); //# sourceMappingURL=getCoinAndAmounts.unit.test.js.map