-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7762 from LedgerHQ/support/fix-approve-operations…
…-tron fix approve operations tron
- Loading branch information
Showing
7 changed files
with
173 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/coin-tron": patch | ||
--- | ||
|
||
Fix approve operations on Tron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { OperationType } from "@ledgerhq/types-live"; | ||
import { TrongridTxInfo, TrongridTxType } from "../types"; | ||
import { txInfoToOperation } from "./utils"; | ||
|
||
jest.mock("@ledgerhq/coin-framework/operation", () => ({ | ||
encodeOperationId: jest.fn(() => "encodedOpId"), | ||
})); | ||
|
||
let mockTx: TrongridTxInfo; | ||
|
||
const testingMap: Record<TrongridTxType, OperationType> = { | ||
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 = {} as TrongridTxInfo; | ||
}); | ||
|
||
it.each(Object.keys(testingMap))( | ||
`should return correct operation type for %p trongrid tx type`, | ||
trongridTxType => { | ||
const tx: TrongridTxInfo = { | ||
...mockTx, | ||
type: trongridTxType as TrongridTxType, | ||
}; | ||
|
||
expect(txInfoToOperation("accountId", "address", tx)?.type).toEqual( | ||
testingMap[trongridTxType as keyof Record<TrongridTxType, OperationType>], | ||
); | ||
}, | ||
); | ||
|
||
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: TrongridTxInfo = { | ||
...mockTx, | ||
type: trongridTxType as TrongridTxType, | ||
from: "address", | ||
}; | ||
|
||
expect(txInfoToOperation("accountId", "address", tx)?.type).toEqual("OUT"); | ||
}, | ||
); | ||
|
||
it("should return undefined operation type for unknown tx type", () => { | ||
const tx: TrongridTxInfo = { | ||
...mockTx, | ||
type: "Unknown" as TrongridTxType, | ||
}; | ||
|
||
expect(txInfoToOperation("accountId", "address", tx)).toBeUndefined(); | ||
}); | ||
|
||
it("should return correct encoded operation id", () => { | ||
const tx: TrongridTxInfo = { | ||
...mockTx, | ||
type: "TransferContract", | ||
txID: "txId", | ||
}; | ||
|
||
expect(txInfoToOperation("accountId", "address", tx)?.id).toEqual("encodedOpId"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { formatTrongridTrc20TxResponse } from "./format"; | ||
import { Trc20API } from "./types"; | ||
|
||
describe("formatTrongridTrc20TxResponse", () => { | ||
it("should return correct TrongridTxInfo for Approval tx type", () => { | ||
const tx = { | ||
from: "from", | ||
to: "to", | ||
block_timestamp: 1, | ||
detail: { | ||
ret: [{ fee: 1 }], | ||
}, | ||
value: 1, | ||
transaction_id: "txId", | ||
token_info: {}, | ||
type: "Approval", | ||
}; | ||
const result = formatTrongridTrc20TxResponse(tx as unknown as Trc20API); | ||
expect(result).toEqual({ | ||
txID: "txId", | ||
date: new Date(1), | ||
type: "ContractApproval", | ||
tokenId: undefined, | ||
from: "from", | ||
to: "to", | ||
blockHeight: undefined, | ||
value: new BigNumber(1), | ||
fee: new BigNumber(1), | ||
hasFailed: false, | ||
}); | ||
}); | ||
|
||
it("should return correct TrongridTxInfo for Transfer tx type", () => { | ||
const tx = { | ||
from: "from", | ||
to: "to", | ||
block_timestamp: 1, | ||
detail: { | ||
ret: [{ fee: 1 }], | ||
}, | ||
value: 1, | ||
transaction_id: "txId", | ||
token_info: { address: "tokenId" }, | ||
type: "Transfer", | ||
}; | ||
const result = formatTrongridTrc20TxResponse(tx as unknown as Trc20API); | ||
expect(result).toEqual({ | ||
txID: "txId", | ||
date: new Date(1), | ||
type: "TriggerSmartContract", | ||
tokenId: "tokenId", | ||
from: "from", | ||
to: "to", | ||
blockHeight: undefined, | ||
value: new BigNumber(1), | ||
fee: new BigNumber(1), | ||
hasFailed: false, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters