forked from ethereum/execution-spec-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tests): EOF - EIP-7698: context variables
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
tests/prague/eip7692_eof_v1/eip7698_eof_creation_tx/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
EOF creation transaction (empty `to`) tests | ||
""" |
16 changes: 16 additions & 0 deletions
16
tests/prague/eip7692_eof_v1/eip7698_eof_creation_tx/helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
A collection of contracts used in 7698 EOF tests | ||
""" | ||
import itertools | ||
|
||
from ethereum_test_tools import Opcodes as Op | ||
from ethereum_test_tools.eof.v1 import Container | ||
|
||
"""Storage addresses for common testing fields""" | ||
_slot = itertools.count() | ||
next(_slot) # don't use slot 0 | ||
slot_call_result = next(_slot) | ||
|
||
slot_last_slot = next(_slot) | ||
|
||
smallest_runtime_subcontainer = Container.Code(code=Op.STOP, name="Runtime Subcontainer") |
79 changes: 79 additions & 0 deletions
79
tests/prague/eip7692_eof_v1/eip7698_eof_creation_tx/test_eof_creation_tx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Test execution of EOF creation txs | ||
""" | ||
|
||
import pytest | ||
|
||
from ethereum_test_base_types.base_types import Address | ||
from ethereum_test_tools import Account, Alloc, Environment, StateTestFiller, Transaction | ||
from ethereum_test_tools.eof.v1 import Container, Section | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
from ethereum_test_types.helpers import compute_create_address | ||
from ethereum_test_vm.bytecode import Bytecode | ||
|
||
from .. import EOF_FORK_NAME | ||
from .helpers import slot_call_result, smallest_runtime_subcontainer | ||
|
||
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7698.md" | ||
REFERENCE_SPEC_VERSION = "ff544c14889aeb84be214546a09f410a67b919be" | ||
|
||
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["destination_code", "expected_result"], | ||
[ | ||
pytest.param(Op.ADDRESS, "destination"), | ||
pytest.param(Op.CALLER, "sender"), | ||
pytest.param(Op.CALLVALUE, "value"), | ||
pytest.param(Op.ORIGIN, "sender"), | ||
], | ||
) | ||
def test_eof_creation_tx_context( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
destination_code: Bytecode, | ||
expected_result: str, | ||
): | ||
"""Test EOF creation txs' initcode context instructions""" | ||
env = Environment() | ||
sender = pre.fund_eoa() | ||
value = 0x1123 | ||
|
||
initcode = Container( | ||
sections=[ | ||
Section.Code( | ||
Op.SSTORE(slot_call_result, destination_code) + Op.RETURNCONTRACT[0](0, 0) | ||
), | ||
Section.Container(smallest_runtime_subcontainer), | ||
] | ||
) | ||
|
||
destination_contract_address = compute_create_address(address=sender, nonce=sender.nonce) | ||
|
||
tx = Transaction(sender=sender, to=None, gas_limit=100000, value=value, input=initcode) | ||
|
||
expected_bytes: Address | int | ||
if expected_result == "destination": | ||
expected_bytes = destination_contract_address | ||
elif expected_result == "sender": | ||
expected_bytes = sender | ||
elif expected_result == "value": | ||
expected_bytes = value | ||
else: | ||
raise TypeError("Unexpected expected_result", expected_result) | ||
|
||
destination_contract_storage = { | ||
slot_call_result: expected_bytes, | ||
} | ||
|
||
post = { | ||
destination_contract_address: Account(storage=destination_contract_storage), | ||
} | ||
|
||
state_test( | ||
env=env, | ||
pre=pre, | ||
post=post, | ||
tx=tx, | ||
) |