2020-05-12 21:07:35 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import { renderHook } from '@testing-library/react-hooks'
|
2020-08-18 21:18:25 +02:00
|
|
|
import sinon from 'sinon'
|
2020-05-12 21:07:35 +02:00
|
|
|
import * as tokenUtil from '../../helpers/utils/token-util'
|
|
|
|
import * as txUtil from '../../helpers/utils/transactions.util'
|
|
|
|
import { useTokenDisplayValue } from '../useTokenDisplayValue'
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
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 () {
|
2020-08-22 04:29:19 +02:00
|
|
|
const getTokenValueStub = sinon.stub(tokenUtil, 'getTokenValueParam')
|
2020-05-12 21:07:35 +02:00
|
|
|
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),
|
|
|
|
)
|
2020-05-12 21:07:35 +02:00
|
|
|
sinon.restore()
|
|
|
|
assert.equal(result.current, test.displayValue)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|