Skip to content

Commit

Permalink
Merge branch 'master' into fix/builtins-tstorage-codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Apr 4, 2024
2 parents 17aee50 + f87628c commit 4820a68
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 37 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)
)
27 changes: 27 additions & 0 deletions tests/functional/codegen/features/decorators/test_pure.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ def foo() -> uint256:
compile_code(code)


def test_type_in_pure(get_contract):
code = """
@pure
@external
def _convert(x: bytes32) -> uint256:
return convert(x, uint256)
"""
c = get_contract(code)
x = 123456
bs = x.to_bytes(32, "big")
assert x == c._convert(bs)


def test_invalid_conflicting_decorators():
code = """
@pure
Expand All @@ -185,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 4820a68

Please sign in to comment.