mirror of https://github.com/trezor/trezor-wallet
parent
921ca49535
commit
366e5f4d10
@ -1,32 +1,24 @@
|
||||
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('to decimal amount', () => {
|
||||
expect(utils.toDecimalAmount(0, 1)).toBe('0');
|
||||
expect(utils.toDecimalAmount(1, 1)).toBe('0.1');
|
||||
expect(utils.toDecimalAmount(1000, 1)).toBe('100');
|
||||
expect(utils.toDecimalAmount(1000, 2)).toBe('10');
|
||||
expect(utils.toDecimalAmount(1000, 3)).toBe('1');
|
||||
expect(utils.toDecimalAmount('1', 'a')).toBe('NaN');
|
||||
expect(utils.toDecimalAmount('a', 'a')).toBe('0');
|
||||
expect(utils.toDecimalAmount('a', '1')).toBe('0');
|
||||
});
|
||||
|
||||
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');
|
||||
it('from decimal amount', () => {
|
||||
expect(utils.fromDecimalAmount(0, 1)).toBe('0');
|
||||
expect(utils.fromDecimalAmount(10, 1)).toBe('100');
|
||||
expect(utils.fromDecimalAmount(10, 2)).toBe('1000');
|
||||
expect(utils.fromDecimalAmount(10, 3)).toBe('10000');
|
||||
expect(utils.fromDecimalAmount('1', 'a')).toBe('NaN');
|
||||
expect(utils.fromDecimalAmount('a', 'a')).toBe('0');
|
||||
expect(utils.fromDecimalAmount('a', '1')).toBe('0');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in new issue