UNPKG

@ledgerhq/coin-ton

Version:
169 lines 10.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const operation_1 = require("@ledgerhq/coin-framework/lib/operation"); const bignumber_js_1 = __importDefault(require("bignumber.js")); // eslint-disable-next-line no-restricted-imports const lodash_1 = require("lodash"); const txn_1 = require("../../bridge/bridgeHelpers/txn"); const common_fixtures_1 = require("../fixtures/common.fixtures"); describe("Transaction functions", () => { describe("mapTxToOps", () => { it.skip("should map an IN ton transaction without total_fees to a ledger operation", async () => { const { now, lt, hash, in_msg, total_fees, mc_block_seqno } = common_fixtures_1.tonTransactionResponse.transactions[0]; const finalOperation = (0, lodash_1.flatMap)(common_fixtures_1.tonTransactionResponse.transactions, (0, txn_1.mapTxToOps)(common_fixtures_1.mockAccountId, common_fixtures_1.mockAddress, common_fixtures_1.tonTransactionResponse.address_book)); expect(finalOperation).toEqual([ { accountId: common_fixtures_1.mockAccountId, blockHash: null, blockHeight: mc_block_seqno, date: new Date(now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt }, fee: (0, bignumber_js_1.default)(total_fees), hasFailed: false, hash: in_msg?.hash, id: (0, operation_1.encodeOperationId)(common_fixtures_1.mockAccountId, in_msg?.hash ?? "", "IN"), recipients: [in_msg?.destination], senders: ["EQCVnqqL0OOiZi2BQnjVGm-ZeUYgfUhHgAi-vn9F8-94HwrH"], type: "IN", value: (0, bignumber_js_1.default)(in_msg?.value ?? 0), }, ]); }); it.skip("should map an IN ton transaction with total_fees to a ledger operation", async () => { const transactions = [{ ...common_fixtures_1.tonTransactionResponse.transactions[0], total_fees: "15" }]; const { now, lt, hash, in_msg, total_fees, mc_block_seqno, account } = transactions[0]; const finalOperation = (0, lodash_1.flatMap)(transactions, (0, txn_1.mapTxToOps)(common_fixtures_1.mockAccountId, common_fixtures_1.mockAddress, common_fixtures_1.tonTransactionResponse.address_book)); expect(finalOperation).toEqual([ { id: (0, operation_1.encodeOperationId)(common_fixtures_1.mockAccountId, in_msg?.hash ?? "", "NONE"), hash: in_msg?.hash, type: "NONE", value: (0, bignumber_js_1.default)(total_fees), fee: (0, bignumber_js_1.default)(0), blockHash: null, blockHeight: mc_block_seqno, hasFailed: false, accountId: common_fixtures_1.mockAccountId, senders: [account], recipients: [], date: new Date(now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt }, }, { accountId: common_fixtures_1.mockAccountId, blockHash: null, blockHeight: mc_block_seqno, date: new Date(now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt }, fee: (0, bignumber_js_1.default)(total_fees), hasFailed: false, hash: in_msg?.hash, id: (0, operation_1.encodeOperationId)(common_fixtures_1.mockAccountId, in_msg?.hash ?? "", "IN"), recipients: [in_msg?.destination], senders: ["EQCVnqqL0OOiZi2BQnjVGm-ZeUYgfUhHgAi-vn9F8-94HwrH"], type: "IN", value: (0, bignumber_js_1.default)(in_msg?.value ?? 0), }, ]); }); it.skip("should map an OUT ton transaction to a ledger operation", async () => { // The IN transaction will be used as OUT transaction and it will be adjusted const transactions = [ { ...common_fixtures_1.tonTransactionResponse.transactions[0], in_msg: null, }, ]; if (common_fixtures_1.tonTransactionResponse.transactions[0].in_msg) { transactions[0].out_msgs = [ { ...common_fixtures_1.tonTransactionResponse.transactions[0].in_msg, source: transactions[0].account }, ]; } const { now, lt, hash, out_msgs, total_fees, mc_block_seqno, account } = transactions[0]; const finalOperation = (0, lodash_1.flatMap)(transactions, (0, txn_1.mapTxToOps)(common_fixtures_1.mockAccountId, common_fixtures_1.mockAddress, common_fixtures_1.tonTransactionResponse.address_book)); expect(finalOperation).toEqual([ { id: (0, operation_1.encodeOperationId)(common_fixtures_1.mockAccountId, hash ?? "", "OUT"), hash: out_msgs?.[0].hash, type: "OUT", value: (0, bignumber_js_1.default)(out_msgs[0].value ?? 0).plus((0, bignumber_js_1.default)(total_fees)), fee: (0, bignumber_js_1.default)(total_fees), blockHeight: mc_block_seqno, blockHash: null, hasFailed: false, accountId: common_fixtures_1.mockAccountId, senders: [account], recipients: ["EQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbJfg"], date: new Date(now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt }, }, ]); }); }); describe("mapJettonToOps", () => { it("should map an IN ton transaction without total_fees to a ledger operation", async () => { const { transaction_hash, amount, transaction_now, transaction_lt } = common_fixtures_1.jettonTransferResponse.jetton_transfers[0]; const finalOperation = (0, lodash_1.flatMap)(common_fixtures_1.jettonTransferResponse.jetton_transfers, (0, txn_1.mapJettonTxToOps)(common_fixtures_1.mockAccountId, common_fixtures_1.mockAddress, common_fixtures_1.tonTransactionResponse.address_book)); const tokenByCurrencyAddress = `${common_fixtures_1.mockAccountId}+ton%2Fjetton%2Feqavlwfdxgf2lxm67y4yzc17wykd9a0guwpkms1gosm~!underscore!~~!underscore!~not`; expect(finalOperation).toEqual([ { id: (0, operation_1.encodeOperationId)(tokenByCurrencyAddress, transaction_hash, "IN"), hash: transaction_hash, type: "IN", value: (0, bignumber_js_1.default)(amount), fee: (0, bignumber_js_1.default)(0), blockHeight: 1, blockHash: null, hasFailed: false, accountId: tokenByCurrencyAddress, senders: ["EQDnqcVSV4S9m2Y9gLAQrDerQktKSx2I1uhs6r5o_H8VT9G-"], recipients: [common_fixtures_1.mockAddress], date: new Date(transaction_now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: transaction_hash, lt: transaction_lt, }, }, ]); }); it("should map an OUT jetton transaction to a ledger operation", async () => { // The IN jetton transaction will be used as OUT transaction and it will be adjusted const jettonTransfers = [ { ...common_fixtures_1.jettonTransferResponse.jetton_transfers[0], }, ]; jettonTransfers[0].source = jettonTransfers[0].destination; jettonTransfers[0].destination = common_fixtures_1.jettonTransferResponse.jetton_transfers[0].source; const { transaction_hash, amount, transaction_now, transaction_lt } = jettonTransfers[0]; const finalOperation = (0, lodash_1.flatMap)(jettonTransfers, (0, txn_1.mapJettonTxToOps)(common_fixtures_1.mockAccountId, common_fixtures_1.mockAddress, common_fixtures_1.tonTransactionResponse.address_book)); const tokenByCurrencyAddress = `${common_fixtures_1.mockAccountId}+ton%2Fjetton%2Feqavlwfdxgf2lxm67y4yzc17wykd9a0guwpkms1gosm~!underscore!~~!underscore!~not`; expect(finalOperation).toEqual([ { id: (0, operation_1.encodeOperationId)(tokenByCurrencyAddress, transaction_hash, "OUT"), hash: transaction_hash, type: "OUT", value: (0, bignumber_js_1.default)(amount), fee: (0, bignumber_js_1.default)(0), blockHeight: 1, blockHash: null, hasFailed: false, accountId: tokenByCurrencyAddress, recipients: ["EQDnqcVSV4S9m2Y9gLAQrDerQktKSx2I1uhs6r5o_H8VT9G-"], senders: [common_fixtures_1.mockAddress], date: new Date(transaction_now * 1000), // now is defined in seconds extra: { comment: { isEncrypted: false, text: "" }, explorerHash: transaction_hash, lt: transaction_lt, }, }, ]); }); }); }); //# sourceMappingURL=txn.unit.test.js.map