Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Mar 19, 2024
1 parent c3f2bf6 commit 3931761
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,25 +900,29 @@ def set_lucky(arg1: address, arg2: int128):
print("Successfully executed an external contract call state change")


def test_constant_external_contract_call_cannot_change_state():
c = """
@pytest.mark.parametrize("state_modifying_decorator", ("payable", "nonpayable"))
@pytest.mark.parametrize("non_modifying_decorator", ("pure", "view"))
def test_constant_external_contract_call_cannot_change_state(
state_modifying_decorator, non_modifying_decorator
):
c = f"""
interface Foo:
def set_lucky(_lucky: int128) -> int128: nonpayable
def set_lucky(_lucky: int128) -> int128: {state_modifying_decorator}
@external
@view
@{non_modifying_decorator}
def set_lucky_stmt(arg1: address, arg2: int128):
extcall Foo(arg1).set_lucky(arg2)
"""

with pytest.raises(StateAccessViolation):
compile_code(c)

c2 = """
c2 = f"""
interface Foo:
def set_lucky(_lucky: int128) -> int128: nonpayable
def set_lucky(_lucky: int128) -> int128: {state_modifying_decorator}
@external
@view
@{non_modifying_decorator}
def set_lucky_expr(arg1: address, arg2: int128) -> int128:
return extcall Foo(arg1).set_lucky(arg2)
"""
Expand Down
31 changes: 7 additions & 24 deletions tests/functional/codegen/features/decorators/test_pure.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest

from vyper import compile_code
from vyper.exceptions import FunctionDeclarationException, StateAccessViolation


Expand Down Expand Up @@ -131,33 +134,13 @@ def foo() -> uint256:
)


def test_invalid_builtin(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
"""
def test_invalid_builtin(get_contract):
code = """
@external
@pure
def foo(x: uint256)-> bytes32:
return blockhash(x)
"""
),
StateAccessViolation,
)


def test_invalid_interface(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
"""
interface Foo:
def foo() -> uint256: payable

@external
@pure
def bar(a: address) -> uint256:
return extcall Foo(a).foo()
"""
),
StateAccessViolation,
)
with pytest.raises(StateAccessViolation):
compile_code(code)

0 comments on commit 3931761

Please sign in to comment.