2021-02-04 19:15:23 +01:00
|
|
|
import { renderHook } from '@testing-library/react-hooks';
|
|
|
|
import sinon from 'sinon';
|
2021-03-16 22:00:08 +01:00
|
|
|
import * as tokenUtil from '../helpers/utils/token-util';
|
2022-03-17 19:35:40 +01:00
|
|
|
import * as txUtil from '../../shared/modules/transaction.utils';
|
2021-03-16 22:00:08 +01:00
|
|
|
import { useTokenDisplayValue } from './useTokenDisplayValue';
|
2020-05-12 21:07:35 +02:00
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'DAI',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params1',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1000000000000000000',
|
|
|
|
displayValue: '1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'DAI',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params2',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '10000000000000000000',
|
|
|
|
displayValue: '10',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'DAI',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params3',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1500000000000000000',
|
|
|
|
displayValue: '1.5',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'DAI',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params4',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1756000000000000000',
|
|
|
|
displayValue: '1.756',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'DAI',
|
|
|
|
decimals: 18,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params5',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '25500000000000000000',
|
|
|
|
displayValue: '25.5',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'USDC',
|
|
|
|
decimals: 6,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params6',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1000000',
|
|
|
|
displayValue: '1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'USDC',
|
|
|
|
decimals: 6,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params7',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '10000000',
|
|
|
|
displayValue: '10',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'USDC',
|
|
|
|
decimals: 6,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params8',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1500000',
|
|
|
|
displayValue: '1.5',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'USDC',
|
|
|
|
decimals: 6,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params9',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '1756000',
|
|
|
|
displayValue: '1.756',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
token: {
|
|
|
|
symbol: 'USDC',
|
|
|
|
decimals: 6,
|
|
|
|
},
|
|
|
|
tokenData: {
|
2020-08-22 04:29:19 +02:00
|
|
|
args: 'decoded-params10',
|
2020-05-12 21:07:35 +02:00
|
|
|
},
|
|
|
|
tokenValue: '25500000',
|
|
|
|
displayValue: '25.5',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-05-12 21:07:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('useTokenDisplayValue', () => {
|
2021-12-09 20:06:24 +01:00
|
|
|
tests.forEach(({ displayValue, token, tokenData, tokenValue }, idx) => {
|
|
|
|
describe(`when input is decimals: ${token.decimals} and value: ${tokenValue}`, () => {
|
|
|
|
it(`should return ${displayValue} as displayValue`, () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const getTokenValueStub = sinon.stub(tokenUtil, 'getTokenValueParam');
|
2022-03-17 19:35:40 +01:00
|
|
|
const parseStandardTokenTransactionDataStub = sinon.stub(
|
|
|
|
txUtil,
|
|
|
|
'parseStandardTokenTransactionData',
|
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
|
2022-03-17 19:35:40 +01:00
|
|
|
parseStandardTokenTransactionDataStub.callsFake(() => tokenData);
|
2021-12-09 20:06:24 +01:00
|
|
|
getTokenValueStub.callsFake(() => tokenValue);
|
2021-04-15 20:01:46 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const { result } = renderHook(() =>
|
2021-12-09 20:06:24 +01:00
|
|
|
useTokenDisplayValue(`${idx}-fakestring`, token),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
sinon.restore();
|
2021-12-09 20:06:24 +01:00
|
|
|
expect(result.current).toStrictEqual(displayValue);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|