mirror of https://github.com/trezor/trezor-wallet
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.5 KiB
33 lines
1.5 KiB
import * as utils from '../formatUtils';
|
|
|
|
describe('format utils', () => {
|
|
// TODO: check this weird function
|
|
it('formatAmount', () => {
|
|
expect(utils.formatAmount(0, { isBitcoin: false, shortcut: 'mbtc' }, 'mbtc')).toBe('0 mbtc');
|
|
expect(utils.formatAmount(1000000, { isBitcoin: true }, 'mbtc')).toBe('10 mBTC');
|
|
expect(utils.formatAmount(0.5, { isBitcoin: true }, 'mbtc')).toBe('0.000005 mBTC');
|
|
expect(utils.formatAmount(1, { isBitcoin: false, shortcut: 'eth' }, null)).toBe('1e-8 eth');
|
|
expect(utils.formatAmount(99999, { isBitcoin: false, shortcut: 'tau' }, null)).toBe('0.00099999 tau');
|
|
});
|
|
|
|
it('btckb2satoshib', () => {
|
|
expect(utils.btckb2satoshib(0)).toBe(0);
|
|
expect(utils.btckb2satoshib(1)).toBe(100000);
|
|
expect(utils.btckb2satoshib(2)).toBe(200000);
|
|
expect(utils.btckb2satoshib(100)).toBe(10000000);
|
|
expect(utils.btckb2satoshib(999)).toBe(99900000);
|
|
});
|
|
|
|
it('string to hex', () => {
|
|
expect(utils.stringToHex('test')).toBe('0074006500730074');
|
|
expect(utils.stringToHex('0001')).toBe('0030003000300031');
|
|
expect(utils.stringToHex('test99999')).toBe('007400650073007400390039003900390039');
|
|
});
|
|
|
|
it('hex to string', () => {
|
|
expect(utils.hexToString('0074006500730074')).toBe('test');
|
|
expect(utils.hexToString('0030003000300031')).toBe('0001');
|
|
expect(utils.hexToString('007400650073007400390039003900390039')).toBe('test99999');
|
|
});
|
|
});
|