Skip to content

Commit 9a2cc26

Browse files
committed
Ban post merge empty accounts in tests
1 parent 3fe6514 commit 9a2cc26

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ethereum_spec_tools/evm_tools/fixture_loader.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def __init__(self, encoded_params: bytes, error_message: str) -> None:
3232
self.error_message = error_message
3333

3434

35+
class EmptyAccountOnPostMergeFork(Exception):
36+
"""
37+
Exception for tests that are invalid due to empty accounts on post
38+
merge forks
39+
"""
40+
41+
3542
class BaseLoad(ABC):
3643
"""Base class for loading json fixtures"""
3744

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

246+
def _is_post_merge_fork(self) -> bool:
247+
return not hasattr(self._module("fork"), "validate_proof_of_work")
248+
239249
def json_to_state(self, raw: Any) -> Any:
240250
"""Converts json state data to a state object"""
241251
state = self.State()
242252
set_storage = self._module("state").set_storage
253+
is_post_merge_fork = self._is_post_merge_fork()
254+
EMPTY_ACCOUNT = self._module("fork_types").EMPTY_ACCOUNT
243255

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

253267
for (k, v) in account_state.get("storage", {}).items():

0 commit comments

Comments
 (0)