-
Notifications
You must be signed in to change notification settings - Fork 67
/
utils.test.ts
35 lines (26 loc) · 1.17 KB
/
utils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import BigNumber from 'bignumber.js'
import { RAD } from 'components/constants'
import { one } from 'helpers/zero'
import { amountFromGwei, amountFromRad, amountFromRay } from './utils'
describe('utils$', () => {
it('should not reconfigure global precision for bignumber', () => {
const defaultDecimals = BigNumber.config({}).DECIMAL_PLACES
amountFromRad(one)
expect(BigNumber.config({}).DECIMAL_PLACES).toBe(defaultDecimals)
amountFromRay(one)
expect(BigNumber.config({}).DECIMAL_PLACES).toBe(defaultDecimals)
})
it('should not lose precision when dividing rad value', () => {
const radValue = RAD.plus(2)
const radValueUnits = amountFromRad(radValue)
const halfRadValueUnits = radValueUnits.div(2)
// Return values is not needed, so ignore it
amountFromRay(one)
expect(halfRadValueUnits.toFixed()).toBe('0.500000000000000000000000000000000000000000001')
expect(radValueUnits.div(2).toFixed()).toBe(halfRadValueUnits.toFixed())
})
//TODO: [Mocha -> Jest] Rewrite in Jest compatible format.
it.skip('should convert from gwei correctly', () => {
expect(amountFromGwei(new BigNumber('1')).toString()).toBe('0.000000001')
})
})