Skip to content

Commit

Permalink
Ban post merge empty accounts in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petertdavies committed Dec 1, 2023
1 parent 3fe6514 commit 9a2cc26
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 9a2cc26

Please sign in to comment.