UNPKG

@ledgerhq/coin-tron

Version:
78 lines 3.21 kB
import { craftTransaction } from "./craftTransaction"; import { decode58Check } from "../network/format"; import { craftStandardTransaction, craftTrc20Transaction } from "../network"; import BigNumber from "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), }; decode58Check.mockImplementation(address => address); craftTrc20Transaction.mockResolvedValue({ raw_data_hex: "extendedRawDataHex", }); const result = await craftTransaction(transactionIntent); expect(decode58Check).toHaveBeenCalledWith("recipient"); expect(decode58Check).toHaveBeenCalledWith("sender"); expect(craftTrc20Transaction).toHaveBeenCalledWith("contractAddress", "recipient", "sender", new BigNumber(1000)); expect(result).toBe("extendedRawDataHex"); }); it("should craft a standard transaction", async () => { const transactionIntent = { type: "send", recipient: "recipient", sender: "sender", amount: BigInt(1000), }; decode58Check.mockImplementation(address => address); craftStandardTransaction.mockResolvedValue({ raw_data_hex: "extendedRawDataHex", }); const result = await craftTransaction(transactionIntent); expect(decode58Check).toHaveBeenCalledWith("recipient"); expect(decode58Check).toHaveBeenCalledWith("sender"); expect(craftStandardTransaction).toHaveBeenCalledWith(undefined, "recipient", "sender", new BigNumber(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), }; decode58Check.mockImplementation(address => address); craftStandardTransaction.mockResolvedValue({ raw_data_hex: "extendedRawDataHex", }); const result = await craftTransaction(transactionIntent); expect(decode58Check).toHaveBeenCalledWith("recipient"); expect(decode58Check).toHaveBeenCalledWith("sender"); expect(craftStandardTransaction).toHaveBeenCalledWith("tokenId", "recipient", "sender", new BigNumber(1000), true); expect(result).toBe("extendedRawDataHex"); }); }); //# sourceMappingURL=craftTransaction.test.js.map