From 7e7f19ec69e363bbe3bbbd0152870fb659bb49d7 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 6 Apr 2024 22:42:45 +0000 Subject: [PATCH] wip - tests --- tests/functional/builtins/codegen/test_as_wei_value.py | 10 ++++++++-- tests/functional/builtins/codegen/test_minmax_value.py | 2 +- tests/functional/builtins/folding/test_epsilon.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/functional/builtins/codegen/test_as_wei_value.py b/tests/functional/builtins/codegen/test_as_wei_value.py index 129b04be91..00cc7d4e33 100644 --- a/tests/functional/builtins/codegen/test_as_wei_value.py +++ b/tests/functional/builtins/codegen/test_as_wei_value.py @@ -1,5 +1,7 @@ import pytest +from decimal import Decimal +from vyper.semantics.types.primitives import DecimalT from tests.utils import decimal_to_int wei_denoms = { @@ -63,9 +65,13 @@ def foo(a: decimal) -> uint256: """ c = get_contract(code) - value = decimal_to_int((2**127 - 1) / (10**multiplier)) - assert c.foo(value) == value * (10**multiplier) + # TODO: test this with values closer to decimal bounds + + denom = 10**multiplier + value = Decimal((2**127 - 1) / denom) + + assert c.foo(decimal_to_int(value)) == decimal_to_int(value * denom) @pytest.mark.parametrize("value", (-1, -(2**127))) diff --git a/tests/functional/builtins/codegen/test_minmax_value.py b/tests/functional/builtins/codegen/test_minmax_value.py index c5ee5c3584..0b0ede51ae 100644 --- a/tests/functional/builtins/codegen/test_minmax_value.py +++ b/tests/functional/builtins/codegen/test_minmax_value.py @@ -15,7 +15,7 @@ def foo() -> {typ}: """ c = get_contract(code) - lo, hi = typ.ast_bounds + lo, hi = typ.int_bounds if op == "min_value": assert c.foo() == lo elif op == "max_value": diff --git a/tests/functional/builtins/folding/test_epsilon.py b/tests/functional/builtins/folding/test_epsilon.py index 7bc2afe757..1ced828ad2 100644 --- a/tests/functional/builtins/folding/test_epsilon.py +++ b/tests/functional/builtins/folding/test_epsilon.py @@ -1,6 +1,6 @@ import pytest -from tests.utils import parse_and_fold +from tests.utils import parse_and_fold, decimal_to_int @pytest.mark.parametrize("typ_name", ["decimal"]) @@ -16,4 +16,4 @@ def foo() -> {typ_name}: old_node = vyper_ast.body[0].value new_node = old_node.get_folded_value() - assert contract.foo() == new_node.value + assert contract.foo() == decimal_to_int(new_node.value)