Skip to content

Commit

Permalink
fix a bad use of assert_compile_failed
Browse files Browse the repository at this point in the history
latest hypothesis complains with a health check about the fixture
scoping, it's better to fix the usage anyways.
  • Loading branch information
charles-cooper committed Mar 16, 2024
1 parent b7e2d2d commit 694def9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/functional/builtins/codegen/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import pytest
from hypothesis import given, settings

from vyper.compiler.settings import OptimizationLevel
from vyper.compiler import compile_code
from vyper.compiler.settings import OptimizationLevel, Settings
from vyper.exceptions import ArgumentException, TypeMismatch

_fun_bytes32_bounds = [(0, 32), (3, 29), (27, 5), (0, 5), (5, 3), (30, 2)]
Expand Down Expand Up @@ -32,6 +33,12 @@ def slice_tower_test(inp1: Bytes[50]) -> Bytes[50]:
_bytes_1024 = st.binary(min_size=0, max_size=1024)


def _fail_contract(code, opt_level, exceptions):
settings = Settings(optimize=opt_level)
with pytest.raises(exceptions):
compile_code(code, settings)


@pytest.mark.parametrize("use_literal_start", (True, False))
@pytest.mark.parametrize("use_literal_length", (True, False))
@pytest.mark.parametrize("opt_level", list(OptimizationLevel))
Expand All @@ -40,7 +47,6 @@ def slice_tower_test(inp1: Bytes[50]) -> Bytes[50]:
@pytest.mark.fuzzing
def test_slice_immutable(
get_contract,
assert_compile_failed,
tx_failed,
opt_level,
bytesdata,
Expand Down Expand Up @@ -76,7 +82,8 @@ def _get_contract():
or (use_literal_start and start > length_bound)
or (use_literal_length and length == 0)
):
assert_compile_failed(lambda: _get_contract(), ArgumentException)
_fail_contract(code, opt_level, ArgumentException)

elif start + length > len(bytesdata) or (len(bytesdata) > length_bound):
# deploy fail
with tx_failed():
Expand All @@ -95,7 +102,6 @@ def _get_contract():
@pytest.mark.fuzzing
def test_slice_bytes_fuzz(
get_contract,
assert_compile_failed,
tx_failed,
opt_level,
location,
Expand Down Expand Up @@ -173,7 +179,8 @@ def _get_contract():
)

if compile_time_oob or slice_output_too_large:
assert_compile_failed(lambda: _get_contract(), (ArgumentException, TypeMismatch))
_fail_contract(code, opt_level, (ArgumentException, TypeMismatch))

elif location == "code" and len(bytesdata) > length_bound:
# deploy fail
with tx_failed():
Expand Down

0 comments on commit 694def9

Please sign in to comment.