|
|
@@ -9,6 +9,7 @@ from decimal import Decimal
|
|
|
from mmgen.protocol import init_proto
|
|
|
from mmgen.tx.new import parse_fee_spec
|
|
|
from mmgen.cfg import Config
|
|
|
+from mmgen.amt import TokenAmt
|
|
|
|
|
|
from ..include.common import cfg, vmsg
|
|
|
|
|
|
@@ -38,7 +39,7 @@ def test_fee_spec(data):
|
|
|
|
|
|
class unit_tests:
|
|
|
|
|
|
- altcoin_deps = ('fee_spec_alt', 'to_unit_alt')
|
|
|
+ altcoin_deps = ('fee_spec_alt', 'to_unit_alt', 'token_amt')
|
|
|
|
|
|
def to_unit(self, name, ut, desc='CoinAmt.to_unit() (BTC)'):
|
|
|
return test_to_unit((
|
|
|
@@ -79,3 +80,18 @@ class unit_tests:
|
|
|
('eth', '3701w', '3701', 'wei'),
|
|
|
('eth', '3.07M', '3.07', 'Mwei'),
|
|
|
('xmr', '3.07a', '3.07', 'atomic')))
|
|
|
+
|
|
|
+ def token_amt(self, name, ut, desc='TokenAmt (ETH)'):
|
|
|
+ for n, dec, unit, chk in (
|
|
|
+ (1234567, 6, 'atomic', '1.234567'),
|
|
|
+ ('1.234567', 6, None, '1.234567'),
|
|
|
+ (1234567, 22, 'atomic', '0.0000000000000001234567'),
|
|
|
+ ('0.0000000000000001234567', 22, None, '0.0000000000000001234567'),
|
|
|
+ ):
|
|
|
+ amt = TokenAmt(n, decimals=dec, from_unit=unit)
|
|
|
+ amt_disp = amt.hl(color=False)
|
|
|
+ vmsg(' ' + amt_disp)
|
|
|
+ if unit == 'atomic':
|
|
|
+ assert amt.to_unit('atomic') == n
|
|
|
+ assert amt_disp == chk, f'{amt_disp} != {chk}'
|
|
|
+ return True
|