@ledgerhq/coin-ton
Version:
102 lines • 4.07 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 bignumber_js_1 = __importDefault(require("bignumber.js"));
const constants_1 = require("../../constants");
const deviceTransactionConfig_1 = __importDefault(require("../../deviceTransactionConfig"));
const common_fixtures_1 = require("../fixtures/common.fixtures");
const status = {
errors: {},
warnings: {},
estimatedFees: new bignumber_js_1.default(0),
amount: new bignumber_js_1.default(0),
totalSpent: new bignumber_js_1.default(0),
};
describe("deviceTransactionConfig", () => {
describe("TON transaction", () => {
it("should return the fields for a transaction when there is a valid comment", async () => {
const transaction = {
...common_fixtures_1.transaction,
comment: { isEncrypted: false, text: "validComment" },
};
const res = await (0, deviceTransactionConfig_1.default)({
account: common_fixtures_1.account,
parentAccount: undefined,
transaction,
status,
});
expect(res).toEqual([
{
type: "address",
label: "To",
address: transaction.recipient,
},
{
type: "amount",
label: "Amount",
},
{ type: "fees", label: "Fee" },
{ type: "text", label: "Comment", value: "validComment" },
]);
});
it("should return the fields for a transaction when useAllAmount is true and there is a valid comment", async () => {
const transaction = {
...common_fixtures_1.transaction,
useAllAmount: true,
comment: { isEncrypted: false, text: "validComment" },
};
const res = await (0, deviceTransactionConfig_1.default)({
account: common_fixtures_1.account,
parentAccount: undefined,
transaction,
status,
});
expect(res).toEqual([
{
type: "address",
label: "To",
address: transaction.recipient,
},
{
type: "text",
label: "Amount",
value: "ALL YOUR TONs",
},
{ type: "fees", label: "Fee" },
{ type: "text", label: "Comment", value: "validComment" },
]);
});
});
describe("Jetton transaction", () => {
it("should return the fields for a jetton transaction", async () => {
if (common_fixtures_1.account.subAccounts?.[0]) {
const res = await (0, deviceTransactionConfig_1.default)({
account: common_fixtures_1.account.subAccounts[0],
parentAccount: common_fixtures_1.account,
transaction: common_fixtures_1.jettonTransaction,
status,
});
expect(res).toEqual([
{
type: "address",
label: "To",
address: common_fixtures_1.jettonTransaction.recipient,
},
{
type: "text",
label: "Jetton units",
value: common_fixtures_1.jettonTransaction.amount.toString(),
},
{
type: "text",
label: "Amount",
value: constants_1.TOKEN_TRANSFER_MAX_FEE,
},
]);
}
});
});
});
//# sourceMappingURL=deviceTransactionConfig.unit.test.js.map