Skip to content

Commit

Permalink
chore: fix fuzzer test case
Browse files Browse the repository at this point in the history
for cases where `a << b` is an int256 between `max_value(int256)` and
`max_value(uint256)`, the typechecker will fail with TypeMismatch
instead of OverflowException. this fixes the test to catch the case.
note that the code was correctly failing to compile, just the test was
not catching both exception types.
  • Loading branch information
charles-cooper committed May 5, 2023
1 parent 7c3cf61 commit 0f919ef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/builtins/folding/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hypothesis import strategies as st

from vyper import ast as vy_ast
from vyper.exceptions import OverflowException
from vyper.exceptions import InvalidType, OverflowException
from vyper.semantics.analysis.utils import validate_expected_type
from vyper.semantics.types.shortcuts import INT256_T, UINT256_T
from vyper.utils import unsigned_to_signed
Expand Down Expand Up @@ -83,7 +83,8 @@ def foo(a: int256, b: uint256) -> int256:
validate_expected_type(new_node, INT256_T) # force bounds check
# compile time behavior does not match runtime behavior.
# compile-time will throw on OOB, runtime will wrap.
except OverflowException: # here: check the wrapped value matches runtime
except (InvalidType, OverflowException):
# check the wrapped value matches runtime
assert op == "<<"
assert contract.foo(a, b) == unsigned_to_signed((a << b) % (2**256), 256)
else:
Expand Down

0 comments on commit 0f919ef

Please sign in to comment.