feat(converters): add from_wei and to_wei

This commit is contained in:
William Luke
2022-02-03 10:35:29 +03:00
commit c044fb9c70
12 changed files with 943 additions and 0 deletions

0
tests/__init__.py Normal file
View File

3
tests/run_tests.sh Normal file
View File

@@ -0,0 +1,3 @@
pip install -r test_requirements.txt
pytest -x --cov=aiee --cov-fail-under=97 --cov-report term-missing tests

33
tests/test_converters.py Normal file
View File

@@ -0,0 +1,33 @@
import pytest
from cic_utils.converters import from_wei, to_wei, truncate
import decimal
@pytest.mark.parametrize("expected, decimals, value", [
(1, 6, 1_000_000),
(500, 9, 500_000_000_000)
])
def test_from_wei(value, decimals, expected):
assert expected == from_wei(value=value, decimals=decimals)
@pytest.mark.parametrize("expected, decimals, value", [
(10_000_000_000, 10, 1),
(500_000_000, 6, 500)
])
def test_to_wei(value, decimals, expected):
assert expected == to_wei(value=value, decimals=decimals)
@pytest.mark.parametrize("expected, decimals, value", [
(1.234567, 6, 1.23456789),
(1.234567, 6, 1.2345675),
(1.234567, 6, 1.2345679),
(0.1003210000, 10, 0.100321),
(1.0, 0, 1),
(3.99, 2, 3.999999999999999),
# This is a bit weird
(4.0, 2, 3.9999999999999999),
(0.0, 2, 0.000413)
])
def test_truncate(expected, decimals, value):
assert expected == truncate(value=value, decimals=decimals)