2121REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7748.md"
2222REFERENCE_SPEC_VERSION = "TODO"
2323
24- accounts = sorted ([Address (i ) for i in range (0 , 50 )], key = lambda x : x .keccak256 ())
24+ stride = 7
25+ accounts = sorted ([Address (i ) for i in range (0 , 100 )], key = lambda x : x .keccak256 ())
2526
2627
2728class AccountConfig :
@@ -30,15 +31,16 @@ def __init__(self, code_length: int, storage_slot_count: int):
3031 self .storage_slots_count = storage_slot_count
3132
3233
34+ @pytest .mark .skip ("TEMPORAL" )
3335@pytest .mark .valid_from ("EIP6800Transition" )
3436@pytest .mark .parametrize (
3537 "account_configs" ,
3638 [
3739 [AccountConfig (0 , 0 )],
3840 [AccountConfig (0 , 0 )] * 2 ,
39- [AccountConfig (0 , 0 )] * 7 ,
41+ [AccountConfig (0 , 0 )] * stride ,
4042 [AccountConfig (15 , 2 )],
41- [AccountConfig (31 * 2 + 1 , 3 )], # 3 code-chunks + 3 slots + account data = 7
43+ [AccountConfig (31 * 2 + 1 , 3 )], # 3 code-chunks + 3 slots + account data = stride
4244 [AccountConfig (0 , 0 ), AccountConfig (15 , 2 )],
4345 [
4446 AccountConfig (0 , 0 ),
@@ -77,39 +79,112 @@ def __init__(self, code_length: int, storage_slot_count: int):
7779)
7880@pytest .mark .parametrize (
7981 "fill_first_block" ,
82+ [False , True ],
83+ )
84+ @pytest .mark .parametrize (
85+ "fill_last_block" ,
86+ [False , True ],
87+ )
88+ def test_non_partial (
89+ blockchain_test : BlockchainTestFiller ,
90+ account_configs : list [AccountConfig ],
91+ fill_first_block : bool ,
92+ fill_last_block : bool ,
93+ ):
94+ """
95+ Test non-partial account conversions.
96+ """
97+ _generic_conversion (blockchain_test , account_configs , fill_first_block , fill_last_block )
98+
99+
100+ @pytest .mark .valid_from ("EIP6800Transition" )
101+ @pytest .mark .parametrize (
102+ "account_configs" ,
80103 [
81- False ,
82- True ,
104+ # No prefix
105+ [AccountConfig (31 * 2 + 1 , stride + 2 )],
106+ [AccountConfig (31 * 2 + 1 , stride + 1 )],
107+ [AccountConfig (31 + 2 + 1 , stride )],
108+ # EOA prefix
109+ [AccountConfig (0 , 0 ), AccountConfig (42 , - 1 + stride + 2 )],
110+ [AccountConfig (0 , 0 ), AccountConfig (42 , - 1 + stride + 1 )],
111+ [AccountConfig (0 , 0 ), AccountConfig (42 , - 1 + stride )],
112+ # Contract prefix
113+ [AccountConfig (10 , 1 ), AccountConfig (42 , - 3 + stride + 2 )],
114+ [AccountConfig (10 , 1 ), AccountConfig (42 , - 3 + stride + 1 )],
115+ [AccountConfig (10 , 1 ), AccountConfig (42 , - 3 + stride )],
116+ ],
117+ ids = [
118+ "No prefix & boundary at two storage slots before finishing storage trie" ,
119+ "No prefix & boundary at one storage slot before finishing storage trie" ,
120+ "No prefix & boundary matching exactly the end of the storage trie" ,
121+ "EOA prefix & boundary at two storage slots before finishing storage trie" ,
122+ "EOA prefix & boundary at one storage slot before finishing storage trie" ,
123+ "EOA prefix & boundary matching exactly the end of the storage trie" ,
124+ "Contract prefix & boundary at two storage slots before finishing storage trie" ,
125+ "Contract prefix & boundary at one storage slot before finishing storage trie" ,
126+ "Contract prefix & boundary matching exactly the end of the storage trie" ,
83127 ],
84128)
85- def test_conversions (
129+ @pytest .mark .parametrize (
130+ "fill_first_block" ,
131+ [False , True ],
132+ )
133+ @pytest .mark .parametrize (
134+ "fill_last_block" ,
135+ [False , True ],
136+ )
137+ def test_partial (
86138 blockchain_test : BlockchainTestFiller ,
87139 account_configs : list [AccountConfig ],
88140 fill_first_block : bool ,
141+ fill_last_block : bool ,
89142):
90143 """
91- Test conversion cases .
144+ Test partial account conversions .
92145 """
93- stride = 7
146+ _generic_conversion (blockchain_test , account_configs , fill_first_block , fill_last_block )
147+
148+
149+ def _generic_conversion (
150+ blockchain_test : BlockchainTestFiller ,
151+ account_configs : list [AccountConfig ],
152+ fill_first_block : bool ,
153+ fill_last_block : bool ,
154+ ):
94155 conversion_units = 0
95156 pre_state = {}
157+ account_idx = 0
96158 if fill_first_block :
97159 for i in range (stride ):
98160 conversion_units += 1
99- pre_state [accounts [i ]] = Account (balance = 100 + 1000 * i )
161+ pre_state [accounts [account_idx ]] = Account (balance = 100 + 1000 * i )
162+ account_idx += 1
100163
101- for i , account_config in enumerate (account_configs , start = len ( pre_state ) ):
164+ for i , account_config in enumerate (account_configs ):
102165 storage = {}
103166 for j in range (account_config .storage_slots_count ):
104167 conversion_units += 1
105168 storage [j ] = j + 1
106169
107- pre_state [accounts [i ]] = Account (
170+ pre_state [accounts [account_idx ]] = Account (
108171 balance = 100 + 1000 * i ,
172+ nonce = i ,
109173 code = Op .JUMPDEST * account_config .code_length ,
110174 storage = storage ,
111175 )
112- conversion_units += 1 + math .ceil (account_config .code_length / 31 )
176+ account_idx += 1
177+
178+ conversion_units += 1 # Account basic data
179+ num_code_chunks = math .ceil (account_config .code_length / 31 )
180+ # Code is always converted in one go, but it counts for stride quota usage
181+ conversion_units += min (num_code_chunks , stride - conversion_units % stride )
182+
183+ if fill_last_block :
184+ for i in range ((- conversion_units ) % stride + stride ):
185+ conversion_units += 1
186+ pre_state [accounts [account_idx ]] = Account (balance = 100 + 1000 * i )
187+ account_idx += 1
113188
114189 _state_conversion (blockchain_test , pre_state , stride , math .ceil (conversion_units / stride ))
115190
0 commit comments