diff --git a/tests/functional/builtins/codegen/test_abi_decode.py b/tests/functional/builtins/codegen/test_abi_decode.py index d281851f8e..ab2295c8fe 100644 --- a/tests/functional/builtins/codegen/test_abi_decode.py +++ b/tests/functional/builtins/codegen/test_abi_decode.py @@ -1,9 +1,12 @@ from decimal import Decimal import pytest +from tests.utils import wrap_typ_with_storage_loc + from eth.codecs import abi from vyper.exceptions import ArgumentException, StructureException +from vyper.evm.opcodes import version_check TEST_ADDR = "0x" + b"".join(chr(i).encode("utf-8") for i in range(20)).hex() @@ -220,9 +223,13 @@ def abi_decode(x: Bytes[{len}]) -> DynArray[DynArray[DynArray[uint256, 3], 3], 3 assert c.abi_decode(encoded) == args -def test_side_effects_evaluation(get_contract): - contract_1 = """ -counter: uint256 +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_side_effects_evaluation(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + contract_1 = f""" +counter: {wrap_typ_with_storage_loc("uint256", location)} @deploy def __init__(): @@ -253,9 +260,13 @@ def foo(addr: address) -> (uint256, String[5]): assert tuple(c2.foo(c.address)) == (1, "hello") -def test_abi_decode_private_dynarray(get_contract): - code = """ -bytez: DynArray[uint256, 3] +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_abi_decode_private_dynarray(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +bytez: {wrap_typ_with_storage_loc("DynArray[uint256, 3]", location)} @internal def _foo(bs: Bytes[160]): @@ -273,9 +284,13 @@ def foo(bs: Bytes[160]) -> (uint256, DynArray[uint256, 3]): assert c.foo(encoded) == [2**256 - 1, bs] -def test_abi_decode_private_nested_dynarray(get_contract): - code = """ -bytez: DynArray[DynArray[DynArray[uint256, 3], 3], 3] +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_abi_decode_private_nested_dynarray(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +bytez: {wrap_typ_with_storage_loc("DynArray[DynArray[DynArray[uint256, 3], 3], 3]", location)} @internal def _foo(bs: Bytes[1696]): diff --git a/tests/functional/builtins/codegen/test_abi_encode.py b/tests/functional/builtins/codegen/test_abi_encode.py index f014c47a19..70ea7fe88c 100644 --- a/tests/functional/builtins/codegen/test_abi_encode.py +++ b/tests/functional/builtins/codegen/test_abi_encode.py @@ -3,6 +3,9 @@ import pytest from eth.codecs import abi +from tests.utils import wrap_typ_with_storage_loc + +from vyper.evm.opcodes import version_check # @pytest.mark.parametrize("string", ["a", "abc", "abcde", "potato"]) def test_abi_encode(get_contract): @@ -259,9 +262,13 @@ def abi_encode( ) -def test_side_effects_evaluation(get_contract): - contract_1 = """ -counter: uint256 +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_side_effects_evaluation(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + contract_1 = f""" +counter: {wrap_typ_with_storage_loc("uint256", location)} @deploy def __init__(): @@ -295,9 +302,13 @@ def foo(addr: address) -> Bytes[164]: # test _abi_encode in private functions to check buffer overruns -def test_abi_encode_private(get_contract): - code = """ -bytez: Bytes[96] +@pytest.mark.parametrize("location", ["storage", "transient"]) +def test_abi_encode_private(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +bytez: {wrap_typ_with_storage_loc("Bytes[96]", location)} @internal def _foo(bs: Bytes[32]): self.bytez = _abi_encode(bs) @@ -313,9 +324,13 @@ def foo(bs: Bytes[32]) -> (uint256, Bytes[96]): assert c.foo(bs) == [2**256 - 1, abi.encode("(bytes)", (bs,))] -def test_abi_encode_private_dynarray(get_contract): - code = """ -bytez: Bytes[160] +@pytest.mark.parametrize("location", ["storage", "transient"]) +def test_abi_encode_private_dynarray(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +bytez: {wrap_typ_with_storage_loc("Bytes[160]", location)} @internal def _foo(bs: DynArray[uint256, 3]): self.bytez = _abi_encode(bs) @@ -330,9 +345,13 @@ def foo(bs: DynArray[uint256, 3]) -> (uint256, Bytes[160]): assert c.foo(bs) == [2**256 - 1, abi.encode("(uint256[])", (bs,))] -def test_abi_encode_private_nested_dynarray(get_contract): - code = """ -bytez: Bytes[1696] +@pytest.mark.parametrize("location", ["storage", "transient"]) +def test_abi_encode_private_nested_dynarray(get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +bytez: {wrap_typ_with_storage_loc("Bytes[1696]", location)} @internal def _foo(bs: DynArray[DynArray[DynArray[uint256, 3], 3], 3]): self.bytez = _abi_encode(bs) diff --git a/tests/functional/builtins/codegen/test_addmod.py b/tests/functional/builtins/codegen/test_addmod.py index 10fe4bfc54..9a9acaad0c 100644 --- a/tests/functional/builtins/codegen/test_addmod.py +++ b/tests/functional/builtins/codegen/test_addmod.py @@ -1,3 +1,9 @@ +import pytest + +from tests.utils import wrap_typ_with_storage_loc + +from vyper.evm.opcodes import version_check + def test_uint256_addmod(tx_failed, get_contract_with_gas_estimation): uint256_code = """ @external @@ -58,9 +64,13 @@ def c() -> uint256: assert c.foo() == 2 -def test_uint256_addmod_evaluation_order(get_contract_with_gas_estimation): - code = """ -a: uint256 +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_uint256_addmod_evaluation_order(get_contract_with_gas_estimation, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +a: {wrap_typ_with_storage_loc("uint256", location)} @external def foo1() -> uint256: diff --git a/tests/functional/builtins/codegen/test_ceil.py b/tests/functional/builtins/codegen/test_ceil.py index a5b5cbc561..046fb28695 100644 --- a/tests/functional/builtins/codegen/test_ceil.py +++ b/tests/functional/builtins/codegen/test_ceil.py @@ -1,17 +1,23 @@ import math from decimal import Decimal +import pytest +from tests.utils import wrap_typ_with_storage_loc -def test_ceil(get_contract_with_gas_estimation): - code = """ -x: decimal +from vyper.evm.opcodes import version_check -@deploy -def __init__(): - self.x = 504.0000000001 + +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_ceil(get_contract_with_gas_estimation, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + code = f""" +x: {wrap_typ_with_storage_loc("decimal", location)} @external def x_ceil() -> int256: + self.x = 504.0000000001 return ceil(self.x) @external @@ -49,16 +55,17 @@ def fou() -> int256: # ceil(x) should yield the smallest integer greater than or equal to x -def test_ceil_negative(get_contract_with_gas_estimation): - code = """ -x: decimal +@pytest.mark.parametrize("location", ["storage", "transient"]) +def test_ceil_negative(get_contract_with_gas_estimation, get_contract, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") -@deploy -def __init__(): - self.x = -504.0000000001 + code = f""" +x: {wrap_typ_with_storage_loc("decimal", location)} @external def x_ceil() -> int256: + self.x = -504.0000000001 return ceil(self.x) @external diff --git a/tests/functional/builtins/codegen/test_concat.py b/tests/functional/builtins/codegen/test_concat.py index 37bdaaaf7b..525ffd5946 100644 --- a/tests/functional/builtins/codegen/test_concat.py +++ b/tests/functional/builtins/codegen/test_concat.py @@ -1,3 +1,10 @@ +import pytest + +from tests.utils import wrap_typ_with_storage_loc + +from vyper.evm.opcodes import version_check + + def test_concat(get_contract_with_gas_estimation): test_concat = """ @external @@ -21,7 +28,6 @@ def foo3(input1: Bytes[50], input2: Bytes[50], input3: Bytes[50]) -> Bytes[1000] c.foo3(b"horses" * 4, b"mice" * 7, b"crows" * 10) == b"horses" * 4 + b"mice" * 7 + b"crows" * 10 ) # noqa: E501 - print("Passed simple concat test") def test_concat2(get_contract_with_gas_estimation): @@ -34,12 +40,15 @@ def foo(inp: Bytes[50]) -> Bytes[1000]: c = get_contract_with_gas_estimation(test_concat2) assert c.foo(b"horse" * 9 + b"vyper") == (b"horse" * 9 + b"vyper") * 10 - print("Passed second concat test") -def test_crazy_concat_code(get_contract_with_gas_estimation): - crazy_concat_code = """ -y: Bytes[10] +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_crazy_concat_code(get_contract_with_gas_estimation, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + + crazy_concat_code = f""" +y: {wrap_typ_with_storage_loc("Bytes[10]", location)} @external def krazykonkat(z: Bytes[10]) -> Bytes[25]: @@ -52,8 +61,6 @@ def krazykonkat(z: Bytes[10]) -> Bytes[25]: assert c.krazykonkat(b"moose") == b"cow horse moose" - print("Passed third concat test") - def test_concat_buffer(get_contract): # GHSA-2q8v-3gqq-4f8p @@ -92,15 +99,19 @@ def foo() -> int256: assert c.foo() == -1 -def test_concat_buffer3(get_contract): +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_concat_buffer3(get_contract, location): # GHSA-2q8v-3gqq-4f8p - code = """ -s: String[1] -s2: String[33] -s3: String[34] + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") -@deploy -def __init__(): + code = f""" +s: {wrap_typ_with_storage_loc("String[1]", location)} +s2: {wrap_typ_with_storage_loc("String[33]", location)} +s3: {wrap_typ_with_storage_loc("String[34]", location)} + +@internal +def init_test(): self.s = "a" self.s2 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # 33*'a' @@ -111,6 +122,7 @@ def bar() -> uint256: @external def foo() -> int256: + self.init_test() i: int256 = -1 b: uint256 = self.bar() return i @@ -140,12 +152,14 @@ def fivetimes(inp: bytes32) -> Bytes[160]: assert c.sandwich(b"\x57" * 97, b"\x57" * 32) == b"\x57" * 161 assert c.fivetimes(b"mongoose" * 4) == b"mongoose" * 20 - print("Passed concat bytes32 test") +@pytest.mark.parametrize('location', ["storage", "transient"]) +def test_konkat_code(get_contract_with_gas_estimation, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") -def test_konkat_code(get_contract_with_gas_estimation): - konkat_code = """ -ecks: bytes32 + konkat_code = f""" +ecks: {wrap_typ_with_storage_loc("bytes32", location)} @external def foo(x: bytes32, y: bytes32) -> Bytes[64]: @@ -167,8 +181,6 @@ def hoo(x: bytes32, y: bytes32) -> Bytes[64]: assert c.goo(b"\x35" * 32, b"\x00" * 32) == b"\x35" * 32 + b"\x00" * 32 assert c.hoo(b"\x35" * 32, b"\x00" * 32) == b"\x35" * 32 + b"\x00" * 32 - print("Passed second concat tests") - def test_small_output(get_contract_with_gas_estimation): code = """ diff --git a/tests/functional/builtins/codegen/test_convert.py b/tests/functional/builtins/codegen/test_convert.py index ad1a616300..555332f426 100644 --- a/tests/functional/builtins/codegen/test_convert.py +++ b/tests/functional/builtins/codegen/test_convert.py @@ -8,6 +8,8 @@ import eth.codecs.abi.exceptions import pytest +from tests.utils import wrap_typ_with_storage_loc + from vyper.compiler import compile_code from vyper.exceptions import InvalidLiteral, InvalidType, TypeMismatch from vyper.semantics.types import AddressT, BoolT, BytesM_T, BytesT, DecimalT, IntegerT, StringT @@ -20,6 +22,7 @@ round_towards_zero, unsigned_to_signed, ) +from vyper.evm.opcodes import version_check BASE_TYPES = set(IntegerT.all()) | set(BytesM_T.all()) | {DecimalT(), AddressT(), BoolT()} @@ -420,10 +423,14 @@ def _vyper_literal(val, typ): @pytest.mark.parametrize("i_typ,o_typ,val", generate_passing_cases()) +@pytest.mark.parametrize("location", ["storage", "transient"]) @pytest.mark.fuzzing def test_convert_passing( - get_contract_with_gas_estimation, assert_compile_failed, i_typ, o_typ, val + get_contract_with_gas_estimation, assert_compile_failed, i_typ, o_typ, location, val ): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + expected_val = _py_convert(val, i_typ, o_typ) if isinstance(o_typ, AddressT) and expected_val == "0x" + "00" * 20: # web3 has special formatter for zero address @@ -463,16 +470,16 @@ def test_input_convert(x: {i_typ}) -> {o_typ}: assert c2.test_input_convert(val) == expected_val contract_3 = f""" -bar: {i_typ} +bar: {wrap_typ_with_storage_loc(i_typ, location)} @external -def test_state_variable_convert() -> {o_typ}: +def test_storage_variable_convert() -> {o_typ}: self.bar = {_vyper_literal(val, i_typ)} return convert(self.bar, {o_typ}) """ c3 = get_contract_with_gas_estimation(contract_3) - assert c3.test_state_variable_convert() == expected_val + assert c3.test_storage_variable_convert() == expected_val contract_4 = f""" @external @@ -633,7 +640,11 @@ def foo() -> {typ}: @pytest.mark.parametrize("n", range(1, 33)) -def test_Bytes_to_bytes(get_contract, n): +@pytest.mark.parametrize("location", ["storage", "transient"]) +def test_Bytes_to_bytes(get_contract, n, location): + if location == "transient" and not version_check(begin="cancun"): + pytest.skip("Skipping test as storage_location is 'transient' and EVM version is pre-Cancun") + t_bytes = f"bytes{n}" t_Bytes = f"Bytes[{n}]" @@ -649,7 +660,7 @@ def foo() -> {t_bytes}: assert c1.foo() == test_data code2 = f""" -bar: {t_Bytes} +bar: {wrap_typ_with_storage_loc(t_Bytes, location)} @external def foo() -> {t_bytes}: self.bar = {test_data}