Skip to content

Commit

Permalink
feat[test]: add more transient storage tests (#3883)
Browse files Browse the repository at this point in the history
this commit adds dedicated tests for basic operations in the transient
storage location. it mostly follows the dedicated tests for immutables
and copies them where relevant.

it also adds a `requires_evm_version` marker, which can be used in
future to test language features which should be blocked in certain EVM
versions.

---------

Co-authored-by: cyberthirst <cyberthirst.eth@gmail.com>
  • Loading branch information
tserg and cyberthirst authored Apr 4, 2024
1 parent 45a225c commit f87628c
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 18 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ testpaths = tests
xfail_strict = true
markers =
fuzzing: Run Hypothesis fuzz test suite (deselect with '-m "not fuzzing"')
requires_evm_version(version): Mark tests that require at least a specific EVM version and would throw `EvmVersionException` otherwise
venom_xfail: mark a test case as a regression (expected to fail) under the venom pipeline
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from vyper.codegen.ir_node import IRnode
from vyper.compiler.input_bundle import FilesystemInputBundle, InputBundle
from vyper.compiler.settings import OptimizationLevel, Settings, _set_debug_mode
from vyper.evm.opcodes import version_check
from vyper.exceptions import EvmVersionException
from vyper.ir import compile_ir, optimizer
from vyper.utils import ERC5202_PREFIX

Expand Down Expand Up @@ -580,3 +582,14 @@ def fn(exception=TransactionFailed, exc_text=None):
assert exc_text in str(excinfo.value), (exc_text, excinfo.value)

return fn


def pytest_runtest_call(item):
marker = item.get_closest_marker("requires_evm_version")
if marker:
assert len(marker.args) == 1
version = marker.args[0]
if not version_check(begin=version):
item.add_marker(
pytest.mark.xfail(reason="Wrong EVM version", raises=EvmVersionException)
)
14 changes: 14 additions & 0 deletions tests/functional/codegen/features/decorators/test_pure.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ def foo() -> uint256:
"""
with pytest.raises(FunctionDeclarationException):
compile_code(code)


@pytest.mark.requires_evm_version("cancun")
def test_invalid_transient_access():
code = """
x: transient(uint256)
@external
@pure
def foo() -> uint256:
return self.x
"""
with pytest.raises(StateAccessViolation):
compile_code(code)
16 changes: 16 additions & 0 deletions tests/functional/codegen/features/decorators/test_view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from vyper.exceptions import FunctionDeclarationException


Expand All @@ -15,6 +17,20 @@ def foo() -> int128:
print("Passed constant function test")


@pytest.mark.requires_evm_version("cancun")
def test_transient_test(get_contract):
code = """
x: transient(uint256)
@external
@view
def foo() -> uint256:
return self.x
"""
c = get_contract(code)
assert c.foo() == 0


def test_invalid_constant_and_payable(
get_contract_with_gas_estimation_for_constants, assert_compile_failed
):
Expand Down
Loading

0 comments on commit f87628c

Please sign in to comment.