Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vyperlang/vyper into chor…
Browse files Browse the repository at this point in the history
…e/vy_nodes
  • Loading branch information
tserg committed May 7, 2024
2 parents 507137f + ef2d535 commit d826ba4
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 127 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ jobs:
debug: [true, false]
evm-version: [shanghai]
experimental-codegen: [false]
memorymock: [false]
evm-backend: [revm]

# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
Expand All @@ -80,22 +79,26 @@ jobs:
debug: false
opt-mode: gas
evm-version: london
evm-backend: revm

- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: paris
evm-backend: revm

# redundant rule, for clarity
- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: shanghai
evm-backend: revm

- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: cancun
evm-backend: revm

# py-evm rules
- python-version: ["3.11", "311"]
Expand All @@ -115,36 +118,30 @@ jobs:
opt-mode: gas
debug: false
evm-version: shanghai
evm-backend: revm
experimental-codegen: true
# TODO: test experimental_codegen + -Ocodesize

# run with `--memorymock`, but only need to do it one configuration
# TODO: consider removing the memorymock tests
- python-version: ["3.11", "311"]
opt-mode: gas
debug: false
evm-version: shanghai
memorymock: true

# run across other python versions. we don't really need to run all
# modes across all python versions - one is enough
- python-version: ["3.10", "310"]
opt-mode: gas
debug: false
evm-version: shanghai
evm-backend: revm

- python-version: ["3.12", "312"]
opt-mode: gas
debug: false
evm-version: shanghai
evm-backend: revm

name: "py${{ matrix.python-version[1] }}\
-opt-${{ matrix.opt-mode }}\
${{ matrix.debug && '-debug' || '' }}\
${{ matrix.memorymock && '-memorymock' || '' }}\
${{ matrix.experimental-codegen && '-experimental' || '' }}\
-${{ matrix.evm-version }}\
${{ matrix.evm-backend && format('-{0}', matrix.evm-backend) || '' }}"
-${{ matrix.evm-backend }}"

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -172,7 +169,6 @@ jobs:
--evm-version ${{ matrix.evm-version }} \
${{ matrix.evm-backend && format('--evm-backend {0}', matrix.evm-backend) || '' }} \
${{ matrix.debug && '--enable-compiler-debug-mode' || '' }} \
${{ matrix.memorymock && '--memorymock' || '' }} \
${{ matrix.experimental-codegen && '--experimental-codegen' || '' }} \
--cov-branch \
--cov-report xml:coverage.xml \
Expand Down
7 changes: 2 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from hexbytes import HexBytes

import vyper.evm.opcodes as evm_opcodes
from tests.evm_backends.base_env import BaseEnv, EvmError
from tests.evm_backends.base_env import BaseEnv, ExecutionReverted
from tests.evm_backends.pyevm_env import PyEvmEnv
from tests.evm_backends.revm_env import RevmEnv
from tests.utils import working_directory
Expand All @@ -20,9 +20,6 @@
from vyper.ir import compile_ir, optimizer
from vyper.utils import keccak256

# Import the base fixtures
pytest_plugins = ["tests.fixtures.memorymock"]

############
# PATCHING #
############
Expand Down Expand Up @@ -314,7 +311,7 @@ def assert_side_effects_invoked(side_effects_contract, side_effects_trigger, n=1
@pytest.fixture(scope="module")
def tx_failed(env):
@contextmanager
def fn(exception=EvmError, exc_text=None):
def fn(exception=ExecutionReverted, exc_text=None):
with pytest.raises(exception) as excinfo:
yield

Expand Down
11 changes: 10 additions & 1 deletion tests/evm_backends/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class BaseEnv:
It provides a common interface for deploying contracts and interacting with them.
"""

INVALID_OPCODE_ERROR = "NotImplemented" # must be implemented by subclasses
DEFAULT_CHAIN_ID = 1

def __init__(self, gas_limit: int, account_keys: list[PrivateKey]) -> None:
Expand Down Expand Up @@ -196,6 +195,16 @@ def _parse_revert(output_bytes: bytes, error: Exception, gas_used: int):

raise ExecutionReverted(f"0x{output_bytes.hex()}", gas_used) from error

@property
def invalid_opcode_error(self) -> str:
"""Expected error message when invalid opcode is executed."""
raise NotImplementedError # must be implemented by subclasses

@property
def out_of_gas_error(self) -> str:
"""Expected error message when user runs out of gas"""
raise NotImplementedError # must be implemented by subclasses


def _compile(
source_code: str,
Expand Down
3 changes: 2 additions & 1 deletion tests/evm_backends/pyevm_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
class PyEvmEnv(BaseEnv):
"""EVM backend environment using the Py-EVM library."""

INVALID_OPCODE_ERROR = "Invalid opcode"
invalid_opcode_error = "Invalid opcode"
out_of_gas_error = "Out of gas"

def __init__(
self,
Expand Down
3 changes: 2 additions & 1 deletion tests/evm_backends/revm_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


class RevmEnv(BaseEnv):
INVALID_OPCODE_ERROR = "InvalidFEOpcode"
invalid_opcode_error = "InvalidFEOpcode"
out_of_gas_error = "OutOfGas"

def __init__(
self,
Expand Down
Empty file removed tests/fixtures/__init__.py
Empty file.
51 changes: 0 additions & 51 deletions tests/fixtures/memorymock.py

This file was deleted.

17 changes: 10 additions & 7 deletions tests/functional/builtins/codegen/test_abi_decode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from eth.codecs import abi

from tests.evm_backends.base_env import EvmError, ExecutionReverted
from tests.utils import decimal_to_int
from vyper.exceptions import ArgumentException, StructureException

Expand Down Expand Up @@ -421,15 +422,17 @@ def abi_decode(x: Bytes[160]) -> uint256:


@pytest.mark.parametrize(
"output_typ1,output_typ2,input_",
"output_typ1,output_typ2,input_,error,error_property",
[
("DynArray[uint256, 3]", "uint256", b""),
("DynArray[uint256, 3]", "uint256", b"\x01" * 128),
("Bytes[5]", "address", b""),
("Bytes[5]", "address", b"\x01" * 128),
("DynArray[uint256, 3]", "uint256", b"", ExecutionReverted, ""),
("DynArray[uint256, 3]", "uint256", b"\x01" * 128, EvmError, "OUT_OF_GAS_ERROR"),
("Bytes[5]", "address", b"", ExecutionReverted, ""),
("Bytes[5]", "address", b"\x01" * 128, EvmError, "OUT_OF_GAS_ERROR"),
],
)
def test_clamper_dynamic_tuple(get_contract, tx_failed, output_typ1, output_typ2, input_):
def test_clamper_dynamic_tuple(
get_contract, tx_failed, output_typ1, output_typ2, input_, error, error_property, env
):
contract = f"""
@external
def abi_decode(x: Bytes[224]) -> ({output_typ1}, {output_typ2}):
Expand All @@ -439,7 +442,7 @@ def abi_decode(x: Bytes[224]) -> ({output_typ1}, {output_typ2}):
return a, b
"""
c = get_contract(contract)
with tx_failed():
with tx_failed(error, exc_text=getattr(env, error_property, None)):
c.abi_decode(input_)


Expand Down
2 changes: 0 additions & 2 deletions tests/functional/builtins/codegen/test_raw_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from vyper.builtins.functions import eip1167_bytecode
from vyper.exceptions import ArgumentException, StateAccessViolation, TypeMismatch

pytestmark = pytest.mark.usefixtures("memory_mocker")


def test_max_outsize_exceeds_returndatasize(get_contract):
source_code = """
Expand Down
4 changes: 0 additions & 4 deletions tests/functional/builtins/codegen/test_sha256.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import hashlib

import pytest

from vyper.utils import hex_to_int

pytestmark = pytest.mark.usefixtures("memory_mocker")


def test_sha256_string_literal(get_contract):
code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def __init__():

assert c.x() == 123
assert env.get_balance(c.address) == 0
value = to_wei(0.1, "ether")
env.set_balance(env.deployer, value)
with tx_failed():
env.message_call(c.address, value=to_wei(0.1, "ether"), data=b"") # call default function
env.message_call(c.address, value=value, data=b"") # call default function
assert env.get_balance(c.address) == 0


Expand Down Expand Up @@ -70,6 +72,7 @@ def __default__():
log Sent(msg.sender)
"""
c = get_contract(code)
env.set_balance(env.deployer, 10**17)

with tx_failed():
env.message_call(c.address, value=10**17, data=b"") # call default function
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/codegen/calling_convention/test_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from vyper import compile_code
from vyper.exceptions import TypeMismatch

pytestmark = pytest.mark.usefixtures("memory_mocker")


def test_correct_abi_right_padding(env, get_contract):
selfcall_code_6 = """
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/codegen/features/decorators/test_payable.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def baz() -> bool:
@pytest.mark.parametrize("code", nonpayable_code)
def test_nonpayable_runtime_assertion(env, keccak, tx_failed, get_contract, code):
c = get_contract(code)
env.set_balance(env.deployer, 10**18)

c.foo(value=0)
sig = keccak("foo()".encode()).hex()[:10]
Expand Down Expand Up @@ -371,6 +372,7 @@ def __default__():

c = get_contract(code)
env.message_call(c.address, value=0, data="0x12345678")
env.set_balance(env.deployer, 100)
with tx_failed():
env.message_call(c.address, value=100, data="0x12345678")

Expand All @@ -391,5 +393,6 @@ def __default__():
data = bytes([1, 2, 3, 4])
for i in range(5):
calldata = "0x" + data[:i].hex()
env.set_balance(env.deployer, 100)
with tx_failed():
env.message_call(c.address, value=100, data=calldata)
10 changes: 5 additions & 5 deletions tests/functional/codegen/features/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def foo():
assert env.last_result.gas_used < gas_sent


def test_assert_reason(env, get_contract, tx_failed, memory_mocker):
def test_assert_reason(env, get_contract, tx_failed):
code = """
err: String[32]
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_valid_assertions(get_contract, code):
get_contract(code)


def test_assert_staticcall(get_contract, env, tx_failed, memory_mocker):
def test_assert_staticcall(get_contract, env, tx_failed):
foreign_code = """
state: uint256
@external
Expand All @@ -158,7 +158,7 @@ def test(c: ForeignContract):
c2.test(c1.address)


def test_assert_in_for_loop(get_contract, tx_failed, memory_mocker):
def test_assert_in_for_loop(get_contract, tx_failed):
code = """
@external
def test(x: uint256[3]) -> bool:
Expand All @@ -178,7 +178,7 @@ def test(x: uint256[3]) -> bool:
c.test([1, 3, 5])


def test_assert_with_reason_in_for_loop(get_contract, tx_failed, memory_mocker):
def test_assert_with_reason_in_for_loop(get_contract, tx_failed):
code = """
@external
def test(x: uint256[3]) -> bool:
Expand All @@ -198,7 +198,7 @@ def test(x: uint256[3]) -> bool:
c.test([1, 3, 5])


def test_assert_reason_revert_length(env, get_contract, tx_failed, memory_mocker):
def test_assert_reason_revert_length(env, get_contract, tx_failed):
code = """
@external
def test() -> int128:
Expand Down
Loading

0 comments on commit d826ba4

Please sign in to comment.