Skip to content

Commit c97902a

Browse files
committed
eip7748: add eoa test cases
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent c5205f6 commit c97902a

File tree

1 file changed

+144
-131
lines changed

1 file changed

+144
-131
lines changed

tests/verkle/eip7748/accounts.py

Lines changed: 144 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"""
77

88
import pytest
9+
import math
10+
import sys
911

1012
from ethereum_test_tools import (
1113
Account,
@@ -31,155 +33,166 @@
3133
# d3bd43970708294fd4d78893c4e7c2fed43c8cd505e9c9516e1f11e79f574598
3234
Account4 = Address("0xd94f5374fce5edbc8e2a8697c15331677e6ebf0f")
3335

36+
accounts = [Account0, Account1, Account2, Account3, Account4]
3437

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-
)
10738

108-
_state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
109-
110-
111-
@pytest.mark.valid_from("Verkle")
39+
@pytest.mark.valid_from("EIP6800Transition")
11240
@pytest.mark.parametrize(
113-
"fcb, stride, num_expected_blocks",
41+
"stride",
11442
[
115-
(True, 1, 2),
116-
(True, 2, 1),
117-
(False, 1, 1),
118-
(False, 2, 1),
43+
3,
11944
],
12045
)
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")
14746
@pytest.mark.parametrize(
148-
"fcb, stride, num_expected_blocks",
47+
"num_accounts",
14948
[
150-
(True, 1, 2),
151-
(True, 2, 1),
152-
(False, 1, 1),
49+
1,
50+
2,
51+
3,
52+
4,
15353
],
15454
)
155-
def test_last_conversion_block(
156-
blockchain_test: BlockchainTestFiller,
157-
fcb: bool,
158-
stride: int,
159-
num_expected_blocks: int,
160-
):
55+
def test_eoa(blockchain_test: BlockchainTestFiller, stride: int, num_accounts: int):
16156
"""
162-
Test last conversion block scenario.
57+
Test only EOA account conversion.
16358
"""
16459
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)
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)
120+
121+
122+
# @pytest.mark.skip("stride config not supported yet")
123+
# @pytest.mark.valid_from("EIP6800Transition")
124+
# @pytest.mark.parametrize(
125+
# "fcb, stride, num_expected_blocks",
126+
# [
127+
# (True, 1, 2),
128+
# (True, 2, 1),
129+
# (False, 1, 1),
130+
# (False, 2, 1),
131+
# ],
132+
# )
133+
# def test_empty_account(
134+
# blockchain_test: BlockchainTestFiller,
135+
# fcb: bool,
136+
# stride: int,
137+
# num_expected_blocks: int,
138+
# ):
139+
# """
140+
# Test EIP-161 accounts.
141+
# """
142+
# pre_state = {}
143+
# if not fcb:
144+
# pre_state[Account0] = Account(balance=1000)
145+
146+
# # Empty account (EIP-161)
147+
# pre_state[Account1] = Account(
148+
# balance=0,
149+
# nonce=0,
150+
# storage={0: 0x1, 1: 0x2},
151+
# )
152+
153+
# pre_state[Account2] = Account(balance=1001)
154+
155+
# _state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
156+
157+
158+
# @pytest.mark.skip("stride config not supported yet")
159+
# @pytest.mark.valid_from("EIP6800Transition")
160+
# @pytest.mark.parametrize(
161+
# "fcb, stride, num_expected_blocks",
162+
# [
163+
# (True, 1, 2),
164+
# (True, 2, 1),
165+
# (False, 1, 1),
166+
# ],
167+
# )
168+
# def test_last_conversion_block(
169+
# blockchain_test: BlockchainTestFiller,
170+
# fcb: bool,
171+
# stride: int,
172+
# num_expected_blocks: int,
173+
# ):
174+
# """
175+
# Test last conversion block scenario.
176+
# """
177+
# pre_state = {}
178+
# if not fcb:
179+
# pre_state[Account0] = Account(balance=1000)
180+
181+
# # Empty account (EIP-161)
182+
# pre_state[Account1] = Account(
183+
# balance=0,
184+
# nonce=0,
185+
# storage={0: 0x1, 1: 0x2},
186+
# )
187+
188+
# _state_conversion(blockchain_test, pre_state, stride, num_expected_blocks)
176189

177190

178191
def _state_conversion(
179192
blockchain_test: BlockchainTestFiller,
180193
pre_state: dict[Address, Account],
181194
stride: int,
182-
num_expected_blocks: int,
195+
num_blocks: int,
183196
):
184197
# TODO: test library should allow passing stride
185198
env = Environment(
@@ -189,7 +202,7 @@ def _state_conversion(
189202
)
190203

191204
blocks: list[Block] = []
192-
for i in range(num_expected_blocks):
205+
for i in range(num_blocks):
193206
blocks.append(Block(txs=[]))
194207

195208
# TODO: witness assertion

0 commit comments

Comments
 (0)