UNPKG

@ledgerhq/coin-mina

Version:
55 lines 2.27 kB
import { buildTransaction } from "./buildTransaction"; import { MINA_MAINNET_NETWORK_ID, MINA_PAYMENT_TYPE_ID } from "../consts"; import { getAccountNumFromPath } from "../common-logic"; import { BigNumber } from "bignumber.js"; jest.mock("../common-logic"); describe("buildTransaction", () => { let getAccountNumSpy; beforeEach(() => { getAccountNumSpy = jest.spyOn({ getAccountNumFromPath }, "getAccountNumFromPath"); getAccountNumSpy.mockReturnValue(42); // Mock account number }); const mockAccount = { freshAddress: "B62qrPN5Y5yq8kGE3FbVKbGTdTAJNdHm8qSqZhhtiu1Dq56Cmuo2aJ4", freshAddressPath: "44'/12586'/0'/0/0", }; const mockTransaction = { recipient: "B62qoDWfBZUxKpaoQCoMPJEysXXWv7reVgo7CEAjqx1xAYs3CsT8Gtz", amount: new BigNumber(1000000000), fees: { fee: new BigNumber(1000000), accountCreationFee: new BigNumber(0), }, nonce: 5, memo: "test transaction", family: "mina", }; it("should build a transaction correctly", async () => { const result = await buildTransaction(mockAccount, mockTransaction); expect(result).toEqual({ txType: MINA_PAYMENT_TYPE_ID, senderAccount: 42, senderAddress: mockAccount.freshAddress, receiverAddress: mockTransaction.recipient, amount: mockTransaction.amount.toNumber(), fee: mockTransaction.fees.fee.toNumber(), nonce: mockTransaction.nonce, memo: mockTransaction.memo, networkId: MINA_MAINNET_NETWORK_ID, }); expect(getAccountNumFromPath).toHaveBeenCalledWith(mockAccount.freshAddressPath); }); it("should handle empty memo", async () => { const txWithoutMemo = { ...mockTransaction, memo: undefined, }; const result = await buildTransaction(mockAccount, txWithoutMemo); expect(result.memo).toBe(""); }); it("should throw error if accountNum is undefined", async () => { getAccountNumSpy.mockReturnValue(undefined); await expect(buildTransaction(mockAccount, mockTransaction)).rejects.toThrow(); }); }); //# sourceMappingURL=buildTransaction.test.js.map