mirror of
https://github.com/trezor/trezor-wallet
synced 2025-01-12 17:10:56 +00:00
Added more unit tests - eth utils
This commit is contained in:
parent
6f9f31a2e4
commit
1a6c90bec0
@ -57,6 +57,7 @@ export default function modal(state: State = initialState, action: Action): Stat
|
||||
if (state.opened && action.device.path === state.device.path && action.device.status === 'occupied') {
|
||||
return initialState;
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
case DEVICE.DISCONNECT:
|
||||
|
@ -1,5 +1,7 @@
|
||||
// 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"`;
|
||||
@ -8,4 +10,30 @@ exports[`eth utils decimalToHex 3`] = `"2"`;
|
||||
|
||||
exports[`eth utils decimalToHex 4`] = `"64"`;
|
||||
|
||||
exports[`eth utils decimalToHex 5`] = `"3e7"`;
|
||||
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 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`] = `null`;
|
||||
|
||||
exports[`eth utils strip 1`] = `""`;
|
||||
|
||||
exports[`eth utils strip 2`] = `"02540be3ff"`;
|
||||
|
45
src/utils/__tests__/__snapshots__/formatUtils.test.js.snap
Normal file
45
src/utils/__tests__/__snapshots__/formatUtils.test.js.snap
Normal file
@ -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`] = `"5e-9 btc"`;
|
||||
|
||||
exports[`format utils formatAmount 3`] = `"1e-8 eth"`;
|
||||
|
||||
exports[`format utils formatAmount 4`] = `"0.00099999 undefined"`;
|
||||
|
||||
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 hexToString 1`] = `""`;
|
||||
|
||||
exports[`format utils hexToString 2`] = `"ªªª"`;
|
||||
|
||||
exports[`format utils hexToString 3`] = `""`;
|
||||
|
||||
exports[`format utils hexToString 4`] = `""`;
|
||||
|
||||
exports[`format utils hexToString 5`] = `""`;
|
||||
|
||||
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'];
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user