1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-02-11 15:42:42 +00:00
trezor-wallet/src/utils/__tests__/formatUtils.test.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-09-12 08:54:03 +00:00
import * as formatUtils from '../formatUtils';
describe('format utils', () => {
it('formatAmount', () => {
const input = [
{ amount: 0, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
2018-09-12 14:01:48 +00:00
{ amount: 1000000, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
2018-09-12 08:54:03 +00:00
{ amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } },
{ amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } },
2018-09-12 14:43:08 +00:00
{ amount: 99999, coinInfo: { isBitcoin: false, shortcut: 'tau' } },
2018-09-12 08:54:03 +00:00
];
input.forEach((entry) => {
2018-09-12 14:01:48 +00:00
expect(formatUtils.formatAmount(entry.amount, entry.coinInfo, entry.coinInfo.currencyUnits)).toMatchSnapshot();
2018-09-12 08:54:03 +00:00
});
});
it('formatTime', () => {
2018-09-12 14:01:48 +00:00
const input = [0, 1, 2, 100, 999, 45];
2018-09-12 08:54:03 +00:00
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', () => {
2018-09-12 14:01:48 +00:00
const input = ['0074006500730074', '0030003000300031', '007400650073007400390039003900390039'];
2018-09-12 08:54:03 +00:00
input.forEach((entry) => {
expect(formatUtils.hexToString(entry)).toMatchSnapshot();
});
});
});