2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
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';
|
|
|
|
import * as txUtil from '../helpers/utils/transactions.util';
|
|
|
|
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
|
|
|
|
|
|
|
describe('useTokenDisplayValue', function () {
|
|
|
|
tests.forEach((test, idx) => {
|
|
|
|
describe(`when input is decimals: ${test.token.decimals} and value: ${test.tokenValue}`, function () {
|
|
|
|
it(`should return ${test.displayValue} as displayValue`, function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const getTokenValueStub = sinon.stub(tokenUtil, 'getTokenValueParam');
|
|
|
|
const getTokenDataStub = sinon.stub(txUtil, 'getTokenData');
|
|
|
|
getTokenDataStub.callsFake(() => test.tokenData);
|
|
|
|
getTokenValueStub.callsFake(() => test.tokenValue);
|
2020-11-03 00:41:28 +01:00
|
|
|
const { result } = renderHook(() =>
|
|
|
|
useTokenDisplayValue(`${idx}-fakestring`, test.token),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
sinon.restore();
|
|
|
|
assert.strictEqual(result.current, test.displayValue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|