@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
221 lines • 9.36 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 bridge_fixture_1 = require("../../bridge/bridge.fixture");
const transaction_1 = require("../../bridge/transaction");
describe("transaction Test", () => {
describe("when formatTransaction", () => {
describe("when amount is 0 and fee is 0", () => {
it("should return a transaction SEND to 0xff00 with fees=?", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.recipient = "0xff00";
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND
TO 0xff00
with fees=?`;
expect(result).toBe(expected);
});
});
describe("when amount is 0 and fee is 0.0001", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("0.0001");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND
TO 0xff00
with fees=0`;
expect(result).toBe(expected);
});
});
describe("when amount is 0 and fee is 0.1", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("0.1");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND
TO 0xff00
with fees=0`;
expect(result).toBe(expected);
});
});
describe("when amount is 1 and fee is 0.1", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.amount = (0, bignumber_js_1.default)("1");
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("0.1");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND 0.00000001
TO 0xff00
with fees=0`;
expect(result).toBe(expected);
});
});
describe("when amount is 10 and fee is 1", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.amount = (0, bignumber_js_1.default)("10");
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("1");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND 0.0000001
TO 0xff00
with fees=0.00000001`;
expect(result).toBe(expected);
});
});
describe("when amount is 1000 and fee is 1", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.amount = (0, bignumber_js_1.default)("1000");
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("1");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND 0.00001
TO 0xff00
with fees=0.00000001`;
expect(result).toBe(expected);
});
});
describe("when using MAX with amount is 1000 and fee is 1", () => {
it("should return a transaction SEND to 0xff00 with fees=0", async () => {
const account = (0, bridge_fixture_1.createFixtureAccount)();
const transaction = (0, bridge_fixture_1.createFixtureTransaction)();
transaction.amount = (0, bignumber_js_1.default)("1000");
transaction.useAllAmount = true;
transaction.recipient = "0xff00";
transaction.fees = (0, bignumber_js_1.default)("1");
const result = (0, transaction_1.formatTransaction)(transaction, account);
const expected = `
SEND MAX
TO 0xff00
with fees=0.00000001`;
expect(result).toBe(expected);
});
});
});
describe("when fromTransactionRaw", () => {
it("should return the transaction object", () => {
const txRaw = {
family: "aptos",
mode: "send",
options: "{}",
amount: "0.5",
recipient: "0xff00",
useAllAmount: false,
subAccountId: "0xff01",
recipientDomain: {},
};
const result = (0, transaction_1.fromTransactionRaw)(txRaw);
const expected = {
family: "aptos",
amount: (0, bignumber_js_1.default)("0.5"),
options: {},
mode: "send",
recipient: "0xff00",
recipientDomain: {},
subAccountId: "0xff01",
useAllAmount: false,
};
expect(result).toEqual(expected);
});
it("should return the transaction object with fees and errors", () => {
const txRaw = {
family: "aptos",
mode: "send",
fees: "50",
errors: '{ "errors": "error" }',
options: "{}",
amount: "0.5",
recipient: "0xff00",
useAllAmount: false,
subAccountId: "0xff01",
recipientDomain: {},
};
const result = (0, transaction_1.fromTransactionRaw)(txRaw);
const expected = {
family: "aptos",
amount: (0, bignumber_js_1.default)("0.5"),
fees: (0, bignumber_js_1.default)(50),
errors: { errors: "error" },
options: {},
mode: "send",
recipient: "0xff00",
recipientDomain: {},
subAccountId: "0xff01",
useAllAmount: false,
};
expect(result).toEqual(expected);
});
});
describe("when toTransactionRaw", () => {
it("should return the raw transaction object", () => {
const tx = {
family: "aptos",
amount: (0, bignumber_js_1.default)("0.5"),
options: {},
mode: "send",
recipient: "0xff00",
recipientDomain: {},
subAccountId: "0xff01",
useAllAmount: false,
};
const result = (0, transaction_1.toTransactionRaw)(tx);
const expected = {
family: "aptos",
mode: "send",
options: "{}",
amount: "0.5",
recipient: "0xff00",
useAllAmount: false,
subAccountId: "0xff01",
recipientDomain: {},
};
expect(result).toEqual(expected);
});
it("should return the raw transaction object with fees", () => {
const tx = {
family: "aptos",
amount: (0, bignumber_js_1.default)("0.5"),
options: {},
fees: (0, bignumber_js_1.default)("0.1"),
mode: "send",
recipient: "0xff00",
recipientDomain: {},
subAccountId: "0xff01",
useAllAmount: false,
};
const result = (0, transaction_1.toTransactionRaw)(tx);
const expected = {
family: "aptos",
mode: "send",
fees: "0.1",
options: "{}",
amount: "0.5",
recipient: "0xff00",
useAllAmount: false,
subAccountId: "0xff01",
recipientDomain: {},
};
expect(result).toEqual(expected);
});
});
});
//# sourceMappingURL=transaction.test.js.map