diff --git a/tests/functional/builtins/codegen/test_as_wei_value.py b/tests/functional/builtins/codegen/test_as_wei_value.py index 00cc7d4e33..7910d8ac5d 100644 --- a/tests/functional/builtins/codegen/test_as_wei_value.py +++ b/tests/functional/builtins/codegen/test_as_wei_value.py @@ -1,8 +1,7 @@ import pytest -from decimal import Decimal -from vyper.semantics.types.primitives import DecimalT from tests.utils import decimal_to_int +from vyper.semantics.types.primitives import DecimalT wei_denoms = { "femtoether": 3, @@ -71,7 +70,7 @@ def foo(a: decimal) -> uint256: denom = 10**multiplier value = Decimal((2**127 - 1) / denom) - assert c.foo(decimal_to_int(value)) == decimal_to_int(value * denom) + assert c.foo(decimal_to_int(value)) == int(value * denom) @pytest.mark.parametrize("value", (-1, -(2**127))) diff --git a/tests/functional/codegen/types/numbers/test_constants.py b/tests/functional/codegen/types/numbers/test_constants.py index af871983ab..8ad2b559de 100644 --- a/tests/functional/codegen/types/numbers/test_constants.py +++ b/tests/functional/codegen/types/numbers/test_constants.py @@ -1,8 +1,8 @@ import itertools -from decimal import Decimal import pytest +from tests.utils import decimal_to_int from vyper.compiler import compile_code from vyper.exceptions import TypeMismatch from vyper.utils import MemoryPositions @@ -59,15 +59,13 @@ def test_arithmetic(a: int128) -> int128: assert c.test_int128(-(2**127)) == [False, True] assert c.test_int128(0) == [False, False] - assert c.test_decimal(Decimal("18707220957835557353007165858768422651595.9365500927")) == [ - True, - False, - ] - assert c.test_decimal(Decimal("-18707220957835557353007165858768422651595.9365500928")) == [ - False, - True, - ] - assert c.test_decimal(Decimal("0.1")) == [False, False] + assert c.test_decimal( + decimal_to_int("18707220957835557353007165858768422651595.9365500927") + ) == [True, False] + assert c.test_decimal( + decimal_to_int("-18707220957835557353007165858768422651595.9365500928") + ) == [False, True] + assert c.test_decimal(decimal_to_int("0.1")) == [False, False] assert c.test_uint256(2**256 - 1) is True @@ -121,8 +119,8 @@ def zoo() -> uint256: assert c.joo() is None - assert c.koo() == Decimal(2**167 - 1) / 10**10 - assert c.loo() == Decimal(-(2**167)) / 10**10 + assert c.koo() == (2**167 - 1) + assert c.loo() == -(2**167) assert c.zoo() == 2**256 - 1 diff --git a/tests/functional/codegen/types/numbers/test_decimals.py b/tests/functional/codegen/types/numbers/test_decimals.py index fe03df78a8..e66d2f001f 100644 --- a/tests/functional/codegen/types/numbers/test_decimals.py +++ b/tests/functional/codegen/types/numbers/test_decimals.py @@ -156,7 +156,7 @@ def iarg() -> uint256: assert c.arg(decimal_to_int("3.7")) == decimal_to_int("3.7") assert c.garg() == decimal_to_int("6.75") assert c.harg() == decimal_to_int("9.0") - assert c.iarg() == decimal_to_int("14") + assert c.iarg() == 14 print("Passed fractional multiplication test") @@ -182,14 +182,18 @@ def _num_mul(x: decimal, y: decimal) -> decimal: y = 1 + DECIMAL_EPSILON with tx_failed(): - c._num_mul(x, y) + c._num_mul(decimal_to_int(x), decimal_to_int(y)) - assert c._num_mul(x, decimal_to_int(1)) == x + assert c._num_mul(decimal_to_int(x), decimal_to_int(1)) == decimal_to_int(x) - assert c._num_mul(x, 1 - DECIMAL_EPSILON) == quantize(x * (1 - DECIMAL_EPSILON)) + assert c._num_mul(decimal_to_int(x), decimal_to_int(1 - DECIMAL_EPSILON)) == decimal_to_int( + quantize(x * (1 - DECIMAL_EPSILON)) + ) x = SizeLimits.MIN_AST_DECIMAL - assert c._num_mul(x, 1 - DECIMAL_EPSILON) == quantize(x * (1 - DECIMAL_EPSILON)) + assert c._num_mul(decimal_to_int(x), decimal_to_int(1 - DECIMAL_EPSILON)) == decimal_to_int( + quantize(x * (1 - DECIMAL_EPSILON)) + ) # division failure modes(!) @@ -206,35 +210,39 @@ def foo(x: decimal, y: decimal) -> decimal: y = -DECIMAL_EPSILON with tx_failed(): - c.foo(x, y) + c.foo(decimal_to_int(x), decimal_to_int(y)) with tx_failed(): - c.foo(x, decimal_to_int(0)) + c.foo(decimal_to_int(x), 0) with tx_failed(): - c.foo(y, decimal_to_int(0)) + c.foo(decimal_to_int(y), 0) - y = decimal_to_int(1) - DECIMAL_EPSILON # 0.999999999 + y = 1 - DECIMAL_EPSILON # 0.999999999 with tx_failed(): - c.foo(x, y) + c.foo(decimal_to_int(x), decimal_to_int(y)) - y = decimal_to_int(-1) + y = -1 with tx_failed(): - c.foo(x, y) + c.foo(decimal_to_int(x), decimal_to_int(y)) - assert c.foo(x, decimal_to_int(1)) == x - assert c.foo(x, 1 + DECIMAL_EPSILON) == quantize(x / (1 + DECIMAL_EPSILON)) + assert c.foo(decimal_to_int(x), decimal_to_int(1)) == decimal_to_int(x) + assert c.foo(decimal_to_int(x), decimal_to_int(1 + DECIMAL_EPSILON)) == decimal_to_int( + quantize(x / (1 + DECIMAL_EPSILON)) + ) x = SizeLimits.MAX_AST_DECIMAL with tx_failed(): - c.foo(x, DECIMAL_EPSILON) + c.foo(decimal_to_int(x), decimal_to_int(DECIMAL_EPSILON)) - y = decimal_to_int(1) - DECIMAL_EPSILON + y = 1 - DECIMAL_EPSILON with tx_failed(): - c.foo(x, y) + c.foo(decimal_to_int(x), decimal_to_int(y)) - assert c.foo(x, decimal_to_int(1)) == x + assert c.foo(decimal_to_int(x), decimal_to_int(1)) == decimal_to_int(x) - assert c.foo(x, 1 + DECIMAL_EPSILON) == quantize(x / (1 + DECIMAL_EPSILON)) + assert c.foo(decimal_to_int(x), decimal_to_int(1 + DECIMAL_EPSILON)) == decimal_to_int( + quantize(x / (1 + DECIMAL_EPSILON)) + ) def test_decimal_min_max_literals(tx_failed, get_contract_with_gas_estimation): diff --git a/tests/functional/codegen/types/numbers/test_modulo.py b/tests/functional/codegen/types/numbers/test_modulo.py index 465426cd1d..3b204e8121 100644 --- a/tests/functional/codegen/types/numbers/test_modulo.py +++ b/tests/functional/codegen/types/numbers/test_modulo.py @@ -1,7 +1,6 @@ -from decimal import Decimal - import pytest +from tests.utils import decimal_to_int from vyper.exceptions import ZeroDivisionException @@ -26,9 +25,9 @@ def num_modulo_decimal() -> decimal: """ c = get_contract_with_gas_estimation(code) assert c.num_modulo_num() == 1 - assert c.decimal_modulo_decimal() == Decimal(".18") - assert c.decimal_modulo_num() == Decimal(".5") - assert c.num_modulo_decimal() == Decimal(".5") + assert c.decimal_modulo_decimal() == decimal_to_int(".18") + assert c.decimal_modulo_num() == decimal_to_int(".5") + assert c.num_modulo_decimal() == decimal_to_int(".5") def test_modulo_with_input_of_zero(tx_failed, get_contract_with_gas_estimation): @@ -39,7 +38,7 @@ def foo(a: decimal, b: decimal) -> decimal: """ c = get_contract_with_gas_estimation(code) with tx_failed(): - c.foo(Decimal("1"), Decimal("0")) + c.foo(decimal_to_int("1"), decimal_to_int("0")) def test_literals_vs_evm(get_contract): diff --git a/tests/functional/codegen/types/test_dynamic_array.py b/tests/functional/codegen/types/test_dynamic_array.py index efa2799480..63d3d0b8f1 100644 --- a/tests/functional/codegen/types/test_dynamic_array.py +++ b/tests/functional/codegen/types/test_dynamic_array.py @@ -2,6 +2,7 @@ import pytest +from tests.utils import decimal_to_int from vyper.compiler import compile_code from vyper.exceptions import ( ArgumentException, @@ -220,7 +221,10 @@ def uoo(inp: DynArray[Foobar, 2]) -> DynArray[DynArray[Foobar, 2], 2]: assert c.poo([]) == [] assert c.poo([[1, 2], [3, 4]]) == [[1, 2], [3, 4]] assert c.qoo([1, 2]) == [[1, 2], [3, 4]] - assert c.roo([1, 2]) == [[1.0, 2.0], [3.0, 4.0]] + assert c.roo([decimal_to_int(1), decimal_to_int(2)]) == [ + [decimal_to_int(1), decimal_to_int(2)], + [decimal_to_int(3), decimal_to_int(4)], + ] assert c.soo() == [1, 2] assert c.too() == [2, 1] assert c.uoo([1, 2]) == [[1, 2], [2, 1]] @@ -729,9 +733,15 @@ def test_array_decimal_return3() -> DynArray[DynArray[decimal, 2], 2]: c = get_contract_with_gas_estimation(code) assert c.test_array_num_return() == [[], [3, 4]] - assert c.test_array_decimal_return1() == [[1.0], [3.0, 4.0]] - assert c.test_array_decimal_return2() == [[1.0, 2.0]] - assert c.test_array_decimal_return3() == [[1.0, 2.0], [3.0]] + assert c.test_array_decimal_return1() == [ + [decimal_to_int(1)], + [decimal_to_int(3), decimal_to_int(4)], + ] + assert c.test_array_decimal_return2() == [[decimal_to_int(1), decimal_to_int(2)]] + assert c.test_array_decimal_return3() == [ + [decimal_to_int(1), decimal_to_int(2)], + [decimal_to_int(3)], + ] @pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression") @@ -1660,7 +1670,7 @@ def ix(i: uint256) -> decimal: """ c = get_contract(code) for i, p in enumerate(some_good_primes): - assert c.ix(i) == p + assert c.ix(i) == decimal_to_int(p) # assert oob with tx_failed(): c.ix(len(some_good_primes) + 1) diff --git a/tests/functional/codegen/types/test_lists.py b/tests/functional/codegen/types/test_lists.py index d6a4665e51..7fa727bb6e 100644 --- a/tests/functional/codegen/types/test_lists.py +++ b/tests/functional/codegen/types/test_lists.py @@ -2,8 +2,8 @@ import pytest -from vyper.exceptions import ArrayIndexException, OverflowException, TypeMismatch from tests.utils import decimal_to_int +from vyper.exceptions import ArrayIndexException, OverflowException, TypeMismatch def _map_nested(f, xs): @@ -129,8 +129,9 @@ def roo(inp: decimal[2]) -> decimal[2][2]: assert c.noo([3, 5]) == [3, 5] assert c.poo([[1, 2], [3, 4]]) == [[1, 2], [3, 4]] assert c.qoo([1, 2]) == [[1, 2], [3, 4]] - assert c.roo(_map_nested(decimal_to_int, [1.0, 2.0])) == _map_nested(decimal_to_int, [[1.0, 2.0], [3.0, 4.0]]) - + assert c.roo(_map_nested(decimal_to_int, [1.0, 2.0])) == _map_nested( + decimal_to_int, [[1.0, 2.0], [3.0, 4.0]] + ) def test_array_accessor(get_contract_with_gas_estimation): @@ -335,7 +336,7 @@ def test_array_decimal_return3() -> decimal[2][2]: c = get_contract_with_gas_estimation(code) assert c.test_array_num_return() == [[1, 2], [3, 4]] - assert c.test_array_decimal_return1() == _map_nested(decimal_to_int,[[1.0, 2.0], [3.0, 4.0]]) + assert c.test_array_decimal_return1() == _map_nested(decimal_to_int, [[1.0, 2.0], [3.0, 4.0]]) assert c.test_array_decimal_return2() == _map_nested(decimal_to_int, [[1.0, 2.0], [3.0, 4.0]]) assert c.test_array_decimal_return3() == _map_nested(decimal_to_int, [[1.0, 2.0], [3.0, 4.0]])