diff --git a/tests/functional/builtins/codegen/test_raw_call.py b/tests/functional/builtins/codegen/test_raw_call.py index 64643da79c..051722ae4a 100644 --- a/tests/functional/builtins/codegen/test_raw_call.py +++ b/tests/functional/builtins/codegen/test_raw_call.py @@ -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): @@ -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) diff --git a/tests/functional/syntax/test_raw_call.py b/tests/functional/syntax/test_raw_call.py index c0b38d1d1e..e8074b1b84 100644 --- a/tests/functional/syntax/test_raw_call.py +++ b/tests/functional/syntax/test_raw_call.py @@ -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 = [ ( @@ -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, + ), ]