@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
56 lines • 2.11 kB
JavaScript
import { txInfoToOperation } from "./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(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(txInfoToOperation("accountId", "address", tx)?.type).toEqual("OUT");
});
it("should return undefined operation type for unknown tx type", () => {
const tx = {
...mockTx,
type: "Unknown",
};
expect(txInfoToOperation("accountId", "address", tx)).toBeUndefined();
});
it("should return correct encoded operation id", () => {
const tx = {
...mockTx,
type: "TransferContract",
txID: "txId",
};
expect(txInfoToOperation("accountId", "address", tx)?.id).toEqual("encodedOpId");
});
});
//# sourceMappingURL=utils.test.js.map