Skip to content

Commit

Permalink
move raw call tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 31, 2024
1 parent 31f6fff commit c1f43fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 67 deletions.
66 changes: 0 additions & 66 deletions tests/functional/builtins/codegen/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest
from hexbytes import HexBytes

from tests.utils import ZERO_ADDRESS
from vyper import compile_code
from vyper.builtins.functions import eip1167_bytecode
from vyper.exceptions import ArgumentException, StateAccessViolation, TypeMismatch


def test_max_outsize_exceeds_returndatasize(get_contract):
Expand Down Expand Up @@ -599,67 +597,3 @@ def bar(f: uint256) -> Bytes[100]:
c.bar(15).hex() == "0423a132"
"000000000000000000000000000000000000000000000000000000000000000f"
)


uncompilable_code = [
(
"""
@external
@view
def foo(_addr: address):
raw_call(_addr, method_id("foo()"))
""",
StateAccessViolation,
),
(
"""
@external
def foo(a: address):
for i: uint256 in range(
0,
extract32(raw_call(a, b"", max_outsize=32), 0, output_type=uint256),
bound = 12
):
pass
""",
StateAccessViolation,
),
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_delegate_call=True, is_static_call=True)
""",
ArgumentException,
),
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_delegate_call=True, value=1)
""",
ArgumentException,
),
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_static_call=True, value=1)
""",
ArgumentException,
),
(
"""
@external
@view
def foo(_addr: address):
raw_call(_addr, 256)
""",
TypeMismatch,
),
]


@pytest.mark.parametrize("source_code,exc", uncompilable_code)
def test_invalid_type_exception(assert_compile_failed, get_contract, source_code, exc):
assert_compile_failed(lambda: get_contract(source_code), exc)
68 changes: 67 additions & 1 deletion tests/functional/syntax/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import pytest

from vyper import compile_code
from vyper.exceptions import ArgumentException, InvalidType, SyntaxException, TypeMismatch
from vyper.exceptions import (
ArgumentException,
InvalidType,
StateAccessViolation,
SyntaxException,
TypeMismatch,
)

fail_list = [
(
Expand Down Expand Up @@ -33,6 +39,66 @@ def foo():
""",
InvalidType,
),
(
"""
@external
@view
def foo(_addr: address):
raw_call(_addr, method_id("foo()"))
""",
StateAccessViolation,
),
# non-static call cannot be used in a range expression
(
"""
@external
def foo(a: address):
for i: uint256 in range(
0,
extract32(raw_call(a, b"", max_outsize=32), 0, output_type=uint256),
bound = 12
):
pass
""",
StateAccessViolation,
),
# call cannot be both a delegate call and a static call
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_delegate_call=True, is_static_call=True)
""",
ArgumentException,
),
# value cannot be passed for delegate call
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_delegate_call=True, value=1)
""",
ArgumentException,
),
#
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_static_call=True, value=1)
""",
ArgumentException,
),
# second argument should be Bytes
(
"""
@external
@view
def foo(_addr: address):
raw_call(_addr, 256)
""",
TypeMismatch,
),
]


Expand Down

0 comments on commit c1f43fc

Please sign in to comment.