1212from ethereum .exceptions import StateWithEmptyAccount
1313from ethereum .utils .hexadecimal import hex_to_bytes
1414from ethereum_spec_tools .evm_tools import create_parser
15- from ethereum_spec_tools .evm_tools .statetest import TestCase , read_test_case
15+ from ethereum_spec_tools .evm_tools .statetest import read_test_case
1616from ethereum_spec_tools .evm_tools .t8n import T8N
1717
1818from .. import FORKS
1919from .exceptional_test_patterns import (
2020 exceptional_state_test_patterns ,
2121)
22- from .fixtures import Fixture
22+ from .fixtures import Fixture , FixturesFile , FixtureTestItem
2323
2424parser = create_parser ()
2525
2626
27- class StateTest (Item ):
27+ class StateTest (FixtureTestItem ):
2828 """Single state test case item."""
2929
30- test_case : TestCase
31- test_dict : Dict [ str , Any ]
30+ index : int
31+ fork_name : str
3232
3333 def __init__ (
3434 self ,
3535 * args : Any ,
36- test_case : TestCase ,
37- test_dict : Dict [str , Any ],
36+ index : int ,
37+ fork_name : str ,
38+ key : str ,
3839 ** kwargs : Any ,
3940 ) -> None :
4041 """Initialize a single test case item."""
4142 super ().__init__ (* args , ** kwargs )
42- self .test_case = test_case
43- self .test_dict = test_dict
44- self .add_marker (pytest .mark .fork (self .test_case . fork_name ))
43+ self .index = index
44+ self .fork_name = fork_name
45+ self .add_marker (pytest .mark .fork (self .fork_name ))
4546 self .add_marker ("evm_tools" )
4647 self .add_marker ("json_state_tests" )
47- eels_fork = FORKS [test_case .fork_name ]["eels_fork" ]
48- test_patterns = exceptional_state_test_patterns (
49- test_case .fork_name , eels_fork
50- )
51- if any (x .search (test_case .key ) for x in test_patterns .slow ):
48+ eels_fork = FORKS [fork_name ]["eels_fork" ]
49+ test_patterns = exceptional_state_test_patterns (fork_name , eels_fork )
50+ if any (x .search (key ) for x in test_patterns .slow ):
5251 self .add_marker ("slow" )
5352
53+ @property
54+ def state_test_fixture (self ) -> "StateTestFixture" :
55+ """Return the state test fixture this test belongs to."""
56+ parent = self .parent
57+ assert parent is not None
58+ assert isinstance (parent , StateTestFixture )
59+ return parent
60+
61+ @property
62+ def test_key (self ) -> str :
63+ """Return the key of the state test fixture in the fixture file."""
64+ return self .state_test_fixture .test_key
65+
66+ @property
67+ def fixtures_file (self ) -> FixturesFile :
68+ """Fixtures file from which the test fixture was collected."""
69+ return self .state_test_fixture .fixtures_file
70+
71+ @property
72+ def test_dict (self ) -> Dict [str , Any ]:
73+ """Load test from disk."""
74+ loaded_file = self .fixtures_file .data
75+ return loaded_file [self .test_key ]
76+
5477 def runtest (self ) -> None :
5578 """
5679 Runs a single general state test.
5780 """
58- index = self .test_case .index
59- json_fork = self .test_case .fork_name
81+ json_fork = self .fork_name
6082 test_dict = self .test_dict
6183
6284 env = test_dict ["env" ]
@@ -68,7 +90,7 @@ def runtest(self) -> None:
6890
6991 alloc = test_dict ["pre" ]
7092
71- post = test_dict ["post" ][json_fork ][ index ]
93+ post = test_dict ["post" ][self . fork_name ][ self . index ]
7294 post_hash = post ["hash" ]
7395 d = post ["indexes" ]["data" ]
7496 g = post ["indexes" ]["gas" ]
@@ -144,6 +166,20 @@ def is_format(cls, test_dict: Dict[str, Any]) -> bool:
144166 return False
145167 return True
146168
169+ @property
170+ def fixtures_file (self ) -> FixturesFile :
171+ """Fixtures file from which the test fixture was collected."""
172+ parent = self .parent
173+ assert parent is not None
174+ assert isinstance (parent , FixturesFile )
175+ return parent
176+
177+ @property
178+ def test_dict (self ) -> Dict [str , Any ]:
179+ """Load test from disk."""
180+ loaded_file = self .fixtures_file .data
181+ return loaded_file [self .test_key ]
182+
147183 def collect (self ) -> Iterable [Item | Collector ]:
148184 """Collect state test cases inside of this fixture."""
149185 for test_case in read_test_case (
@@ -157,6 +193,7 @@ def collect(self) -> Iterable[Item | Collector]:
157193 yield StateTest .from_parent (
158194 parent = self ,
159195 name = name ,
160- test_case = test_case ,
161- test_dict = self .test_dict ,
196+ index = test_case .index ,
197+ fork_name = test_case .fork_name ,
198+ key = self .test_key ,
162199 )
0 commit comments