UNPKG

@ledgerhq/coin-tron

Version:
58 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); jest.mock("@ledgerhq/coin-framework/operation", () => ({ encodeOperationId: jest.fn(() => "encodedOpId"), })); let mockTx; const testingMap = { TransferContract: "IN", TransferAssetContract: "IN", TriggerSmartContract: "IN", ContractApproval: "APPROVE", ExchangeTransactionContract: "OUT", VoteWitnessContract: "VOTE", WithdrawBalanceContract: "REWARD", FreezeBalanceContract: "FREEZE", FreezeBalanceV2Contract: "FREEZE", UnfreezeBalanceV2Contract: "UNFREEZE", WithdrawExpireUnfreezeContract: "WITHDRAW_EXPIRE_UNFREEZE", UnDelegateResourceContract: "UNDELEGATE_RESOURCE", UnfreezeBalanceContract: "LEGACY_UNFREEZE", }; describe("txInfoToOperation", () => { beforeEach(() => { mockTx = {}; }); it.each(Object.keys(testingMap))(`should return correct operation type for %p trongrid tx type`, trongridTxType => { const tx = { ...mockTx, type: trongridTxType, }; expect((0, utils_1.txInfoToOperation)("accountId", "address", tx)?.type).toEqual(testingMap[trongridTxType]); }); it.each(["TransferContract", "TransferAssetContract", "TriggerSmartContract"])("should return OUT operation type when from is equal to user address for %p trongrid tx type", trongridTxType => { const tx = { ...mockTx, type: trongridTxType, from: "address", }; expect((0, utils_1.txInfoToOperation)("accountId", "address", tx)?.type).toEqual("OUT"); }); it("should return undefined operation type for unknown tx type", () => { const tx = { ...mockTx, type: "Unknown", }; expect((0, utils_1.txInfoToOperation)("accountId", "address", tx)).toBeUndefined(); }); it("should return correct encoded operation id", () => { const tx = { ...mockTx, type: "TransferContract", txID: "txId", }; expect((0, utils_1.txInfoToOperation)("accountId", "address", tx)?.id).toEqual("encodedOpId"); }); }); //# sourceMappingURL=utils.test.js.map