Skip to content
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

Ban post merge empty accounts in tests #853

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/ethereum_spec_tools/evm_tools/fixture_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def __init__(self, encoded_params: bytes, error_message: str) -> None:
self.error_message = error_message


class EmptyAccountOnPostMergeFork(Exception):
"""
Exception for tests that are invalid due to empty accounts on post
merge forks
"""


class BaseLoad(ABC):
"""Base class for loading json fixtures"""

Expand Down Expand Up @@ -236,10 +243,15 @@ def _module(self, name: str) -> Any:
"""Imports a module from the fork"""
return importlib.import_module(f"ethereum.{self._fork_module}.{name}")

def _is_post_merge_fork(self) -> bool:
return not hasattr(self._module("fork"), "validate_proof_of_work")

def json_to_state(self, raw: Any) -> Any:
"""Converts json state data to a state object"""
state = self.State()
set_storage = self._module("state").set_storage
is_post_merge_fork = self._is_post_merge_fork()
EMPTY_ACCOUNT = self._module("fork_types").EMPTY_ACCOUNT

for address_hex, account_state in raw.items():
address = self.hex_to_address(address_hex)
Expand All @@ -248,6 +260,8 @@ def json_to_state(self, raw: Any) -> Any:
balance=U256(hex_to_uint(account_state.get("balance", "0x0"))),
code=hex_to_bytes(account_state.get("code", "")),
)
if is_post_merge_fork and account == EMPTY_ACCOUNT:
raise EmptyAccountOnPostMergeFork
self.set_account(state, address, account)

for k, v in account_state.get("storage", {}).items():
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ def pytest_sessionstart(session: Session) -> None:
git_clone_fixtures(
props["url"], props["commit_hash"], fixture_path
)
else:
elif "url" in props:
download_fixtures(props["url"], fixture_path)
2 changes: 1 addition & 1 deletion tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ethereum_tests": {
"url": "https://github.com/ethereum/tests.git",
"commit_hash": "0ec53d0",
"commit_hash": "9e8719a",
"fixture_path": "tests/fixtures/ethereum_tests",
},
}
Loading