2021-04-15 20:01:46 +02:00
|
|
|
/* eslint-disable jest/no-conditional-expect */
|
2021-02-04 19:15:23 +01:00
|
|
|
import { ethers } from 'ethers';
|
|
|
|
import { renderHook } from '@testing-library/react-hooks';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { TRANSACTION_TYPES } from '../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import { useTokenData } from './useTokenData';
|
2020-05-26 22:49:11 +02:00
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
2020-11-03 00:41:28 +01:00
|
|
|
data:
|
|
|
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
2020-05-26 22:49:11 +02:00
|
|
|
tokenData: {
|
2021-03-10 21:16:44 +01:00
|
|
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
2020-11-03 00:41:28 +01:00
|
|
|
args: [
|
2020-08-22 04:29:19 +02:00
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(15000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-11-03 00:41:28 +01:00
|
|
|
data:
|
|
|
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
2020-05-26 22:49:11 +02:00
|
|
|
tokenData: {
|
2021-03-10 21:16:44 +01:00
|
|
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
2020-11-03 00:41:28 +01:00
|
|
|
args: [
|
2020-08-22 04:29:19 +02:00
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(25000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-11-03 00:41:28 +01:00
|
|
|
data:
|
|
|
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
2020-05-26 22:49:11 +02:00
|
|
|
tokenData: {
|
2021-03-10 21:16:44 +01:00
|
|
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
2020-11-03 00:41:28 +01:00
|
|
|
args: [
|
2020-08-22 04:29:19 +02:00
|
|
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
|
|
|
ethers.BigNumber.from(10000),
|
2020-05-26 22:49:11 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
tokenData: null,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-05-26 22:49:11 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('useTokenData', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
tests.forEach(({ data, tokenData }) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const testTitle =
|
2021-04-15 20:01:46 +02:00
|
|
|
// eslint-disable-next-line no-negated-condition
|
2021-12-09 20:06:24 +01:00
|
|
|
tokenData !== null
|
|
|
|
? `should return properly decoded data with _value ${tokenData.args[1]}`
|
2021-04-15 20:01:46 +02:00
|
|
|
: `should return null when no data provided`;
|
|
|
|
it(`${testTitle}`, () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
const { result } = renderHook(() => useTokenData(data));
|
|
|
|
if (tokenData) {
|
|
|
|
expect(result.current.name).toStrictEqual(tokenData.name);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.current.args[0].toLowerCase()).toStrictEqual(
|
2021-12-09 20:06:24 +01:00
|
|
|
tokenData.args[0],
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-12-09 20:06:24 +01:00
|
|
|
expect(tokenData.args[1]).toStrictEqual(result.current.args[1]);
|
2020-08-22 04:29:19 +02:00
|
|
|
} else {
|
2021-12-09 20:06:24 +01:00
|
|
|
expect(result.current).toStrictEqual(tokenData);
|
2020-08-22 04:29:19 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|