Skip to content

Commit

Permalink
refactor(tests): unify EOF return code constants (ethereum#834)
Browse files Browse the repository at this point in the history
For EOF create and EXTCALL tests use the same return code constants for
success, failure, and revert values.

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Sep 26, 2024
1 parent f41fb29 commit 22c734a
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 69 deletions.
6 changes: 3 additions & 3 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
EOF V1 Constants used throughout all tests
"""

CALL_FAILURE = 0
CALL_SUCCESS = 1
LEGACY_CALL_FAILURE = 0
LEGACY_CALL_SUCCESS = 1
EXTCALL_SUCCESS = 0
EXTCALL_REVERT = 1
EXTCALL_FAILED = 2
EXTCALL_FAILURE = 2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from .. import EOF_FORK_NAME
from .helpers import value_exceptional_abort_canary
from .spec import CALL_SUCCESS, EXTCALL_REVERT, EXTCALL_SUCCESS
from .spec import EXTCALL_REVERT, EXTCALL_SUCCESS, LEGACY_CALL_SUCCESS

REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7069.md"
REFERENCE_SPEC_VERSION = "1795943aeacc86131d5ab6bb3d65824b3b1d4cad"
Expand Down Expand Up @@ -160,16 +160,16 @@ def test_address_space_extension(
caller_storage[slot_target_returndata] = 0
else:
caller_storage[slot_target_call_status] = (
EXTCALL_SUCCESS if ase_ready_opcode else CALL_SUCCESS
EXTCALL_SUCCESS if ase_ready_opcode else LEGACY_CALL_SUCCESS
)
case "LegacyContract" | "EOFContract":
match target_opcode:
case Op.CALL | Op.STATICCALL:
caller_storage[slot_target_call_status] = CALL_SUCCESS
caller_storage[slot_target_call_status] = LEGACY_CALL_SUCCESS
# CALL and STATICCALL call will call the stripped address
caller_storage[slot_target_returndata] = stripped_address
case Op.CALLCODE | Op.DELEGATECALL:
caller_storage[slot_target_call_status] = CALL_SUCCESS
caller_storage[slot_target_call_status] = LEGACY_CALL_SUCCESS
# CALLCODE and DELEGATECALL call will call the stripped address
# but will change the sender to self
caller_storage[slot_target_returndata] = address_caller
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_address_space_extension(
storage={
slot_top_level_call_status: EXTCALL_SUCCESS
if ase_ready_opcode and ase_address
else CALL_SUCCESS
else LEGACY_CALL_SUCCESS
}
),
address_caller: Account(storage=caller_storage),
Expand Down
10 changes: 5 additions & 5 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/test_calldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
value_code_worked,
value_exceptional_abort_canary,
)
from .spec import CALL_FAILURE, CALL_SUCCESS, EXTCALL_FAILED, EXTCALL_SUCCESS
from .spec import EXTCALL_FAILURE, EXTCALL_SUCCESS, LEGACY_CALL_FAILURE, LEGACY_CALL_SUCCESS

REFERENCE_SPEC_GIT_PATH = REFERENCE_SPEC_GIT_PATH
REFERENCE_SPEC_VERSION = REFERENCE_SPEC_VERSION
Expand Down Expand Up @@ -381,7 +381,7 @@ def test_calldata_remains_after_subcall(
case Op.STATICCALL:
called_storage = {
slot_code_worked: value_code_worked,
slot_call_status: CALL_FAILURE,
slot_call_status: LEGACY_CALL_FAILURE,
slot_calldata_1: value_calldata_1,
}
sub_called_storage = {
Expand All @@ -391,7 +391,7 @@ def test_calldata_remains_after_subcall(
called_storage = {
slot_code_worked: value_code_worked,
slot_delegate_code_worked: value_code_worked,
slot_call_status: CALL_SUCCESS,
slot_call_status: LEGACY_CALL_SUCCESS,
slot_calldata_1: value_calldata_1,
}
sub_called_storage = {
Expand All @@ -400,7 +400,7 @@ def test_calldata_remains_after_subcall(
case Op.CALL:
called_storage = {
slot_code_worked: value_code_worked,
slot_call_status: CALL_SUCCESS,
slot_call_status: LEGACY_CALL_SUCCESS,
slot_calldata_1: value_calldata_1,
}
sub_called_storage = {
Expand All @@ -409,7 +409,7 @@ def test_calldata_remains_after_subcall(
case Op.EXTSTATICCALL:
called_storage = {
slot_code_worked: value_code_worked,
slot_call_status: EXTCALL_FAILED,
slot_call_status: EXTCALL_FAILURE,
slot_calldata_1: value_calldata_1,
}
sub_called_storage = {
Expand Down
46 changes: 24 additions & 22 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from ethereum_test_tools.vm.opcode import Opcodes as Op

from .. import EOF_FORK_NAME
from .spec import (
EXTCALL_FAILURE,
EXTCALL_REVERT,
EXTCALL_SUCCESS,
LEGACY_CALL_FAILURE,
LEGACY_CALL_SUCCESS,
)

pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-3540.md"
Expand All @@ -37,11 +44,6 @@

"""Storage values for common testing fields"""
value_code_worked = 0x2015
value_legacy_call_worked = 1
value_legacy_call_failed = 0
value_eof_call_worked = 0
value_eof_call_reverted = 1
value_eof_call_failed = 2
value_returndata_magic = b"\x42"


Expand Down Expand Up @@ -97,7 +99,7 @@ def test_legacy_calls_eof_sstore(
calling_storage = Storage(
{
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_legacy_call_worked, # type: ignore
slot_call_result: LEGACY_CALL_SUCCESS, # type: ignore
}
)
destination_storage = Storage()
Expand All @@ -109,7 +111,7 @@ def test_legacy_calls_eof_sstore(
elif opcode == Op.CALLCODE:
calling_storage[slot_caller] = calling_contract_address
elif opcode == Op.STATICCALL:
calling_storage[slot_call_result] = value_legacy_call_failed
calling_storage[slot_call_result] = LEGACY_CALL_FAILURE

post = {
calling_contract_address: Account(storage=calling_storage),
Expand Down Expand Up @@ -169,7 +171,7 @@ def test_legacy_calls_eof_mstore(

calling_storage = {
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_legacy_call_worked, # type: ignore
slot_call_result: LEGACY_CALL_SUCCESS, # type: ignore
slot_returndatasize: len(value_returndata_magic), # type: ignore
slot_returndata: value_returndata_magic, # type: ignore
}
Expand Down Expand Up @@ -226,7 +228,7 @@ def test_eof_calls_eof_sstore(
calling_storage = Storage(
{
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_eof_call_worked, # type: ignore
slot_call_result: EXTCALL_SUCCESS, # type: ignore
}
)
destination_storage = Storage()
Expand All @@ -236,7 +238,7 @@ def test_eof_calls_eof_sstore(
elif opcode == Op.EXTDELEGATECALL:
calling_storage[slot_caller] = sender
elif opcode == Op.EXTSTATICCALL:
calling_storage[slot_call_result] = value_eof_call_failed
calling_storage[slot_call_result] = EXTCALL_FAILURE

post = {
calling_contract_address: Account(storage=calling_storage),
Expand Down Expand Up @@ -299,7 +301,7 @@ def test_eof_calls_eof_mstore(

calling_storage = {
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_eof_call_worked, # type: ignore
slot_call_result: EXTCALL_SUCCESS, # type: ignore
slot_returndatasize: 0x20, # type: ignore
slot_returndata: value_returndata_magic
+ b"\0" * (0x20 - len(value_returndata_magic)), # type: ignore
Expand Down Expand Up @@ -357,17 +359,17 @@ def test_eof_calls_legacy_sstore(

calling_storage = {
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_eof_call_worked, # type: ignore
slot_call_result: EXTCALL_SUCCESS, # type: ignore
}
destination_storage = {}

if opcode == Op.EXTCALL:
destination_storage[slot_caller] = calling_contract_address
elif opcode == Op.EXTDELEGATECALL:
# EOF delegate call to legacy is a light failure by rule
calling_storage[slot_call_result] = value_eof_call_reverted
calling_storage[slot_call_result] = EXTCALL_REVERT
elif opcode == Op.EXTSTATICCALL:
calling_storage[slot_call_result] = value_eof_call_failed
calling_storage[slot_call_result] = EXTCALL_FAILURE

post = {
calling_contract_address: Account(storage=calling_storage),
Expand Down Expand Up @@ -425,15 +427,15 @@ def test_eof_calls_legacy_mstore(

calling_storage = {
slot_code_worked: value_code_worked, # type: ignore
slot_call_result: value_eof_call_worked, # type: ignore
slot_call_result: EXTCALL_SUCCESS, # type: ignore
slot_returndatasize: 0x20, # type: ignore
slot_returndata: value_returndata_magic
+ b"\0" * (0x20 - len(value_returndata_magic)), # type: ignore
}

if opcode == Op.EXTDELEGATECALL:
# EOF delegate call to legacy is a light failure by rule
calling_storage[slot_call_result] = value_eof_call_reverted
calling_storage[slot_call_result] = EXTCALL_REVERT
calling_storage[slot_returndatasize] = 0
calling_storage[slot_returndata] = 0

Expand Down Expand Up @@ -496,10 +498,10 @@ def test_eof_calls_revert_abort(

calling_storage = {
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_reverted
slot_call_result: EXTCALL_REVERT
if destination_opcode == Op.REVERT
or (opcode == Op.EXTDELEGATECALL and not destination_is_eof)
else value_eof_call_failed,
else EXTCALL_FAILURE,
}

post = {
Expand Down Expand Up @@ -702,7 +704,7 @@ def test_eof_calls_static_flag_with_value(

calling_storage = {
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_failed,
slot_call_result: EXTCALL_FAILURE,
}

post = {
Expand Down Expand Up @@ -768,7 +770,7 @@ def test_eof_calls_min_callee_gas(
calling_contract_address = pre.deploy_contract(
Container.Code(
Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.EQ(opcode(address=noop_callee_address, value=value), value_eof_call_reverted)
+ Op.EQ(opcode(address=noop_callee_address, value=value), EXTCALL_REVERT)
# If the return code isn't 1, it means gas was enough to cover the allowances.
+ Op.RJUMPI[len(revert_block)]
+ revert_block
Expand Down Expand Up @@ -847,7 +849,7 @@ def test_eof_calls_with_value(

calling_storage = {
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_reverted if balance < value else value_eof_call_worked,
slot_call_result: EXTCALL_REVERT if balance < value else EXTCALL_SUCCESS,
}

post = {
Expand Down Expand Up @@ -945,7 +947,7 @@ def test_eof_calls_msg_depth(
calling_storage = {
slot_max_depth: 1024,
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_reverted,
slot_call_result: EXTCALL_REVERT,
}

post = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
value_code_worked,
value_exceptional_abort_canary,
)
from .spec import CALL_FAILURE, CALL_SUCCESS, EXTCALL_FAILED, EXTCALL_SUCCESS
from .spec import EXTCALL_FAILURE, EXTCALL_SUCCESS, LEGACY_CALL_FAILURE, LEGACY_CALL_SUCCESS

REFERENCE_SPEC_GIT_PATH = REFERENCE_SPEC_GIT_PATH
REFERENCE_SPEC_VERSION = REFERENCE_SPEC_VERSION
Expand Down Expand Up @@ -346,18 +346,18 @@ def test_returndatacopy_oob(
post = {
address_entry_point: Account(
storage={
slot_eof_target_call_status: CALL_SUCCESS,
slot_eof_target_call_status: LEGACY_CALL_SUCCESS,
slot_eof_target_returndata: "0x00",
slot_eof_target_returndatasize: "0x01",
slot_legacy_target_call_status: CALL_FAILURE,
slot_legacy_target_call_status: LEGACY_CALL_FAILURE,
slot_legacy_target_returndatasize: "0x00",
}
if opcode == Op.CALL
else {
slot_eof_target_call_status: EXTCALL_SUCCESS,
slot_eof_target_returndata: "0x00",
slot_eof_target_returndatasize: "0x01",
slot_legacy_target_call_status: EXTCALL_FAILED,
slot_legacy_target_call_status: EXTCALL_FAILURE,
slot_legacy_target_returndatasize: "0x00",
}
)
Expand Down
5 changes: 0 additions & 5 deletions tests/prague/eip7692_eof_v1/eip7620_eof_create/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
value_code_worked = 0x2015
value_canary_should_not_change = 0x2019
value_canary_to_be_overwritten = 0x2009
value_create_failed = 0
value_legacy_call_result_failed = 0
value_eof_call_result_success = 0
value_eof_call_result_reverted = 1
value_eof_call_result_failed = 2

smallest_runtime_subcontainer = Container.Code(code=Op.STOP, name="Runtime Subcontainer")

Expand Down
2 changes: 2 additions & 0 deletions tests/prague/eip7692_eof_v1/eip7620_eof_create/spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
EOF V1 Constants used throughout all tests
"""

EOFCREATE_FAILURE = 0
10 changes: 5 additions & 5 deletions tests/prague/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ethereum_test_tools.vm.opcode import Opcodes as Op

from .. import EOF_FORK_NAME
from ..eip7069_extcall.spec import EXTCALL_SUCCESS
from .helpers import (
slot_call_result,
slot_calldata,
Expand All @@ -29,9 +30,8 @@
smallest_runtime_subcontainer,
value_canary_to_be_overwritten,
value_code_worked,
value_create_failed,
value_eof_call_result_success,
)
from .spec import EOFCREATE_FAILURE

REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7620.md"
REFERENCE_SPEC_VERSION = "52ddbcdddcf72dd72427c319f2beddeb468e1737"
Expand Down Expand Up @@ -433,7 +433,7 @@ def test_return_data_cleared(
post = {
contract_address: Account(
storage={
slot_call_result: value_eof_call_result_success,
slot_call_result: EXTCALL_SUCCESS,
slot_returndata_size: value_return_canary_size,
slot_create_address: new_contract_address,
slot_returndata_size_2: 0,
Expand Down Expand Up @@ -496,8 +496,8 @@ def test_address_collision(
contract_address: Account(
storage={
slot_create_address: salt_zero_address,
slot_create_address_2: value_create_failed, # had an in-transaction collision
slot_create_address_3: value_create_failed, # had a pre-existing collision
slot_create_address_2: EOFCREATE_FAILURE, # had an in-transaction collision
slot_create_address_3: EOFCREATE_FAILURE, # had a pre-existing collision
slot_code_worked: value_code_worked,
}
)
Expand Down
Loading

0 comments on commit 22c734a

Please sign in to comment.