@ledgerhq/coin-ton
Version:
120 lines • 6.41 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 errors_1 = require("@ledgerhq/errors");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const errors_2 = require("../../errors");
const getTransactionStatus_1 = __importDefault(require("../../getTransactionStatus"));
const common_fixtures_1 = require("../fixtures/common.fixtures");
describe("getTransactionStatus", () => {
describe("Recipient", () => {
it("should detect the missing recipient and have an error", async () => {
const transaction = { ...common_fixtures_1.transaction, recipient: "" };
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
recipient: new errors_1.RecipientRequired(),
}));
});
it("should detect the incorrect recipient and have an error", async () => {
const transaction = { ...common_fixtures_1.transaction, recipient: "isInvalid" };
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
recipient: new errors_1.InvalidAddress("", {
currencyName: common_fixtures_1.account.currency.name,
}),
}));
});
it("should detect the recipient and the sender are the same and have an error", async () => {
const transaction = {
...common_fixtures_1.transaction,
recipient: "UQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbMol",
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
recipient: new errors_1.InvalidAddressBecauseDestinationIsAlsoSource("", {
currencyName: common_fixtures_1.account.currency.name,
}),
}));
});
});
describe("Sender", () => {
it("should detect the sender is not correct and have an error", async () => {
const tempAccount = { ...common_fixtures_1.account, freshAddress: "isInvalid" };
const res = await (0, getTransactionStatus_1.default)(tempAccount, common_fixtures_1.transaction);
expect(res.errors).toEqual(expect.objectContaining({
sender: new errors_1.InvalidAddress(),
}));
});
});
describe("Amount", () => {
it("should detect the amount is missing and have an error", async () => {
const transaction = { ...common_fixtures_1.transaction, amount: new bignumber_js_1.default(0) };
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
amount: new errors_1.AmountRequired(),
}));
});
it("should detect the amount is greater than the spendable amount and have an error", async () => {
const transaction = {
...common_fixtures_1.transaction,
amount: (0, bignumber_js_1.default)(1000000002),
fees: new bignumber_js_1.default("20"),
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
amount: new errors_1.NotEnoughBalance(),
}));
});
it("should detect the amount is greater than the spendable amount of the token account and have an error", async () => {
const transaction = {
...common_fixtures_1.jettonTransaction,
amount: (0, bignumber_js_1.default)(1000000002),
fees: new bignumber_js_1.default("20"),
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
amount: new errors_1.NotEnoughBalance(),
}));
});
it("should detect the transaction is a jetton transfer and have a warning", async () => {
const transaction = {
...common_fixtures_1.jettonTransaction,
amount: (0, bignumber_js_1.default)(1000000002),
fees: new bignumber_js_1.default("20"),
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.warnings).toEqual(expect.objectContaining({
amount: new errors_2.TonExcessFee(),
}));
});
describe("Comment", () => {
it("should detect the comment is not valid and have an error", async () => {
const transaction = {
...common_fixtures_1.transaction,
amount: new bignumber_js_1.default("1"),
comment: { isEncrypted: false, text: "comment\nInvalid" },
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, transaction);
expect(res.errors).toEqual(expect.objectContaining({
transaction: new errors_2.TonCommentInvalid(),
}));
});
});
describe("Successful transaction", () => {
it("should not have errors", async () => {
const successfulResult = {
amount: common_fixtures_1.transaction.amount,
errors: {},
warnings: {},
estimatedFees: common_fixtures_1.transaction.fees,
totalSpent: common_fixtures_1.transaction.amount.plus(common_fixtures_1.transaction.fees),
};
const res = await (0, getTransactionStatus_1.default)(common_fixtures_1.account, common_fixtures_1.transaction);
expect(res).toEqual(successfulResult);
});
});
});
});
//# sourceMappingURL=getTransactionStatus.unit.test.js.map