mirror of https://github.com/trezor/trezor-wallet
commit
ccddcc3ad3
@ -1,11 +1,19 @@
|
||||
module.exports = {
|
||||
rootDir: './src',
|
||||
automock: false,
|
||||
coverageDirectory: 'coverage/',
|
||||
collectCoverage: true,
|
||||
testURL: 'http://localhost',
|
||||
modulePathIgnorePatterns: [
|
||||
'node_modules',
|
||||
'utils/windowUtils.js',
|
||||
'utils/promiseUtils.js',
|
||||
'utils/networkUtils.js',
|
||||
],
|
||||
collectCoverageFrom: [
|
||||
'utils/**.js',
|
||||
],
|
||||
setupFiles: [
|
||||
'./support/setupJest.js',
|
||||
],
|
||||
};
|
||||
|
@ -0,0 +1 @@
|
||||
global.fetch = require('jest-fetch-mock');
|
@ -0,0 +1,45 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`format utils btckb2satoshib 1`] = `0`;
|
||||
|
||||
exports[`format utils btckb2satoshib 2`] = `100000`;
|
||||
|
||||
exports[`format utils btckb2satoshib 3`] = `200000`;
|
||||
|
||||
exports[`format utils btckb2satoshib 4`] = `10000000`;
|
||||
|
||||
exports[`format utils btckb2satoshib 5`] = `99900000`;
|
||||
|
||||
exports[`format utils formatAmount 1`] = `"0 btc"`;
|
||||
|
||||
exports[`format utils formatAmount 2`] = `"10 mBTC"`;
|
||||
|
||||
exports[`format utils formatAmount 3`] = `"0.000005 mBTC"`;
|
||||
|
||||
exports[`format utils formatAmount 4`] = `"1e-8 eth"`;
|
||||
|
||||
exports[`format utils formatAmount 5`] = `"0.00099999 tau"`;
|
||||
|
||||
exports[`format utils formatTime 1`] = `"No time estimate"`;
|
||||
|
||||
exports[`format utils formatTime 2`] = `"1 minutes"`;
|
||||
|
||||
exports[`format utils formatTime 3`] = `"2 minutes"`;
|
||||
|
||||
exports[`format utils formatTime 4`] = `"1 hour 40 minutes"`;
|
||||
|
||||
exports[`format utils formatTime 5`] = `"16 hours 39 minutes"`;
|
||||
|
||||
exports[`format utils formatTime 6`] = `"45 minutes"`;
|
||||
|
||||
exports[`format utils hexToString 1`] = `"test"`;
|
||||
|
||||
exports[`format utils hexToString 2`] = `"0001"`;
|
||||
|
||||
exports[`format utils hexToString 3`] = `"test99999"`;
|
||||
|
||||
exports[`format utils stringToHex 1`] = `"0074006500730074"`;
|
||||
|
||||
exports[`format utils stringToHex 2`] = `"0030003000300031"`;
|
||||
|
||||
exports[`format utils stringToHex 3`] = `"007400650073007400390039003900390039"`;
|
@ -1,11 +1,53 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as ethUtils from '../ethUtils';
|
||||
|
||||
describe('eth utils', () => {
|
||||
it('decimalToHex', () => {
|
||||
const input = [0, 1, 2, 100, 999];
|
||||
const input = [0, 1, 2, 100, 9999999999];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.decimalToHex(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('hexToDecimal', () => {
|
||||
const input = ['2540be3ff', '64', '2', '1', '0', ''];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.hexToDecimal(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('padLeftEven', () => {
|
||||
const input = ['2540be3ff'];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.padLeftEven(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('sanitizeHex', () => {
|
||||
const input = ['0x2540be3ff', '1', '2', '100', 999, ''];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.sanitizeHex(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('strip', () => {
|
||||
const input = ['0x', '0x2540be3ff', '2540be3ff'];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.strip(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('calcGasPrice', () => {
|
||||
const input = [{ price: new BigNumber(9898998989), limit: '9' }];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(ethUtils.calcGasPrice(entry.price, entry.limit)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -0,0 +1,49 @@
|
||||
import * as formatUtils from '../formatUtils';
|
||||
|
||||
describe('format utils', () => {
|
||||
it('formatAmount', () => {
|
||||
const input = [
|
||||
{ amount: 0, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
|
||||
{ amount: 1000000, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
|
||||
{ amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
|
||||
{ amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } },
|
||||
{ amount: 99999, coinInfo: { isBitcoin: false, shortcut: 'tau' } },
|
||||
];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(formatUtils.formatAmount(entry.amount, entry.coinInfo, entry.coinInfo.currencyUnits)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('formatTime', () => {
|
||||
const input = [0, 1, 2, 100, 999, 45];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(formatUtils.formatTime(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('btckb2satoshib', () => {
|
||||
const input = [0, 1, 2, 100, 999];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(formatUtils.btckb2satoshib(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('stringToHex', () => {
|
||||
const input = ['test', '0001', 'test99999'];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(formatUtils.stringToHex(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('hexToString', () => {
|
||||
const input = ['0074006500730074', '0030003000300031', '007400650073007400390039003900390039'];
|
||||
|
||||
input.forEach((entry) => {
|
||||
expect(formatUtils.hexToString(entry)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in new issue