UNPKG

@ledgerhq/coin-ton

Version:
109 lines 5.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 api_1 = require("../../bridge/bridgeHelpers/api"); const config_1 = require("../../config"); const prepareTransaction_1 = __importDefault(require("../../prepareTransaction")); const api_fixtures_1 = __importStar(require("../fixtures/api.fixtures")); const common_fixtures_1 = require("../fixtures/common.fixtures"); jest.mock("../../bridge/bridgeHelpers/api"); describe("prepareTransaction", () => { beforeAll(() => { const fetchAccountInfoMock = jest.mocked(api_1.fetchAccountInfo); fetchAccountInfoMock.mockReturnValue(Promise.resolve(common_fixtures_1.accountInfo)); const fetchEstimateFeeMock = jest.mocked(api_1.estimateFee); fetchEstimateFeeMock.mockReturnValue(Promise.resolve(common_fixtures_1.fees)); (0, config_1.setCoinConfig)(() => ({ status: { type: "active", }, infra: { API_TON_ENDPOINT: api_fixtures_1.API_TON_ENDPOINT, KNOWN_JETTONS: [], }, })); api_fixtures_1.default.listen(); }); afterAll(() => { api_fixtures_1.default.close(); }); describe("Ton Transaction", () => { it("should return the transaction with the updated amount and fees", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, common_fixtures_1.transaction); expect(transaction).toEqual({ ...common_fixtures_1.transaction, fees: common_fixtures_1.totalFees, }); }); it("should preserve the reference when no change is detected on the transaction", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, { ...common_fixtures_1.transaction }); const transaction2 = await (0, prepareTransaction_1.default)(common_fixtures_1.account, transaction); expect(transaction).toBe(transaction2); }); it("should create a coin transaction using the spendableBalance in the account", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, { ...common_fixtures_1.transaction, useAllAmount: true, }); expect(transaction).toEqual({ ...common_fixtures_1.transaction, useAllAmount: true, fees: common_fixtures_1.totalFees, amount: common_fixtures_1.account.spendableBalance.minus(common_fixtures_1.totalFees), }); }); }); describe("Jetton Transaction", () => { it("should return the transaction with the updated amount and fees", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, common_fixtures_1.jettonTransaction); expect(transaction).toEqual({ ...common_fixtures_1.jettonTransaction, fees: (0, bignumber_js_1.default)("100000000"), }); }); it("should preserve the reference when no change is detected on the transaction", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, { ...common_fixtures_1.jettonTransaction }); const transaction2 = await (0, prepareTransaction_1.default)(common_fixtures_1.account, transaction); expect(transaction).toBe(transaction2); }); it("should create a coin transaction using the spendableBalance in the account", async () => { const transaction = await (0, prepareTransaction_1.default)(common_fixtures_1.account, { ...common_fixtures_1.jettonTransaction, useAllAmount: true, }); expect(transaction).toEqual({ ...common_fixtures_1.jettonTransaction, useAllAmount: true, fees: (0, bignumber_js_1.default)("100000000"), amount: common_fixtures_1.account.subAccounts?.[0].spendableBalance, }); }); }); }); //# sourceMappingURL=prepareTransaction.unit.test.js.map