2020-08-06 18:22:12 +02:00
|
|
|
import assert from 'assert'
|
2020-09-10 07:00:04 +02:00
|
|
|
import { ETH } from '../constants/common'
|
2020-08-18 21:18:25 +02:00
|
|
|
import * as utils from './conversions.util'
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
describe('conversion utils', function () {
|
|
|
|
describe('getWeiHexFromDecimalValue', function () {
|
|
|
|
it('should correctly convert 0 in ETH', function () {
|
|
|
|
const weiValue = utils.getWeiHexFromDecimalValue({
|
|
|
|
value: '0',
|
|
|
|
fromCurrency: ETH,
|
|
|
|
fromDenomination: ETH,
|
|
|
|
})
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '0')
|
2020-09-10 07:00:04 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
describe('decETHToDecWEI', function () {
|
|
|
|
it('should correctly convert 1 ETH to WEI', function () {
|
|
|
|
const weiValue = utils.decETHToDecWEI('1')
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '1000000000000000000')
|
2020-10-23 20:49:49 +02:00
|
|
|
})
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
it('should correctly convert 0.000000000000000001 ETH to WEI', function () {
|
|
|
|
const weiValue = utils.decETHToDecWEI('0.000000000000000001')
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '1')
|
2020-10-23 20:49:49 +02:00
|
|
|
})
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
it('should correctly convert 1000000.000000000000000001 ETH to WEI', function () {
|
|
|
|
const weiValue = utils.decETHToDecWEI('1000000.000000000000000001')
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '1000000000000000000000001')
|
2020-10-23 20:49:49 +02:00
|
|
|
})
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
it('should correctly convert 9876.543210 ETH to WEI', function () {
|
|
|
|
const weiValue = utils.decETHToDecWEI('9876.543210')
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '9876543210000000000000')
|
2020-10-23 20:49:49 +02:00
|
|
|
})
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2020-10-23 20:49:49 +02:00
|
|
|
it('should correctly convert 1.0000000000000000 ETH to WEI', function () {
|
|
|
|
const weiValue = utils.decETHToDecWEI('1.0000000000000000')
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(weiValue, '1000000000000000000')
|
2020-10-23 20:49:49 +02:00
|
|
|
})
|
2020-08-06 18:22:12 +02:00
|
|
|
})
|
|
|
|
})
|