UNPKG

@ledgerhq/coin-mina

Version:
57 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const buildTransaction_1 = require("./buildTransaction"); const consts_1 = require("../consts"); const common_logic_1 = require("../common-logic"); const bignumber_js_1 = require("bignumber.js"); jest.mock("../common-logic"); describe("buildTransaction", () => { let getAccountNumSpy; beforeEach(() => { getAccountNumSpy = jest.spyOn({ getAccountNumFromPath: common_logic_1.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_js_1.BigNumber(1000000000), fees: { fee: new bignumber_js_1.BigNumber(1000000), accountCreationFee: new bignumber_js_1.BigNumber(0), }, nonce: 5, memo: "test transaction", family: "mina", }; it("should build a transaction correctly", async () => { const result = await (0, buildTransaction_1.buildTransaction)(mockAccount, mockTransaction); expect(result).toEqual({ txType: consts_1.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: consts_1.MINA_MAINNET_NETWORK_ID, }); expect(common_logic_1.getAccountNumFromPath).toHaveBeenCalledWith(mockAccount.freshAddressPath); }); it("should handle empty memo", async () => { const txWithoutMemo = { ...mockTransaction, memo: undefined, }; const result = await (0, buildTransaction_1.buildTransaction)(mockAccount, txWithoutMemo); expect(result.memo).toBe(""); }); it("should throw error if accountNum is undefined", async () => { getAccountNumSpy.mockReturnValue(undefined); await expect((0, buildTransaction_1.buildTransaction)(mockAccount, mockTransaction)).rejects.toThrow(); }); }); //# sourceMappingURL=buildTransaction.test.js.map