-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detect native transfers (#3402)
- fix: detect native transfers - add unit tests for decoded tx
- Loading branch information
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
src/components/transactions/TxDetails/TxData/DecodedData/SingleTxDecoded/index.test.tsx
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,111 @@ | ||
import { render } from '@/tests/test-utils' | ||
import SingleTxDecoded from '.' | ||
import { Operation } from '@safe-global/safe-gateway-typescript-sdk' | ||
import { faker } from '@faker-js/faker' | ||
import { parseUnits } from 'ethers' | ||
import { ERC20__factory } from '@/types/contracts' | ||
|
||
describe('SingleTxDecoded', () => { | ||
it('should show native transfers', () => { | ||
const receiver = faker.finance.ethereumAddress() | ||
const result = render( | ||
<SingleTxDecoded | ||
actionTitle="0" | ||
showDelegateCallWarning | ||
tx={{ | ||
data: '0x', | ||
operation: Operation.CALL, | ||
to: receiver, | ||
value: parseUnits('1').toString(), | ||
}} | ||
txData={{ | ||
to: { value: receiver }, | ||
operation: Operation.CALL, | ||
trustedDelegateCallTarget: false, | ||
addressInfoIndex: {}, | ||
value: parseUnits('1').toString(), | ||
}} | ||
/>, | ||
) | ||
|
||
expect(result.queryByText('native transfer')).not.toBeNull() | ||
}) | ||
|
||
it('should show unknown contract interactions', () => { | ||
const unknownToken = faker.finance.ethereumAddress() | ||
const spender = faker.finance.ethereumAddress() | ||
const result = render( | ||
<SingleTxDecoded | ||
actionTitle="0" | ||
showDelegateCallWarning | ||
tx={{ | ||
data: ERC20__factory.createInterface().encodeFunctionData('approve', [spender, '100000']), | ||
operation: Operation.CALL, | ||
to: unknownToken, | ||
}} | ||
txData={{ | ||
to: { value: unknownToken }, | ||
operation: Operation.CALL, | ||
trustedDelegateCallTarget: false, | ||
addressInfoIndex: {}, | ||
}} | ||
/>, | ||
) | ||
|
||
expect(result.queryByText('Unknown contract interaction')).not.toBeNull() | ||
}) | ||
|
||
it('should show decoded data ', () => { | ||
const unknownToken = faker.finance.ethereumAddress() | ||
const spender = faker.finance.ethereumAddress() | ||
const result = render( | ||
<SingleTxDecoded | ||
actionTitle="0" | ||
showDelegateCallWarning | ||
tx={{ | ||
data: ERC20__factory.createInterface().encodeFunctionData('approve', [spender, '100000']), | ||
operation: Operation.CALL, | ||
to: unknownToken, | ||
dataDecoded: { | ||
method: 'approve', | ||
parameters: [ | ||
{ | ||
name: 'spender', | ||
type: 'address', | ||
value: spender, | ||
}, | ||
{ | ||
name: 'value', | ||
type: 'uint256', | ||
value: '100000', | ||
}, | ||
], | ||
}, | ||
}} | ||
txData={{ | ||
to: { value: unknownToken }, | ||
operation: Operation.CALL, | ||
trustedDelegateCallTarget: false, | ||
addressInfoIndex: {}, | ||
dataDecoded: { | ||
method: 'approve', | ||
parameters: [ | ||
{ | ||
name: 'spender', | ||
type: 'address', | ||
value: spender, | ||
}, | ||
{ | ||
name: 'value', | ||
type: 'uint256', | ||
value: '100000', | ||
}, | ||
], | ||
}, | ||
}} | ||
/>, | ||
) | ||
|
||
expect(result.queryAllByText('approve')).not.toHaveLength(0) | ||
}) | ||
}) |
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