@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
79 lines • 3.37 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const processRecipients_1 = require("../../logic/processRecipients");
const constants_1 = require("../../constants");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
describe("processRecipients", () => {
let op;
beforeEach(() => {
op = {
id: "",
hash: "",
type: "",
value: new bignumber_js_1.default(0),
fee: new bignumber_js_1.default(0),
blockHash: "",
blockHeight: 0,
senders: [],
recipients: [],
accountId: "",
date: new Date(),
extra: {},
transactionSequenceNumber: 0,
hasFailed: false,
};
});
it("should add recipient for transfer-like functions from LL account", () => {
const payload = {
function: "0x1::coin::transfer",
typeArguments: [],
functionArguments: ["0x13", 1], // from: &signer, to: address, amount: u64
};
(0, processRecipients_1.processRecipients)(payload, "0x13", op, "0x1");
expect(op.recipients).toContain("0x0000000000000000000000000000000000000000000000000000000000000013");
});
it("should add recipient for transfer-like functions from external account", () => {
const payload = {
function: "0x1::coin::transfer",
typeArguments: [],
functionArguments: ["0x12", 1], // from: &signer, to: address, amount: u64
};
(0, processRecipients_1.processRecipients)(payload, "0x13", op, "0x1");
expect(op.recipients).toContain("0x0000000000000000000000000000000000000000000000000000000000000012");
});
it("should add recipients for batch transfer functions", () => {
const payload = {
function: "0x1::aptos_account::batch_transfer_coins",
typeArguments: [constants_1.APTOS_ASSET_ID],
functionArguments: [
["0x12", "0x13"],
[1, 2],
],
};
op.senders.push("0x11");
(0, processRecipients_1.processRecipients)(payload, "0x12", op, "0x1");
expect(op.recipients).toContain("0x0000000000000000000000000000000000000000000000000000000000000012");
});
it("should add function address as recipient for other smart contracts", () => {
const payload = {
function: "0x2::other::contract",
typeArguments: [],
functionArguments: [["0x12"], [1]],
};
(0, processRecipients_1.processRecipients)(payload, "0x11", op, "0x2");
expect(op.recipients).toContain("0x2");
});
it("should add recipient for fungible assets transfer-like functions", () => {
const payload = {
function: "0x1::primary_fungible_store::transfer",
typeArguments: [],
functionArguments: [["0xfff"], "0x13"],
};
(0, processRecipients_1.processRecipients)(payload, "0x13", op, "0x1");
expect(op.recipients).toContain("0x0000000000000000000000000000000000000000000000000000000000000013");
});
});
//# sourceMappingURL=processRecipients.unit.test.js.map