This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ethtools-tests.js
85 lines (60 loc) · 3.07 KB
/
ethtools-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Tinytest.add('EthTools.toWei', function (test) {
// set BTC price
EthTools.ticker.update('btc', {$set: {
price: '0.01230'
}});
test.equal(EthTools.toWei(0.025, 'btc'), "2032520325203252033");
test.equal(EthTools.toWei(0.02554351, 'btc'), "2076708130081300813");
// set EUR price
EthTools.ticker.update('eur', {$set: {
price: '3.12344'
}});
test.equal(EthTools.toWei(6.247, 'eur'), "2000038419178854084");
test.equal(EthTools.toWei(6.24688, 'eur'), "2000000000000000000");
test.equal(EthTools.toWei('3.7481279999999999042', 'eur'), "1199999999999999969");
});
Tinytest.add('EthTools.formatNumber', function (test) {
test.equal(EthTools.formatNumber('1000000000000000000', '0,0.0[00]'), "1,000,000,000,000,000,000.0");
test.equal(EthTools.formatNumber('11234565.4565432', '0,0.0[00]'), "11,234,565.457");
});
Tinytest.add('EthTools.formatBalance', function (test) {
// default to ether
if(Meteor.isClient)
EthTools.setUnit('ether');
test.equal(EthTools.formatBalance('1000000000000000000', '0,0.0[00] unit'), "1.0 ether");
// default to finney
if(Meteor.isClient) {
EthTools.setUnit('finney');
test.equal(EthTools.formatBalance('1000000000000000000', '0,0.0[00] unit'), "1,000.0 finney");
test.equal(EthTools.formatBalance('100000000000000000', '0,0.0[00] UNIT'), "100.0 FINNEY");
}
test.equal(EthTools.formatBalance('1000000000000000000', '0,0.0[00] unit', 'gwei'), "1,000,000,000.0 gwei");
test.equal(EthTools.formatBalance('112345676543212345', '0,0.0[00] UNIT', 'gwei'), "112,345,676.543 GWEI");
test.equal(EthTools.formatBalance('112345676543212345', '0,0.0[0000]', 'gwei'), "112,345,676.54321");
// set BTC price
EthTools.ticker.update('btc', {$set: {
price: '0.01230'
}});
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[00]', 'btc'), "0.025");
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[00] unit', 'btc'), "0.025 btc");
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[00]unit', 'btc'), "0.025btc");
EthTools.ticker.update('btc', {$set: {
price: '0.1'
}});
test.equal(EthTools.formatBalance('1000000000000000000', '0,0.0000000000000000000', 'btc'), "0.1000000000000000056");
// set EUR price
EthTools.ticker.update('eur', {$set: {
price: '3.12344'
}});
test.equal(EthTools.formatBalance('1200000000000000012', '0,0.0000000000000000000', 'eur'), "3.7481279999999999042");
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[00]', 'eur'), "6.247");
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[00] UNIT', 'eur'), "6.247 EUR");
test.equal(EthTools.formatBalance('2000000000000000000', '0,0.0[0000]UNIT', 'eur'), "6.24688EUR");
EthTools.ticker.update('eur', {$set: {
price: '1.00000'
}});
test.equal(EthTools.formatBalance('1000000000000000000', '0,0.0000000000000000000', 'eur'), "1.0000000000000000000");
// reset
if(Meteor.isClient)
EthTools.setUnit('ether');
});