Eth utils tests refactored

pull/395/head
Vladimir Volek 5 years ago
parent 6d790d9e31
commit d4a19b5133

@ -1,45 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`eth utils calcGasPrice 1`] = `"89090990901"`;
exports[`eth utils decimalToHex 1`] = `"0"`;
exports[`eth utils decimalToHex 2`] = `"1"`;
exports[`eth utils decimalToHex 3`] = `"2"`;
exports[`eth utils decimalToHex 4`] = `"64"`;
exports[`eth utils decimalToHex 5`] = `"2540be3ff"`;
exports[`eth utils hexToDecimal 1`] = `"9999999999"`;
exports[`eth utils hexToDecimal 2`] = `"100"`;
exports[`eth utils hexToDecimal 3`] = `"2"`;
exports[`eth utils hexToDecimal 4`] = `"1"`;
exports[`eth utils hexToDecimal 5`] = `"0"`;
exports[`eth utils hexToDecimal 6`] = `"null"`;
exports[`eth utils padLeftEven 1`] = `"02540be3ff"`;
exports[`eth utils sanitizeHex 1`] = `"0x02540be3ff"`;
exports[`eth utils sanitizeHex 2`] = `"0x01"`;
exports[`eth utils sanitizeHex 3`] = `"0x02"`;
exports[`eth utils sanitizeHex 4`] = `"0x0100"`;
exports[`eth utils sanitizeHex 5`] = `"0x0999"`;
exports[`eth utils sanitizeHex 6`] = `""`;
exports[`eth utils strip 1`] = `""`;
exports[`eth utils strip 2`] = `"02540be3ff"`;
exports[`eth utils strip 3`] = `"02540be3ff"`;

@ -1,53 +1,44 @@
import BigNumber from 'bignumber.js';
import * as ethUtils from '../ethUtils';
import * as utils from '../ethUtils';
describe('eth utils', () => {
it('decimalToHex', () => {
const input = [0, 1, 2, 100, 9999999999];
input.forEach((entry) => {
expect(ethUtils.decimalToHex(entry)).toMatchSnapshot();
});
expect(utils.decimalToHex(0)).toBe('0');
expect(utils.decimalToHex(1)).toBe('1');
expect(utils.decimalToHex(2)).toBe('2');
expect(utils.decimalToHex(100)).toBe('64');
expect(utils.decimalToHex(9999999999)).toBe('2540be3ff');
});
// TODO: decimal as string ?????
it('hexToDecimal', () => {
const input = ['2540be3ff', '64', '2', '1', '0', ''];
input.forEach((entry) => {
expect(ethUtils.hexToDecimal(entry)).toMatchSnapshot();
});
expect(utils.hexToDecimal('2540be3ff')).toBe('9999999999');
expect(utils.hexToDecimal(64)).toBe('100');
expect(utils.hexToDecimal(2)).toBe('2');
expect(utils.hexToDecimal(1)).toBe('1');
expect(utils.hexToDecimal(0)).toBe('0');
});
it('padLeftEven', () => {
const input = ['2540be3ff'];
input.forEach((entry) => {
expect(ethUtils.padLeftEven(entry)).toMatchSnapshot();
});
expect(utils.padLeftEven('2540be3ff')).toBe('02540be3ff');
});
it('sanitizeHex', () => {
const input = ['0x2540be3ff', '1', '2', '100', '999', ''];
input.forEach((entry) => {
expect(ethUtils.sanitizeHex(entry)).toMatchSnapshot();
});
expect(utils.sanitizeHex('0x2540be3ff')).toBe('0x02540be3ff');
expect(utils.sanitizeHex('1')).toBe('0x01');
expect(utils.sanitizeHex('2')).toBe('0x02');
expect(utils.sanitizeHex('100')).toBe('0x0100');
expect(utils.sanitizeHex('999')).toBe('0x0999');
expect(utils.sanitizeHex('')).toBe('');
});
it('strip', () => {
const input = ['0x', '0x2540be3ff', '2540be3ff'];
input.forEach((entry) => {
expect(ethUtils.strip(entry)).toMatchSnapshot();
});
expect(utils.strip('0x')).toBe('');
expect(utils.strip('0x2540be3ff')).toBe('02540be3ff');
expect(utils.strip('2540be3ff')).toBe('02540be3ff');
});
it('calcGasPrice', () => {
const input = [{ price: new BigNumber(9898998989), limit: '9' }];
input.forEach((entry) => {
expect(ethUtils.calcGasPrice(entry.price, entry.limit)).toMatchSnapshot();
});
it('calculate gas price', () => {
expect(utils.calcGasPrice(new BigNumber(9898998989), 9)).toBe('89090990901');
});
});

Loading…
Cancel
Save