Skip to content

Commit

Permalink
wip - tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Apr 6, 2024
1 parent 0cf6c44 commit 7e7f19e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions tests/functional/builtins/codegen/test_as_wei_value.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/builtins/codegen/test_minmax_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/builtins/folding/test_epsilon.py
Original file line number Diff line number Diff line change
@@ -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"])
Expand All @@ -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)

0 comments on commit 7e7f19e

Please sign in to comment.