-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tests): basic EOF execution tests (#912)
- Add basic EOF execution tests migrated from ethereum/tests: EIPTests/StateTests/stEOF/stEIP3540/EOF1_Execution.json - Extend execution test of legacy invoking `EXTCODE*` instruction on EOF with the case from ethereum/tests.
- Loading branch information
Showing
5 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
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
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
78 changes: 78 additions & 0 deletions
78
tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_execution.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,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, | ||
) |
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
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