@@ -32,6 +32,13 @@ def __init__(self, encoded_params: bytes, error_message: str) -> None:
32
32
self .error_message = error_message
33
33
34
34
35
+ class EmptyAccountOnPostMergeFork (Exception ):
36
+ """
37
+ Exception for tests that are invalid due to empty accounts on post
38
+ merge forks
39
+ """
40
+
41
+
35
42
class BaseLoad (ABC ):
36
43
"""Base class for loading json fixtures"""
37
44
@@ -236,10 +243,15 @@ def _module(self, name: str) -> Any:
236
243
"""Imports a module from the fork"""
237
244
return importlib .import_module (f"ethereum.{ self ._fork_module } .{ name } " )
238
245
246
+ def _is_post_merge_fork (self ) -> bool :
247
+ return not hasattr (self ._module ("fork" ), "validate_proof_of_work" )
248
+
239
249
def json_to_state (self , raw : Any ) -> Any :
240
250
"""Converts json state data to a state object"""
241
251
state = self .State ()
242
252
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
243
255
244
256
for (address_hex , account_state ) in raw .items ():
245
257
address = self .hex_to_address (address_hex )
@@ -248,6 +260,8 @@ def json_to_state(self, raw: Any) -> Any:
248
260
balance = U256 (hex_to_uint (account_state .get ("balance" , "0x0" ))),
249
261
code = hex_to_bytes (account_state .get ("code" , "" )),
250
262
)
263
+ if is_post_merge_fork and account == EMPTY_ACCOUNT :
264
+ raise EmptyAccountOnPostMergeFork
251
265
self .set_account (state , address , account )
252
266
253
267
for (k , v ) in account_state .get ("storage" , {}).items ():
0 commit comments