@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
83 lines • 3.67 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 craftTransaction_1 = require("./craftTransaction");
const format_1 = require("../network/format");
const network_1 = require("../network");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
jest.mock("../network/format", () => ({
decode58Check: jest.fn(),
}));
jest.mock("../network", () => ({
post: jest.fn(),
extendTronTxExpirationTimeBy10mn: jest.fn(),
craftStandardTransaction: jest.fn(),
craftTrc20Transaction: jest.fn(),
}));
describe("craftTransaction", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("should craft a TRC20 transaction", async () => {
const transactionIntent = {
type: "send",
asset: {
standard: "trc20",
contractAddress: "contractAddress",
},
recipient: "recipient",
sender: "sender",
amount: BigInt(1000),
};
format_1.decode58Check.mockImplementation(address => address);
network_1.craftTrc20Transaction.mockResolvedValue({
raw_data_hex: "extendedRawDataHex",
});
const result = await (0, craftTransaction_1.craftTransaction)(transactionIntent);
expect(format_1.decode58Check).toHaveBeenCalledWith("recipient");
expect(format_1.decode58Check).toHaveBeenCalledWith("sender");
expect(network_1.craftTrc20Transaction).toHaveBeenCalledWith("contractAddress", "recipient", "sender", new bignumber_js_1.default(1000));
expect(result).toBe("extendedRawDataHex");
});
it("should craft a standard transaction", async () => {
const transactionIntent = {
type: "send",
recipient: "recipient",
sender: "sender",
amount: BigInt(1000),
};
format_1.decode58Check.mockImplementation(address => address);
network_1.craftStandardTransaction.mockResolvedValue({
raw_data_hex: "extendedRawDataHex",
});
const result = await (0, craftTransaction_1.craftTransaction)(transactionIntent);
expect(format_1.decode58Check).toHaveBeenCalledWith("recipient");
expect(format_1.decode58Check).toHaveBeenCalledWith("sender");
expect(network_1.craftStandardTransaction).toHaveBeenCalledWith(undefined, "recipient", "sender", new bignumber_js_1.default(1000), false);
expect(result).toBe("extendedRawDataHex");
});
it("should craft a TRC10 transaction", async () => {
const transactionIntent = {
type: "send",
asset: {
standard: "trc10",
tokenId: "tokenId",
},
recipient: "recipient",
sender: "sender",
amount: BigInt(1000),
};
format_1.decode58Check.mockImplementation(address => address);
network_1.craftStandardTransaction.mockResolvedValue({
raw_data_hex: "extendedRawDataHex",
});
const result = await (0, craftTransaction_1.craftTransaction)(transactionIntent);
expect(format_1.decode58Check).toHaveBeenCalledWith("recipient");
expect(format_1.decode58Check).toHaveBeenCalledWith("sender");
expect(network_1.craftStandardTransaction).toHaveBeenCalledWith("tokenId", "recipient", "sender", new bignumber_js_1.default(1000), true);
expect(result).toBe("extendedRawDataHex");
});
});
//# sourceMappingURL=craftTransaction.test.js.map