UNPKG

@ledgerhq/coin-casper

Version:
76 lines 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const buildOptimisticOperation_1 = require("./buildOptimisticOperation"); const addresses_1 = require("./bridgeHelpers/addresses"); const operation_1 = require("@ledgerhq/coin-framework/operation"); const fixtures_1 = require("../test/fixtures"); // Mock dependencies jest.mock("./bridgeHelpers/addresses", () => ({ getAddress: jest.fn(), })); jest.mock("@ledgerhq/coin-framework/operation", () => ({ encodeOperationId: jest.fn(), })); describe("buildOptimisticOperation", () => { // Create test fixtures using helper functions const mockAccount = (0, fixtures_1.createMockAccount)(); const mockTransaction = (0, fixtures_1.createMockTransaction)(); const mockHash = "mockedTransactionHash"; const mockAddress = "01abcdef1234567890"; const mockOperationId = "mockOperationId"; beforeEach(() => { jest.clearAllMocks(); addresses_1.getAddress.mockReturnValue({ address: mockAddress }); operation_1.encodeOperationId.mockReturnValue(mockOperationId); }); test("should build an optimistic operation for an outgoing transaction", () => { const operation = (0, buildOptimisticOperation_1.buildOptimisticOperation)(mockAccount, mockTransaction, mockHash); expect(addresses_1.getAddress).toHaveBeenCalledWith(mockAccount); expect(operation_1.encodeOperationId).toHaveBeenCalledWith(mockAccount.id, mockHash, "OUT"); expect(operation).toEqual({ id: mockOperationId, hash: mockHash, type: "OUT", senders: [mockAddress], recipients: [mockTransaction.recipient], accountId: mockAccount.id, value: mockTransaction.amount.plus(mockTransaction.fees), fee: mockTransaction.fees, blockHash: null, blockHeight: null, date: expect.any(Date), extra: { transferId: mockTransaction.transferId, }, nftOperations: [], subOperations: [], }); }); test("should build an optimistic operation with a custom operation type", () => { const customType = "IN"; const operation = (0, buildOptimisticOperation_1.buildOptimisticOperation)(mockAccount, mockTransaction, mockHash, customType); expect(operation_1.encodeOperationId).toHaveBeenCalledWith(mockAccount.id, mockHash, customType); expect(operation.type).toBe(customType); }); test("should include transferId in the extra field when present", () => { const txWithTransferId = { ...mockTransaction, transferId: fixtures_1.TEST_TRANSFER_IDS.VALID, }; const operation = (0, buildOptimisticOperation_1.buildOptimisticOperation)(mockAccount, txWithTransferId, mockHash); expect(operation.extra).toEqual({ transferId: fixtures_1.TEST_TRANSFER_IDS.VALID, }); }); test("should handle transaction without transferId", () => { const txWithoutTransferId = { ...mockTransaction, transferId: undefined, }; const operation = (0, buildOptimisticOperation_1.buildOptimisticOperation)(mockAccount, txWithoutTransferId, mockHash); expect(operation.extra).toEqual({ transferId: undefined, }); }); }); //# sourceMappingURL=buildOptimisticOperation.test.js.map