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.1 KiB
68 lines
2.1 KiB
4 years ago
|
import assert from 'assert';
|
||
|
import { ethers } from 'ethers';
|
||
|
import { renderHook } from '@testing-library/react-hooks';
|
||
4 years ago
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
||
|
import { useTokenData } from './useTokenData';
|
||
5 years ago
|
|
||
|
const tests = [
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000003a98',
|
||
5 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(15000),
|
||
5 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a9700000000000000000000000000000000000000000000000000000000000061a8',
|
||
5 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(25000),
|
||
5 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
4 years ago
|
data:
|
||
|
'0xa9059cbb000000000000000000000000ffe5bc4e8f1f969934d773fa67da095d2e491a970000000000000000000000000000000000000000000000000000000000002710',
|
||
5 years ago
|
tokenData: {
|
||
4 years ago
|
name: TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER,
|
||
4 years ago
|
args: [
|
||
4 years ago
|
'0xffe5bc4e8f1f969934d773fa67da095d2e491a97',
|
||
|
ethers.BigNumber.from(10000),
|
||
5 years ago
|
],
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
data: undefined,
|
||
|
tokenData: null,
|
||
|
},
|
||
4 years ago
|
];
|
||
5 years ago
|
|
||
|
describe('useTokenData', function () {
|
||
|
tests.forEach((test) => {
|
||
4 years ago
|
const testTitle =
|
||
|
test.tokenData === null
|
||
|
? `should return null when no data provided`
|
||
4 years ago
|
: `should return properly decoded data with _value ${test.tokenData.args[1].value}`;
|
||
5 years ago
|
it(testTitle, function () {
|
||
4 years ago
|
const { result } = renderHook(() => useTokenData(test.data));
|
||
4 years ago
|
if (test.tokenData) {
|
||
4 years ago
|
assert.strictEqual(result.current.name, test.tokenData.name);
|
||
4 years ago
|
assert.strictEqual(
|
||
4 years ago
|
result.current.args[0].toLowerCase(),
|
||
|
test.tokenData.args[0],
|
||
4 years ago
|
);
|
||
|
assert.ok(test.tokenData.args[1].eq(result.current.args[1]));
|
||
4 years ago
|
} else {
|
||
4 years ago
|
assert.strictEqual(result.current, test.tokenData);
|
||
4 years ago
|
}
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|