Skip to content

Commit 88c37f1

Browse files
committed
eip7748: generalize test
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 3944076 commit 88c37f1

File tree

1 file changed

+61
-81
lines changed

1 file changed

+61
-81
lines changed

tests/verkle/eip7748/accounts.py

Lines changed: 61 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,101 +22,81 @@
2222
REFERENCE_SPEC_VERSION = "TODO"
2323

2424
# List of addressed ordered by MPT tree key.
25-
# 03601462093b5945d1676df093446790fd31b20e7b12a2e8e5e09d068109616b
26-
Account0 = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")
27-
# 0e195438d9f92eb191032b5f660d42a22255c9c417248f092c1f83f3a36b29ba
28-
Account1 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0e")
29-
# 6a7fc6037f7a0dca7004c2cd41d87bfd929be7eb0d31903b238839e8e7aaf897
30-
Account2 = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0a")
31-
# 6a8737909ea3e92b0d47328d70aff338c526832b32362eca8692126c1f399846
32-
Account3 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0d")
33-
# d3bd43970708294fd4d78893c4e7c2fed43c8cd505e9c9516e1f11e79f574598
34-
Account4 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0f")
35-
36-
accounts = [Account0, Account1, Account2, Account3, Account4]
25+
accounts = [
26+
# 03601462093b5945d1676df093446790fd31b20e7b12a2e8e5e09d068109616b
27+
Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
28+
# 1fe26fd0b8a197e7b85ed1ead2b52700041c5d465673aa744f3afc4704f83c03
29+
Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0d"),
30+
# 257f371320e4696a5debc64a489e651fc4565eb07ce0e4d2ce5b6d5b1896d89a
31+
Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0f"),
32+
# 6a7fc6037f7a0dca7004c2cd41d87bfd929be7eb0d31903b238839e8e7aaf897
33+
Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0a"),
34+
# 85174d7e61a36094fc9b58640ad245d4ab61d888699f3659137171ff2910b6cb
35+
Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0e"),
36+
# b4102152d5f5995b7a017c9db0e186028190faafa4326ac1ecfb2bc817c423c9
37+
Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf05"),
38+
# e72525e3842ed775ed5c52ffc1520247deae64a217fcb3fb3ddbe59ffeb5949c
39+
Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf03"),
40+
]
41+
42+
43+
class AccountConfig:
44+
def __init__(self, code_length: int, storage_slot_count: int):
45+
self.code_length = code_length
46+
self.storage_slots_count = storage_slot_count
3747

3848

3949
@pytest.mark.valid_from("EIP6800Transition")
4050
@pytest.mark.parametrize(
41-
"stride",
51+
"account_configs",
4252
[
43-
3,
53+
[AccountConfig(0, 0)],
54+
[AccountConfig(0, 0), AccountConfig(0, 0)],
55+
[AccountConfig(0, 0), AccountConfig(0, 0), AccountConfig(0, 0)],
56+
],
57+
ids=[
58+
"One EOA",
59+
"Two EOAs",
60+
"Three EOAs",
4461
],
4562
)
4663
@pytest.mark.parametrize(
47-
"num_accounts",
64+
"fill_first_block, stride",
4865
[
49-
1,
50-
2,
51-
3,
52-
4,
66+
(False, 3),
67+
(True, 3),
5368
],
5469
)
55-
def test_eoa(blockchain_test: BlockchainTestFiller, stride: int, num_accounts: int):
70+
def test_conversions(
71+
blockchain_test: BlockchainTestFiller,
72+
account_configs: list[AccountConfig],
73+
fill_first_block: bool,
74+
stride: int,
75+
):
5676
"""
57-
Test only EOA account conversion.
77+
Test conversion cases.
5878
"""
79+
conversion_units = 0
5980
pre_state = {}
60-
for i in range(num_accounts):
61-
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
62-
63-
_state_conversion(blockchain_test, pre_state, stride, math.ceil(num_accounts / stride))
64-
65-
66-
# @pytest.mark.skip("stride config not supported yet")
67-
# @pytest.mark.valid_from("EIP6800Transition")
68-
# @pytest.mark.parametrize(
69-
# "contract_length",
70-
# [
71-
# 0,
72-
# 1,
73-
# 128 * 31,
74-
# 130 * 31,
75-
# ],
76-
# ids=[
77-
# "empty",
78-
# "in_header",
79-
# "header_perfect_fit",
80-
# "bigger_than_header",
81-
# ],
82-
# )
83-
# @pytest.mark.parametrize(
84-
# "fcb, stride, num_expected_blocks",
85-
# [
86-
# (True, 1, 6),
87-
# (True, 2, 3),
88-
# (True, 3, 2),
89-
# (True, 4, 2),
90-
# (True, 5, 2),
91-
# (True, 6, 1),
92-
# (False, 1, 3),
93-
# (False, 2, 2),
94-
# (False, 3, 1),
95-
# ],
96-
# )
97-
# def test_full_contract(
98-
# blockchain_test: BlockchainTestFiller,
99-
# contract_length: int,
100-
# fcb: bool,
101-
# stride: int,
102-
# num_expected_blocks: int,
103-
# ):
104-
# """
105-
# Test contract account full/partial migration cases.
106-
# """
107-
# pre_state = {}
108-
# if not fcb:
109-
# pre_state[Account0] = Account(balance=1000)
110-
# pre_state[Account1] = Account(balance=1001)
111-
# pre_state[Account2] = Account(balance=1002)
112-
113-
# pre_state[Account3] = Account(
114-
# balance=2000,
115-
# code=Op.STOP * contract_length,
116-
# storage={0: 0x1, 1: 0x2},
117-
# )
118-
119-
# _state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
81+
if fill_first_block:
82+
for i in range(stride):
83+
conversion_units += 1
84+
pre_state[accounts[i]] = Account(balance=100 + 1000 * i)
85+
86+
for i, account_config in enumerate(account_configs, start=len(pre_state)):
87+
storage = {}
88+
for j in range(account_config.storage_slots_count):
89+
conversion_units += 1
90+
storage[j] = j
91+
92+
pre_state[accounts[i]] = Account(
93+
balance=100 + 1000 * i,
94+
code=Op.STOP * account_config.code_length,
95+
storage=storage,
96+
)
97+
conversion_units += 1 + math.ceil(account_config.code_length / 31) + len(storage)
98+
99+
_state_conversion(blockchain_test, pre_state, stride, math.ceil(conversion_units / stride))
120100

121101

122102
# @pytest.mark.skip("stride config not supported yet")

0 commit comments

Comments
 (0)