Skip to content

Commit d01e5ad

Browse files
committed
refactor
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 240e626 commit d01e5ad

File tree

2 files changed

+92
-88
lines changed

2 files changed

+92
-88
lines changed

tests/verkle/eip7748/accounts.py

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,12 @@
99
import math
1010
from typing import Optional
1111

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
2014

2115
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7748.md"
2216
REFERENCE_SPEC_VERSION = "TODO"
2317

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-
3318

3419
@pytest.mark.valid_from("EIP6800Transition")
3520
@pytest.mark.parametrize(
@@ -199,49 +184,6 @@ def test_codechunks_stride_overflow(
199184
_generic_conversion(blockchain_test, account_configs, fill_first_block, fill_last_block)
200185

201186

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-
245187
# @pytest.mark.skip("stride config not supported yet")
246188
# @pytest.mark.valid_from("EIP6800Transition")
247189
# @pytest.mark.parametrize(
@@ -309,31 +251,3 @@ def _generic_conversion(
309251
# )
310252

311253
# _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-
)

tests/verkle/eip7748/utils.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from ethereum_test_tools.vm.opcode import Opcodes as Op
2+
import math
3+
from ethereum_test_tools import (
4+
Account,
5+
Address,
6+
Block,
7+
BlockchainTestFiller,
8+
Environment,
9+
)
10+
11+
stride = 7
12+
13+
accounts = sorted([Address(i) for i in range(0, 100)], key=lambda x: x.keccak256())
14+
15+
16+
class AccountConfig:
17+
def __init__(self, code_length: int, storage_slot_count: int):
18+
self.code_length = code_length
19+
self.storage_slots_count = storage_slot_count
20+
21+
22+
def _generic_conversion(
23+
blockchain_test: BlockchainTestFiller,
24+
account_configs: list[AccountConfig],
25+
fill_first_block: bool,
26+
fill_last_block: bool,
27+
):
28+
conversion_units = 0
29+
pre_state = {}
30+
account_idx = 0
31+
if fill_first_block:
32+
for i in range(stride):
33+
conversion_units += 1
34+
pre_state[accounts[account_idx]] = Account(balance=100 + 1000 * i)
35+
account_idx += 1
36+
37+
for i, account_config in enumerate(account_configs):
38+
storage = {}
39+
for j in range(account_config.storage_slots_count):
40+
conversion_units += 1
41+
storage[j] = j + 1
42+
43+
pre_state[accounts[account_idx]] = Account(
44+
balance=100 + 1000 * i,
45+
nonce=i,
46+
code=Op.JUMPDEST * account_config.code_length,
47+
storage=storage,
48+
)
49+
account_idx += 1
50+
51+
conversion_units += 1 # Account basic data
52+
num_code_chunks = math.ceil(account_config.code_length / 31)
53+
# Code is always converted in one go, but it counts for stride quota usage
54+
conversion_units += min(num_code_chunks, stride - conversion_units % stride)
55+
56+
if fill_last_block:
57+
for i in range((-conversion_units) % stride + stride):
58+
conversion_units += 1
59+
pre_state[accounts[account_idx]] = Account(balance=100 + 1000 * i)
60+
account_idx += 1
61+
62+
_state_conversion(blockchain_test, pre_state, stride, math.ceil(conversion_units / stride))
63+
64+
65+
def _state_conversion(
66+
blockchain_test: BlockchainTestFiller,
67+
pre_state: dict[Address, Account],
68+
stride: int,
69+
num_blocks: int,
70+
):
71+
# TODO: test library should allow passing stride
72+
env = Environment(
73+
fee_recipient="0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
74+
difficulty=0x20000,
75+
gas_limit=10000000000,
76+
)
77+
78+
blocks: list[Block] = []
79+
for i in range(num_blocks):
80+
blocks.append(Block(txs=[]))
81+
82+
# TODO: witness assertion
83+
# TODO: see if possible last block switch to finished conversion
84+
85+
blockchain_test(
86+
genesis_environment=env,
87+
pre=pre_state,
88+
post=pre_state.copy(),
89+
blocks=blocks,
90+
)

0 commit comments

Comments
 (0)