@ledgerhq/coin-ton
Version:
70 lines • 3.89 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../../bridge/bridgeHelpers/api");
const prepareTransaction_1 = __importDefault(require("../../prepareTransaction"));
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));
});
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: 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.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: common_fixtures_1.totalFees,
amount: common_fixtures_1.account.subAccounts?.[0].spendableBalance,
});
});
});
});
//# sourceMappingURL=prepareTransaction.unit.test.js.map