|
2 | 2 | from decimal import Decimal |
3 | 3 |
|
4 | 4 | def test_it_should_parse_units_into_wei(): |
5 | | - assert UnitConverter.parse_units(1, 'wei') == 1 |
6 | | - assert UnitConverter.parse_units(1.0, 'wei') == 1 |
7 | | - assert UnitConverter.parse_units('1', 'wei') == 1 |
8 | | - assert UnitConverter.parse_units('1.0', 'wei') == 1 |
| 5 | + assert UnitConverter.parse_units(1, 'wei') == Decimal('1') |
| 6 | + assert UnitConverter.parse_units(1.0, 'wei') == Decimal('1') |
| 7 | + assert UnitConverter.parse_units('1', 'wei') == Decimal('1') |
| 8 | + assert UnitConverter.parse_units('1.0', 'wei') == Decimal('1') |
9 | 9 |
|
10 | | - assert UnitConverter.parse_units(Decimal(1), 'wei') == 1 |
11 | | - assert UnitConverter.parse_units(Decimal(1.0), 'wei') == 1 |
12 | | - assert UnitConverter.parse_units(Decimal('1'), 'wei') == 1 |
13 | | - assert UnitConverter.parse_units(Decimal('1.0'), 'wei') == 1 |
| 10 | + assert UnitConverter.parse_units(Decimal(1), 'wei') == Decimal('1') |
| 11 | + assert UnitConverter.parse_units(Decimal(1.0), 'wei') == Decimal('1') |
| 12 | + assert UnitConverter.parse_units(Decimal('1'), 'wei') == Decimal('1') |
| 13 | + assert UnitConverter.parse_units(Decimal('1.0'), 'wei') == Decimal('1') |
| 14 | + |
| 15 | + assert isinstance(UnitConverter.parse_units(1, 'wei'), Decimal) |
14 | 16 |
|
15 | 17 | def test_it_should_parse_units_into_gwei(): |
16 | | - assert UnitConverter.parse_units(1, 'gwei') == 1000000000 |
17 | | - assert UnitConverter.parse_units(1.0, 'gwei') == 1000000000 |
18 | | - assert UnitConverter.parse_units('1', 'gwei') == 1000000000 |
19 | | - assert UnitConverter.parse_units('1.0', 'gwei') == 1000000000 |
| 18 | + assert UnitConverter.parse_units(1, 'gwei') == Decimal('1000000000') |
| 19 | + assert UnitConverter.parse_units(1.0, 'gwei') == Decimal('1000000000') |
| 20 | + assert UnitConverter.parse_units('1', 'gwei') == Decimal('1000000000') |
| 21 | + assert UnitConverter.parse_units('1.0', 'gwei') == Decimal('1000000000') |
| 22 | + |
| 23 | + assert UnitConverter.parse_units(Decimal(1), 'gwei') == Decimal('1000000000') |
| 24 | + assert UnitConverter.parse_units(Decimal(1.0), 'gwei') == Decimal('1000000000') |
| 25 | + assert UnitConverter.parse_units(Decimal('1'), 'gwei') == Decimal('1000000000') |
| 26 | + assert UnitConverter.parse_units(Decimal('1.0'), 'gwei') == Decimal('1000000000') |
20 | 27 |
|
21 | | - assert UnitConverter.parse_units(Decimal(1), 'gwei') == 1000000000 |
22 | | - assert UnitConverter.parse_units(Decimal(1.0), 'gwei') == 1000000000 |
23 | | - assert UnitConverter.parse_units(Decimal('1'), 'gwei') == 1000000000 |
24 | | - assert UnitConverter.parse_units(Decimal('1.0'), 'gwei') == 1000000000 |
| 28 | + assert isinstance(UnitConverter.parse_units(1, 'gwei'), Decimal) |
25 | 29 |
|
26 | 30 | def test_it_should_parse_units_into_ark(): |
27 | | - assert UnitConverter.parse_units(1, 'ark') == 1000000000000000000 |
28 | | - assert UnitConverter.parse_units(1.0, 'ark') == 1000000000000000000 |
29 | | - assert UnitConverter.parse_units('1', 'ark') == 1000000000000000000 |
30 | | - assert UnitConverter.parse_units('1.0', 'ark') == 1000000000000000000 |
| 31 | + assert UnitConverter.parse_units(1, 'ark') == Decimal('1000000000000000000') |
| 32 | + assert UnitConverter.parse_units(1.0, 'ark') == Decimal('1000000000000000000') |
| 33 | + assert UnitConverter.parse_units('1', 'ark') == Decimal('1000000000000000000') |
| 34 | + assert UnitConverter.parse_units('1.0', 'ark') == Decimal('1000000000000000000') |
31 | 35 |
|
32 | | - assert UnitConverter.parse_units(Decimal(1), 'ark') == 1000000000000000000 |
33 | | - assert UnitConverter.parse_units(Decimal(1.0), 'ark') == 1000000000000000000 |
34 | | - assert UnitConverter.parse_units(Decimal('1'), 'ark') == 1000000000000000000 |
35 | | - assert UnitConverter.parse_units(Decimal('1.0'), 'ark') == 1000000000000000000 |
| 36 | + assert UnitConverter.parse_units(Decimal(1), 'ark') == Decimal('1000000000000000000') |
| 37 | + assert UnitConverter.parse_units(Decimal(1.0), 'ark') == Decimal('1000000000000000000') |
| 38 | + assert UnitConverter.parse_units(Decimal('1'), 'ark') == Decimal('1000000000000000000') |
| 39 | + assert UnitConverter.parse_units(Decimal('1.0'), 'ark') == Decimal('1000000000000000000') |
| 40 | + |
| 41 | + assert isinstance(UnitConverter.parse_units(1, 'ark'), Decimal) |
36 | 42 |
|
37 | 43 | def test_it_should_parse_decimal_units_into_ark(): |
38 | | - assert UnitConverter.parse_units(0.1, 'ark') == 100000000000000000 |
39 | | - assert UnitConverter.parse_units('0.1', 'ark') == 100000000000000000 |
| 44 | + assert UnitConverter.parse_units(0.1, 'ark') == Decimal('100000000000000000') |
| 45 | + assert UnitConverter.parse_units('0.1', 'ark') == Decimal('100000000000000000') |
40 | 46 |
|
41 | 47 | def test_it_should_format_units_from_wei(): |
42 | 48 | assert UnitConverter.format_units(1, 'wei') == 1.0 |
@@ -120,3 +126,13 @@ def test_it_should_convert_gwei_to_ark(): |
120 | 126 | assert UnitConverter.gwei_to_ark(Decimal('1')) == '0.000000001' |
121 | 127 | assert UnitConverter.gwei_to_ark(Decimal('1000000000'), 'DARK') == '1 DARK' |
122 | 128 | assert UnitConverter.gwei_to_ark(Decimal('1000000000')) == '1' |
| 129 | + |
| 130 | +def test_it_should_handle_large_token_supply(): |
| 131 | + large_supply = '999999999999999999999999999999999999999' |
| 132 | + result = UnitConverter.format_units(large_supply, 'ark') |
| 133 | + assert isinstance(result, Decimal) |
| 134 | + assert result == Decimal('999999999999999999999.999999999999999999') |
| 135 | + |
| 136 | + result = UnitConverter.parse_units(large_supply, 'wei') |
| 137 | + assert isinstance(result, Decimal) |
| 138 | + assert result == Decimal(large_supply) |
0 commit comments