2021-02-04 19:15:23 +01:00
|
|
|
import { ETH } from '../constants/common';
|
|
|
|
import * as utils from './conversions.util';
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('conversion utils', () => {
|
|
|
|
describe('getWeiHexFromDecimalValue', () => {
|
|
|
|
it('should correctly convert 0 in ETH', () => {
|
2020-10-23 20:49:49 +02:00
|
|
|
const weiValue = utils.getWeiHexFromDecimalValue({
|
|
|
|
value: '0',
|
|
|
|
fromCurrency: ETH,
|
|
|
|
fromDenomination: ETH,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('0');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-09-10 07:00:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('decETHToDecWEI', () => {
|
|
|
|
it('should correctly convert 1 ETH to WEI', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const weiValue = utils.decETHToDecWEI('1');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('1000000000000000000');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should correctly convert 0.000000000000000001 ETH to WEI', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const weiValue = utils.decETHToDecWEI('0.000000000000000001');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('1');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should correctly convert 1000000.000000000000000001 ETH to WEI', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const weiValue = utils.decETHToDecWEI('1000000.000000000000000001');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('1000000000000000000000001');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should correctly convert 9876.543210 ETH to WEI', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const weiValue = utils.decETHToDecWEI('9876.543210');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('9876543210000000000000');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-08-06 18:22:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should correctly convert 1.0000000000000000 ETH to WEI', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const weiValue = utils.decETHToDecWEI('1.0000000000000000');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(weiValue).toStrictEqual('1000000000000000000');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2022-08-09 19:56:52 +02:00
|
|
|
|
|
|
|
describe('decWEIToDecETH', () => {
|
|
|
|
it('converts 10000000000000 WEI to ETH', () => {
|
|
|
|
const ethDec = utils.decWEIToDecETH('10000000000000');
|
|
|
|
expect('0.00001').toStrictEqual(ethDec);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts 9358749494527040 WEI to ETH', () => {
|
|
|
|
const ethDec = utils.decWEIToDecETH('9358749494527040');
|
|
|
|
expect('0.009358749').toStrictEqual(ethDec);
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|