Repository navigation
fix(tests): merge stWalletTest, stSStoreTest and stEIP* tests #4004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
marioevz
wants to merge
19
commits into
ethereum:forks/bogota
Choose a base branch
from
marioevz:finalize-ported-static-wallet-sstore
base: forks/bogota
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,179
−24,700
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0dc2aa3
refactor(tests): merge stEIP1559 diff places tests, drop mutable marker
marioevz 1f6f310
fix(tests): merge stWalletTest into 4 files, fix vacuous wallet cases
marioevz 5c5c635
fix(tests): merge stSStoreTest transitions, fix sstore_0toX CREATE2 case
marioevz a192f18
refactor(tests): merge stEIP3607 sender-with-code tests, narrow colli…
marioevz 203783e
refactor(tests): merge stEIP158Specific CALL-then-SELFDESTRUCT tests
marioevz c442a09
refactor(tests): use the default coinbase in stEIP3651 warm coinbase …
marioevz b0be00f
refactor(tests): merge stEIP2930 coinbase tests, thread storage_costs
marioevz 815ef76
refactor(tests): thread generated addresses through stEIP2930 varied_…
marioevz e8833fe
refactor(tests): use the default base fee in two stEIP1559 tests
marioevz e9b0467
refactor(tests): drop default deploy_contract nonce and empty tx data
marioevz 48fa056
fix(tests): bound failing calls that burn the transaction gas
marioevz 3c6783f
fix(tests): send value to wallet calls that keep the storage
marioevz 913811a
refactor(tests): clarify the wallet construction out-of-gas budget
marioevz 09fe3f4
fix(tests): skip env-dependent tests in execute mode
marioevz a99cc12
refactor(tests): drop legacy source comments from touched files
marioevz af6d723
docs(tests): mark the rewritten files as manually enhanced
marioevz 98e6553
refactor(tests): merge stEIP1559 fee cap and out-of-funds type pairs
marioevz b76c996
refactor(tests): drop default access lists and price-only base fees
marioevz d6b7d68
fix(tests): restore the nonce-only SELFDESTRUCT beneficiary case
marioevz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,276 changes: 0 additions & 1,276 deletions
1,276
tests/ported_static/stEIP1559/test_base_fee_diff_places.py
This file was deleted.
Oops, something went wrong.
1,267 changes: 0 additions & 1,267 deletions
1,267
tests/ported_static/stEIP1559/test_base_fee_diff_places_osaka.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,253 @@ | ||
| """ | ||
| Read BASEFEE and GASPRICE from different execution contexts. | ||
|
|
||
| Ported from: | ||
| state_tests/stEIP1559/baseFeeDiffPlacesFiller.yml | ||
| state_tests/stEIP1559/baseFeeDiffPlacesOsakaFiller.yml | ||
| state_tests/stEIP1559/gasPriceDiffPlacesFiller.yml | ||
| state_tests/stEIP1559/gasPriceDiffPlacesOsakaFiller.yml | ||
|
|
||
| @manually-enhanced: Do not overwrite. Merged into one parametrized test. | ||
| """ | ||
|
|
||
| from typing import Dict | ||
|
|
||
| import pytest | ||
| from execution_testing import ( | ||
| Account, | ||
| Address, | ||
| Alloc, | ||
| Bytecode, | ||
| Conditional, | ||
| Environment, | ||
| Initcode, | ||
| StateTestFiller, | ||
| Transaction, | ||
| ) | ||
| from execution_testing.forks import Fork | ||
| from execution_testing.vm import Op | ||
|
|
||
| from tests.ported_static.constants import HIGH_GAS_LIMIT | ||
|
|
||
| REFERENCE_SPEC_GIT_PATH = "N/A" | ||
| REFERENCE_SPEC_VERSION = "N/A" | ||
|
|
||
| PORTED_FROM = [ | ||
| "state_tests/stEIP1559/baseFeeDiffPlacesFiller.yml", | ||
| "state_tests/stEIP1559/baseFeeDiffPlacesOsakaFiller.yml", | ||
| "state_tests/stEIP1559/gasPriceDiffPlacesFiller.yml", | ||
| "state_tests/stEIP1559/gasPriceDiffPlacesOsakaFiller.yml", | ||
| ] | ||
|
|
||
| GAS_PRICE = 2000 | ||
| GOAT = 0x60A7 | ||
| RECURSION_DEPTH = 1023 | ||
| RECURSION_GAS_LIMIT = 0x10000000000000 | ||
| CREATE2_SALT = 0x5A17 | ||
| FAILING_CALL_GAS = 25_000 | ||
|
|
||
| CALL_OPS = { | ||
| "call": Op.CALL, | ||
| "callcode": Op.CALLCODE, | ||
| "delegatecall": Op.DELEGATECALL, | ||
| "staticcall": Op.STATICCALL, | ||
| } | ||
| CREATE_OPS = {"create": Op.CREATE, "create2": Op.CREATE2} | ||
|
|
||
| ACTIONS = ( | ||
| ["direct"] | ||
| + list(CALL_OPS) | ||
| + [f"{outer}_{inner}" for inner in CALL_OPS for outer in CALL_OPS] | ||
| + ["after_revert", "after_oog", "after_selfdestruct"] | ||
| + list(CREATE_OPS) | ||
| + [f"{create}_{call}" for create in CREATE_OPS for call in CALL_OPS] | ||
| ) | ||
|
|
||
| OPCODES = pytest.mark.parametrize( | ||
| "opcode", [Op.BASEFEE, Op.GASPRICE], ids=["base_fee", "gas_price"] | ||
| ) | ||
|
|
||
|
|
||
| def expected_value(opcode: Op, fork: Fork) -> int: | ||
| """Return the value the opcode is expected to push.""" | ||
| if opcode == Op.BASEFEE: | ||
| base_fee = Environment().set_fork_requirements(fork).base_fee_per_gas | ||
| assert base_fee is not None | ||
| return int(base_fee) | ||
| return GAS_PRICE | ||
|
|
||
|
|
||
| def call_into(op: Op, address: Address | Bytecode) -> Bytecode: | ||
| """Call `address` with `op`, copying 32 bytes of output to memory 0.""" | ||
| return op(address=address, ret_offset=0, ret_size=0x20) | ||
|
|
||
|
|
||
| def run_and_create( | ||
| create: str, initcode_holder: Address, create_value: int = 0 | ||
| ) -> Bytecode: | ||
| """Create a contract with the initcode held by `initcode_holder`.""" | ||
| size = Op.EXTCODESIZE(initcode_holder) | ||
| code = Op.EXTCODECOPY( | ||
| address=initcode_holder, dest_offset=0x20, offset=0, size=size | ||
| ) | ||
| if create == "create": | ||
| return code + Op.CREATE(value=create_value, offset=0x20, size=size) | ||
| return code + Op.CREATE2( | ||
| value=create_value, offset=0x20, size=size, salt=CREATE2_SALT | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.ported_from(PORTED_FROM) | ||
| @pytest.mark.valid_from("Cancun") | ||
| @pytest.mark.execute( | ||
| pytest.mark.skip(reason="Expects the base fee of the test env") | ||
| ) | ||
| @OPCODES | ||
| @pytest.mark.parametrize("action", ACTIONS) | ||
| def test_diff_places( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| fork: Fork, | ||
| opcode: Op, | ||
| action: str, | ||
| ) -> None: | ||
| """Read the opcode directly, through calls, and in created code.""" | ||
| template = Op.MSTORE(offset=0, value=opcode) | ||
| expected = expected_value(opcode, fork) | ||
| sender = pre.fund_eoa() | ||
| post: Dict[Address, Account] = {} | ||
|
|
||
| runner = pre.deploy_contract(code=template + Op.RETURN(0, 0x20)) | ||
| relays = { | ||
| name: pre.deploy_contract( | ||
| code=Op.POP(call_into(op, runner)) + Op.RETURN(0, 0x20) | ||
| ) | ||
| for name, op in CALL_OPS.items() | ||
| } | ||
| reverter = pre.deploy_contract( | ||
| code=template | ||
| + Op.SSTORE(0, Op.MLOAD(0)) | ||
| + Op.REVERT(offset=0, size=0x20), | ||
| storage={0: GOAT}, | ||
| ) | ||
| out_of_gas = pre.deploy_contract( | ||
| code=template + Op.SSTORE(0, Op.MLOAD(0)) + Op.INVALID, | ||
| storage={0: GOAT}, | ||
| ) | ||
| self_destructor = pre.deploy_contract(code=Op.SELFDESTRUCT(0)) | ||
| constructor_holder = pre.deploy_contract( | ||
| code=template | ||
| + Op.MSTORE(0x40, Op.MLOAD(0)) | ||
| + Op.RETURN(offset=0x3F, size=0x21), | ||
| ) | ||
| runtime_holder = pre.deploy_contract( | ||
| code=Initcode(deploy_code=template + Op.RETURN(0, 0x20)), | ||
| ) | ||
|
|
||
| body: Bytecode | ||
| if action == "direct": | ||
| body = template | ||
| elif action in CALL_OPS: | ||
| body = Op.POP(call_into(CALL_OPS[action], runner)) | ||
| elif action in ("after_revert", "after_oog", "after_selfdestruct"): | ||
| failing = { | ||
| "after_revert": reverter, | ||
| "after_oog": out_of_gas, | ||
| "after_selfdestruct": self_destructor, | ||
| }[action] | ||
| body = ( | ||
| template | ||
| + Op.SSTORE(1, Op.MLOAD(0)) | ||
| + Op.MSTORE(0, GOAT) | ||
| + Op.POP(Op.CALL(gas=FAILING_CALL_GAS, address=failing)) | ||
| + template | ||
| ) | ||
| post[reverter] = Account(storage={0: GOAT}) | ||
| post[out_of_gas] = Account(storage={0: GOAT}) | ||
| elif action in CREATE_OPS: | ||
| body = Op.EXTCODECOPY( | ||
| address=run_and_create(action, constructor_holder), | ||
| dest_offset=0, | ||
| offset=1, | ||
| size=0x20, | ||
| ) | ||
| else: | ||
| first, second = action.split("_") | ||
| if first in CREATE_OPS: | ||
| body = Op.POP( | ||
| call_into( | ||
| CALL_OPS[second], run_and_create(first, runtime_holder) | ||
| ) | ||
| ) | ||
| else: | ||
| body = Op.POP(call_into(CALL_OPS[first], relays[second])) | ||
|
|
||
| checker = pre.deploy_contract( | ||
| code=Op.MSTORE(0, GOAT) + body + Op.SSTORE(0, Op.MLOAD(0)), | ||
| ) | ||
| storage = {0: expected} | ||
| if action.startswith("after_"): | ||
| storage[1] = expected | ||
| post[checker] = Account(storage=storage) | ||
|
|
||
| tx = Transaction(sender=sender, to=checker, gas_price=GAS_PRICE) | ||
| state_test(pre=pre, post=post, tx=tx) | ||
|
|
||
|
|
||
| @pytest.mark.ported_from(PORTED_FROM) | ||
| @pytest.mark.valid_from("Cancun") | ||
| @pytest.mark.execute( | ||
| pytest.mark.skip(reason="Expects the base fee of the test env") | ||
| ) | ||
| @pytest.mark.valid_until("Prague") | ||
| @OPCODES | ||
| def test_diff_places_deep_recursion( | ||
| state_test: StateTestFiller, | ||
| pre: Alloc, | ||
| fork: Fork, | ||
| opcode: Op, | ||
| ) -> None: | ||
| """Read the opcode at the bottom of a deep recursion.""" | ||
| template = Op.MSTORE(offset=0, value=opcode) | ||
| sender = pre.fund_eoa(amount=RECURSION_GAS_LIMIT * GAS_PRICE) | ||
| recursor = pre.deploy_contract( | ||
| code=Conditional( | ||
| condition=Op.ISZERO(Op.CALLDATALOAD(0)), | ||
| if_true=template, | ||
| if_false=Op.MSTORE(0, Op.SUB(Op.CALLDATALOAD(0), 1)) | ||
| + Op.POP( | ||
| Op.CALL( | ||
| address=Op.ADDRESS, | ||
| args_offset=0, | ||
| args_size=0x20, | ||
| ret_offset=0, | ||
| ret_size=0x20, | ||
| ) | ||
| ), | ||
| ) | ||
| + Op.RETURN(0, 0x20), | ||
| ) | ||
| checker = pre.deploy_contract( | ||
| code=Op.MSTORE(0, RECURSION_DEPTH) | ||
| + Op.POP( | ||
| Op.CALL( | ||
| address=recursor, | ||
| args_offset=0, | ||
| args_size=0x20, | ||
| ret_offset=0, | ||
| ret_size=0x20, | ||
| ) | ||
| ) | ||
| + Op.SSTORE(0, Op.MLOAD(0)), | ||
| ) | ||
|
|
||
| tx = Transaction( | ||
| sender=sender, | ||
| to=checker, | ||
| gas_limit=RECURSION_GAS_LIMIT, | ||
| gas_price=GAS_PRICE, | ||
| ) | ||
| post = {checker: Account(storage={0: expected_value(opcode, fork)})} | ||
| state_test( | ||
| env=Environment(gas_limit=HIGH_GAS_LIMIT), pre=pre, post=post, tx=tx | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.