34 lines
964 B
Python
34 lines
964 B
Python
|
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)
|