Skip to content

Commit 3f4b674

Browse files
committed
test
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 8fc19ef commit 3f4b674

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

tests/verkle/eip7748/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
abstract: Tests [EIP-7748: State conversion to Verkle Tree]
3+
(https://eips.ethereum.org/EIPS/eip-7748)
4+
Tests for [EIP-7748: State conversion to Verkle Tree]
5+
(https://eips.ethereum.org/EIPS/eip-7748).
6+
"""

tests/verkle/eip7748/accounts.py

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
"""
2+
abstract: Tests [EIP-7748: State conversion to Verkle Tree]
3+
(https://eips.ethereum.org/EIPS/eip-7748)
4+
Tests for [EIP-7748: State conversion to Verkle Tree]
5+
(https://eips.ethereum.org/EIPS/eip-7748).
6+
"""
7+
8+
import pytest
9+
10+
from ethereum_test_tools import (
11+
Account,
12+
Address,
13+
Block,
14+
BlockchainTestFiller,
15+
Environment,
16+
)
17+
from ethereum_test_tools.vm.opcode import Opcodes as Op
18+
19+
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7748.md"
20+
REFERENCE_SPEC_VERSION = "TODO"
21+
22+
# List of addressed ordered by MPT tree key.
23+
# 03601462093b5945d1676df093446790fd31b20e7b12a2e8e5e09d068109616b
24+
Account0 = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")
25+
# 0e195438d9f92eb191032b5f660d42a22255c9c417248f092c1f83f3a36b29ba
26+
Account1 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0e")
27+
# 6a7fc6037f7a0dca7004c2cd41d87bfd929be7eb0d31903b238839e8e7aaf897
28+
Account2 = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0a")
29+
# 6a8737909ea3e92b0d47328d70aff338c526832b32362eca8692126c1f399846
30+
Account3 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0d")
31+
# d3bd43970708294fd4d78893c4e7c2fed43c8cd505e9c9516e1f11e79f574598
32+
Account4 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0f")
33+
34+
35+
@pytest.mark.valid_from("Verkle")
36+
@pytest.mark.parametrize(
37+
"stride, num_expected_blocks",
38+
[
39+
(1, 3),
40+
(2, 2),
41+
(3, 1),
42+
],
43+
)
44+
def test_eoa(blockchain_test: BlockchainTestFiller, stride: int, num_expected_blocks: int):
45+
"""
46+
Test only EOA account conversion.
47+
"""
48+
pre_state = {
49+
Account0: Account(balance=1000),
50+
Account1: Account(balance=2000),
51+
Account2: Account(balance=3000),
52+
}
53+
_state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
54+
55+
56+
@pytest.mark.valid_from("Verkle")
57+
@pytest.mark.parametrize(
58+
"contract_length",
59+
[
60+
0,
61+
1,
62+
128 * 31,
63+
130 * 31,
64+
],
65+
ids=[
66+
"empty",
67+
"in_header",
68+
"header_perfect_fit",
69+
"bigger_than_header",
70+
],
71+
)
72+
@pytest.mark.parametrize(
73+
"fcb, stride, num_expected_blocks",
74+
[
75+
(True, 1, 6),
76+
(True, 2, 3),
77+
(True, 3, 2),
78+
(True, 4, 2),
79+
(True, 5, 2),
80+
(True, 6, 1),
81+
(False, 1, 3),
82+
(False, 2, 2),
83+
(False, 3, 1),
84+
],
85+
)
86+
def test_full_contract(
87+
blockchain_test: BlockchainTestFiller,
88+
contract_length: int,
89+
fcb: bool,
90+
stride: int,
91+
num_expected_blocks: int,
92+
):
93+
"""
94+
Test contract account full/partial migration cases.
95+
"""
96+
pre_state = {}
97+
if not fcb:
98+
pre_state[Account0] = Account(balance=1000)
99+
pre_state[Account1] = Account(balance=1001)
100+
pre_state[Account2] = Account(balance=1002)
101+
102+
pre_state[Account3] = Account(
103+
balance=2000,
104+
code=Op.STOP * contract_length,
105+
storage={0: 0x1, 1: 0x2},
106+
)
107+
108+
_state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
109+
110+
111+
@pytest.mark.valid_from("Verkle")
112+
@pytest.mark.parametrize(
113+
"fcb, stride, num_expected_blocks",
114+
[
115+
(True, 1, 2),
116+
(True, 2, 1),
117+
(False, 1, 1),
118+
(False, 2, 1),
119+
],
120+
)
121+
def test_empty_account(
122+
blockchain_test: BlockchainTestFiller,
123+
fcb: bool,
124+
stride: int,
125+
num_expected_blocks: int,
126+
):
127+
"""
128+
Test EIP-161 accounts.
129+
"""
130+
pre_state = {}
131+
if not fcb:
132+
pre_state[Account0] = Account(balance=1000)
133+
134+
# Empty account (EIP-161)
135+
pre_state[Account1] = Account(
136+
balance=0,
137+
nonce=0,
138+
storage={0: 0x1, 1: 0x2},
139+
)
140+
141+
pre_state[Account2] = Account(balance=1001)
142+
143+
_state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
144+
145+
146+
@pytest.mark.valid_from("Verkle")
147+
@pytest.mark.parametrize(
148+
"fcb, stride, num_expected_blocks",
149+
[
150+
(True, 1, 2),
151+
(True, 2, 1),
152+
(False, 1, 1),
153+
],
154+
)
155+
def test_last_conversion_block(
156+
blockchain_test: BlockchainTestFiller,
157+
fcb: bool,
158+
stride: int,
159+
num_expected_blocks: int,
160+
):
161+
"""
162+
Test last conversion block scenario.
163+
"""
164+
pre_state = {}
165+
if not fcb:
166+
pre_state[Account0] = Account(balance=1000)
167+
168+
# Empty account (EIP-161)
169+
pre_state[Account1] = Account(
170+
balance=0,
171+
nonce=0,
172+
storage={0: 0x1, 1: 0x2},
173+
)
174+
175+
_state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
176+
177+
178+
def _state_conversion(
179+
blockchain_test: BlockchainTestFiller,
180+
pre_state: dict[Address, Account],
181+
stride: int,
182+
num_expected_blocks: int,
183+
):
184+
# TODO: test library should allow passing stride
185+
env = Environment(
186+
fee_recipient="0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
187+
difficulty=0x20000,
188+
gas_limit=10000000000,
189+
)
190+
191+
blocks: list[Block] = []
192+
for i in range(num_expected_blocks):
193+
blocks.append(Block(txs=[]))
194+
195+
# TODO: witness assertion
196+
# TODO: see if possible last block switch to finished conversion
197+
198+
blockchain_test(
199+
genesis_environment=env,
200+
pre=pre_state,
201+
post=pre_state.copy(),
202+
blocks=blocks,
203+
)

0 commit comments

Comments
 (0)