You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
68 lines
2.2 KiB
4 years ago
|
/* eslint-disable jest/no-conditional-expect */
|
||
4 years ago
|
import { ethers } from 'ethers';
|
||
|
import { renderHook } from '@testing-library/react-hooks';
|
||
4 years ago
|
import { TRANSACTION_TYPES } from '../../shared/constants/transaction';
|
||
4 years ago
|
import { useTokenData } from './useTokenData';
|
||
4 years ago
|
|
||
|
const tests = [
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
||
4 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(15000),
|
||
4 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
||
4 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(25000),
|
||
4 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
||
4 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(10000),
|
||
4 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
data: undefined,
|
||
|
tokenData: null,
|
||
|
},
|
||
4 years ago
|
];
|
||
4 years ago
|
|
||
4 years ago
|
describe('useTokenData', () => {
|
||
4 years ago
|
tests.forEach((test) => {
|
||
4 years ago
|
const testTitle =
|
||
4 years ago
|
// eslint-disable-next-line no-negated-condition
|
||
|
test.tokenData !== null
|
||
|
? `should return properly decoded data with _value ${test.tokenData.args[1]}`
|
||
|
: `should return null when no data provided`;
|
||
|
it(`${testTitle}`, () => {
|
||
4 years ago
|
const { result } = renderHook(() => useTokenData(test.data));
|
||
4 years ago
|
if (test.tokenData) {
|
||
4 years ago
|
expect(result.current.name).toStrictEqual(test.tokenData.name);
|
||
|
expect(result.current.args[0].toLowerCase()).toStrictEqual(
|
||
4 years ago
|
test.tokenData.args[0],
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(test.tokenData.args[1]).toStrictEqual(result.current.args[1]);
|
||
4 years ago
|
} else {
|
||
4 years ago
|
expect(result.current).toStrictEqual(test.tokenData);
|
||
4 years ago
|
}
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|