|
9 | 9 | import math |
10 | 10 | from typing import Optional |
11 | 11 |
|
12 | | -from ethereum_test_tools import ( |
13 | | - Account, |
14 | | - Address, |
15 | | - Block, |
16 | | - BlockchainTestFiller, |
17 | | - Environment, |
18 | | -) |
19 | | -from ethereum_test_tools.vm.opcode import Opcodes as Op |
| 12 | +from ethereum_test_tools import BlockchainTestFiller |
| 13 | +from .utils import AccountConfig, stride, _generic_conversion |
20 | 14 |
|
21 | 15 | REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7748.md" |
22 | 16 | REFERENCE_SPEC_VERSION = "TODO" |
23 | 17 |
|
24 | | -stride = 7 |
25 | | -accounts = sorted([Address(i) for i in range(0, 100)], key=lambda x: x.keccak256()) |
26 | | - |
27 | | - |
28 | | -class AccountConfig: |
29 | | - def __init__(self, code_length: int, storage_slot_count: int): |
30 | | - self.code_length = code_length |
31 | | - self.storage_slots_count = storage_slot_count |
32 | | - |
33 | 18 |
|
34 | 19 | @pytest.mark.valid_from("EIP6800Transition") |
35 | 20 | @pytest.mark.parametrize( |
@@ -199,49 +184,6 @@ def test_codechunks_stride_overflow( |
199 | 184 | _generic_conversion(blockchain_test, account_configs, fill_first_block, fill_last_block) |
200 | 185 |
|
201 | 186 |
|
202 | | -def _generic_conversion( |
203 | | - blockchain_test: BlockchainTestFiller, |
204 | | - account_configs: list[AccountConfig], |
205 | | - fill_first_block: bool, |
206 | | - fill_last_block: bool, |
207 | | -): |
208 | | - conversion_units = 0 |
209 | | - pre_state = {} |
210 | | - account_idx = 0 |
211 | | - if fill_first_block: |
212 | | - for i in range(stride): |
213 | | - conversion_units += 1 |
214 | | - pre_state[accounts[account_idx]] = Account(balance=100 + 1000 * i) |
215 | | - account_idx += 1 |
216 | | - |
217 | | - for i, account_config in enumerate(account_configs): |
218 | | - storage = {} |
219 | | - for j in range(account_config.storage_slots_count): |
220 | | - conversion_units += 1 |
221 | | - storage[j] = j + 1 |
222 | | - |
223 | | - pre_state[accounts[account_idx]] = Account( |
224 | | - balance=100 + 1000 * i, |
225 | | - nonce=i, |
226 | | - code=Op.JUMPDEST * account_config.code_length, |
227 | | - storage=storage, |
228 | | - ) |
229 | | - account_idx += 1 |
230 | | - |
231 | | - conversion_units += 1 # Account basic data |
232 | | - num_code_chunks = math.ceil(account_config.code_length / 31) |
233 | | - # Code is always converted in one go, but it counts for stride quota usage |
234 | | - conversion_units += min(num_code_chunks, stride - conversion_units % stride) |
235 | | - |
236 | | - if fill_last_block: |
237 | | - for i in range((-conversion_units) % stride + stride): |
238 | | - conversion_units += 1 |
239 | | - pre_state[accounts[account_idx]] = Account(balance=100 + 1000 * i) |
240 | | - account_idx += 1 |
241 | | - |
242 | | - _state_conversion(blockchain_test, pre_state, stride, math.ceil(conversion_units / stride)) |
243 | | - |
244 | | - |
245 | 187 | # @pytest.mark.skip("stride config not supported yet") |
246 | 188 | # @pytest.mark.valid_from("EIP6800Transition") |
247 | 189 | # @pytest.mark.parametrize( |
@@ -309,31 +251,3 @@ def _generic_conversion( |
309 | 251 | # ) |
310 | 252 |
|
311 | 253 | # _state_conversion(blockchain_test, pre_state, stride, num_expected_blocks) |
312 | | - |
313 | | - |
314 | | -def _state_conversion( |
315 | | - blockchain_test: BlockchainTestFiller, |
316 | | - pre_state: dict[Address, Account], |
317 | | - stride: int, |
318 | | - num_blocks: int, |
319 | | -): |
320 | | - # TODO: test library should allow passing stride |
321 | | - env = Environment( |
322 | | - fee_recipient="0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", |
323 | | - difficulty=0x20000, |
324 | | - gas_limit=10000000000, |
325 | | - ) |
326 | | - |
327 | | - blocks: list[Block] = [] |
328 | | - for i in range(num_blocks): |
329 | | - blocks.append(Block(txs=[])) |
330 | | - |
331 | | - # TODO: witness assertion |
332 | | - # TODO: see if possible last block switch to finished conversion |
333 | | - |
334 | | - blockchain_test( |
335 | | - genesis_environment=env, |
336 | | - pre=pre_state, |
337 | | - post=pre_state.copy(), |
338 | | - blocks=blocks, |
339 | | - ) |
0 commit comments