From e2612a13269e81ed8950ccef41ee76e735deaf98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 24 Oct 2024 11:40:43 +0200 Subject: [PATCH] new(tests): add basic EOF execution tests Migrated from ethereum/tests: EIPTests/StateTests/stEOF/stEIP3540/EOF1_Execution.json --- converted-ethereum-tests.txt | 2 + .../eip3540_eof_v1/test_execution.py | 78 +++++++++++++++++++ tests/osaka/eip7692_eof_v1/eof_tracker.md | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.py diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index 80ecd1ec57..5a028d6990 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -19,6 +19,8 @@ EOFTests/efValidation/unreachable_code_sections_.json EOFTests/efValidation/EOF1_returncontract_invalid_.json EOFTests/efValidation/EOF1_returncontract_valid_.json +EIPTests/StateTests/stEOF/stEIP3540/EOF1_Execution.json + ([#440](https://github.com/ethereum/execution-spec-tests/pull/440)) GeneralStateTests/Cancun/stEIP1153-transientStorage/01_tloadBeginningTxn.json GeneralStateTests/Cancun/stEIP1153-transientStorage/02_tloadAfterTstore.json diff --git a/tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.py b/tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.py new file mode 100644 index 0000000000..64ed462d53 --- /dev/null +++ b/tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.py @@ -0,0 +1,78 @@ +""" +Execution of basic EOF containers. +""" + +import pytest + +from ethereum_test_base_types import Storage +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 .. import EOF_FORK_NAME + +REFERENCE_SPEC_GIT_PATH = "EIPS/eip-3540.md" +REFERENCE_SPEC_VERSION = "8dcb0a8c1c0102c87224308028632cc986a61183" + +pytestmark = pytest.mark.valid_from(EOF_FORK_NAME) + +EXPECTED_STORAGE = (bytes.fromhex("EF"), bytes.fromhex("BADDCAFE")) +"""Expected storage (key => value) to be produced by the EOF containers""" + + +@pytest.mark.parametrize( + "container", + ( + Container( + name="store_from_push", + sections=[Section.Code(Op.SSTORE(*EXPECTED_STORAGE) + Op.STOP)], + ), + Container( + name="store_with_data", + sections=[ + Section.Code(Op.SSTORE(Op.DATALOADN[0], Op.DATALOADN[32]) + Op.STOP), + Section.Data( + EXPECTED_STORAGE[0].rjust(32, b"\x00") + EXPECTED_STORAGE[1].rjust(32, b"\x00") + ), + ], + ), + ), + ids=lambda x: x.name, +) +def test_eof_execution( + state_test: StateTestFiller, + pre: Alloc, + container: Container, +): + """ + Test simple contracts that are expected to succeed on call. + """ + env = Environment() + + storage = Storage() + sender = pre.fund_eoa() + container_address = pre.deploy_contract(container) + caller_contract = Op.SSTORE( + storage.store_next(1), Op.CALL(Op.GAS, container_address, 0, 0, 0, 0, 0) + ) + caller_address = pre.deploy_contract(caller_contract) + + tx = Transaction( + to=caller_address, + gas_limit=1_000_000, + gas_price=10, + protected=False, + sender=sender, + ) + + post = { + caller_address: Account(storage=storage), + container_address: Account(storage=dict([EXPECTED_STORAGE])), + } + + state_test( + env=env, + pre=pre, + post=post, + tx=tx, + ) diff --git a/tests/osaka/eip7692_eof_v1/eof_tracker.md b/tests/osaka/eip7692_eof_v1/eof_tracker.md index 61a8d87009..c52880ba92 100644 --- a/tests/osaka/eip7692_eof_v1/eof_tracker.md +++ b/tests/osaka/eip7692_eof_v1/eof_tracker.md @@ -81,7 +81,7 @@ ### Execution -- [ ] Execution of EOF contracts (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP3540/EOF1_ExecutionFiller.yml) +- [x] Execution of EOF contracts ([`tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.py::test_eof_execution`](./eip3540_eof_v1/test_execution/test_eof_execution.md)) - [x] Legacy executing EXTCODESIZE of EOF contract ([`tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py::test_legacy_calls_eof_sstore`](./eip3540_eof_v1/test_extcode/test_legacy_calls_eof_sstore.md)) - [x] Legacy executing EXTCODEHASH of EOF contract ([`tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py::test_legacy_calls_eof_sstore`](./eip3540_eof_v1/test_extcode/test_legacy_calls_eof_sstore.md)) - [x] Legacy executing EXTCODECOPY of EOF contract ([`tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py::test_legacy_calls_eof_sstore`](./eip3540_eof_v1/test_extcode/test_legacy_calls_eof_sstore.md))