24
24
Transaction ,
25
25
add_kzg_version ,
26
26
)
27
+ from ethereum_test_tools import Opcodes as Op
27
28
28
29
from .spec import Spec , SpecHelpers , ref_spec_4844
29
30
32
33
33
34
# Timestamp of the fork
34
35
FORK_TIMESTAMP = 15_000
36
+ BASE_FEE_MAX_CHANGE_DENOMINATOR = 8
35
37
36
38
37
39
@pytest .fixture
38
- def env () -> Environment : # noqa: D103
39
- return Environment ()
40
+ def block_gas_limit (fork : Fork ) -> int : # noqa: D103
41
+ gas_limit = int (Environment ().gas_limit )
42
+ tx_gas_limit_cap = fork .transaction_gas_limit_cap ()
43
+ if tx_gas_limit_cap is not None :
44
+ # Below transaction gas limit cap to reach gas limit easily
45
+ gas_limit = min (gas_limit , tx_gas_limit_cap * 2 )
46
+ return gas_limit
47
+
48
+
49
+ @pytest .fixture
50
+ def genesis_environment (block_gas_limit : int , block_base_fee_per_gas : int ) -> Environment : # noqa: D103
51
+ return Environment (
52
+ base_fee_per_gas = (block_base_fee_per_gas * BASE_FEE_MAX_CHANGE_DENOMINATOR ) // 7 ,
53
+ gas_limit = block_gas_limit ,
54
+ )
40
55
41
56
42
57
@pytest .fixture
@@ -57,16 +72,33 @@ def post_fork_blobs_per_block(fork: Fork) -> int:
57
72
def pre_fork_blocks (
58
73
pre_fork_blobs_per_block : int ,
59
74
destination_account : Address ,
75
+ gas_spender_account : Address ,
60
76
sender : EOA ,
61
77
fork : Fork ,
78
+ block_base_fee_per_gas : int ,
79
+ block_gas_limit : int ,
62
80
) -> List [Block ]:
63
81
"""Generate blocks to reach the fork."""
64
82
blocks = []
65
- nonce = 0
66
83
67
84
for t in range (999 , FORK_TIMESTAMP , 1_000 ):
85
+ remaining_gas = block_gas_limit // 2
68
86
if pre_fork_blobs_per_block == 0 :
69
- blocks .append (Block (txs = [], timestamp = t ))
87
+ blocks .append (
88
+ Block (
89
+ txs = [
90
+ Transaction (
91
+ to = gas_spender_account ,
92
+ value = 0 ,
93
+ gas_limit = remaining_gas ,
94
+ max_fee_per_gas = 1_000_000 ,
95
+ max_priority_fee_per_gas = 10 ,
96
+ sender = sender ,
97
+ )
98
+ ],
99
+ timestamp = t ,
100
+ )
101
+ )
70
102
continue
71
103
72
104
# Split into multi txs for forks where max per tx < max per block
@@ -77,12 +109,13 @@ def pre_fork_blocks(
77
109
78
110
while remaining_blobs > 0 :
79
111
tx_blobs = min (remaining_blobs , max_blobs_per_tx )
112
+ blob_tx_gas_limit = 21_000
80
113
txs .append (
81
114
Transaction (
82
115
ty = Spec .BLOB_TX_TYPE ,
83
116
to = destination_account ,
84
117
value = 1 ,
85
- gas_limit = 3_000_000 ,
118
+ gas_limit = blob_tx_gas_limit ,
86
119
max_fee_per_gas = 1_000_000 ,
87
120
max_priority_fee_per_gas = 10 ,
88
121
max_fee_per_blob_gas = 100 ,
@@ -92,14 +125,25 @@ def pre_fork_blocks(
92
125
Spec .BLOB_COMMITMENT_VERSION_KZG ,
93
126
),
94
127
sender = sender ,
95
- nonce = nonce ,
96
128
)
97
129
)
98
- nonce += 1
130
+ remaining_gas -= blob_tx_gas_limit
99
131
blob_index += tx_blobs
100
132
remaining_blobs -= tx_blobs
101
-
102
- blocks .append (Block (txs = txs , timestamp = t ))
133
+ txs .append (
134
+ Transaction (
135
+ to = gas_spender_account ,
136
+ value = 0 ,
137
+ gas_limit = remaining_gas ,
138
+ max_fee_per_gas = 1_000_000 ,
139
+ max_priority_fee_per_gas = 10 ,
140
+ sender = sender ,
141
+ )
142
+ )
143
+ block = Block (
144
+ txs = txs , timestamp = t , header_verify = Header (base_fee_per_gas = block_base_fee_per_gas )
145
+ )
146
+ blocks .append (block )
103
147
return blocks
104
148
105
149
@@ -137,6 +181,12 @@ def destination_account(pre: Alloc) -> Address: # noqa: D103
137
181
return pre .fund_eoa (amount = 0 )
138
182
139
183
184
+ @pytest .fixture
185
+ def gas_spender_account (pre : Alloc ) -> Address : # noqa: D103
186
+ # Account that when called consumes the entirety of the transaction's gas
187
+ return pre .deploy_contract (code = Op .INVALID )
188
+
189
+
140
190
@pytest .fixture
141
191
def fork_block_excess_blob_gas (
142
192
fork : Fork ,
@@ -167,15 +217,16 @@ def post_fork_blocks(
167
217
):
168
218
"""Generate blocks after the fork."""
169
219
blocks = []
170
- nonce = sum (len (block .txs ) for block in pre_fork_blocks )
171
220
172
221
for i in range (post_fork_block_count ):
173
222
if post_fork_blobs_per_block == 0 :
174
223
if i == 0 :
175
224
blocks .append (
176
225
Block (
177
226
txs = [],
178
- excess_blob_gas = fork_block_excess_blob_gas ,
227
+ header_verify = Header (
228
+ excess_blob_gas = fork_block_excess_blob_gas ,
229
+ ),
179
230
)
180
231
)
181
232
else :
@@ -194,7 +245,7 @@ def post_fork_blocks(
194
245
ty = Spec .BLOB_TX_TYPE ,
195
246
to = destination_account ,
196
247
value = 1 ,
197
- gas_limit = 3_000_000 ,
248
+ gas_limit = 100_000 ,
198
249
max_fee_per_gas = 1_000_000 ,
199
250
max_priority_fee_per_gas = 10 ,
200
251
max_fee_per_blob_gas = 100 ,
@@ -203,18 +254,18 @@ def post_fork_blocks(
203
254
Spec .BLOB_COMMITMENT_VERSION_KZG ,
204
255
),
205
256
sender = sender ,
206
- nonce = nonce ,
207
257
)
208
258
)
209
- nonce += 1
210
259
blob_index += tx_blobs
211
260
remaining_blobs -= tx_blobs
212
261
213
262
if i == 0 :
214
263
blocks .append (
215
264
Block (
216
265
txs = txs ,
217
- excess_blob_gas = fork_block_excess_blob_gas ,
266
+ header_verify = Header (
267
+ excess_blob_gas = fork_block_excess_blob_gas ,
268
+ ),
218
269
)
219
270
)
220
271
else :
@@ -438,7 +489,7 @@ def test_fork_transition_excess_blob_gas_at_blob_genesis(
438
489
@pytest .mark .parametrize ("block_base_fee_per_gas" , [7 , 16 , 23 ])
439
490
def test_fork_transition_excess_blob_gas_post_blob_genesis (
440
491
blockchain_test : BlockchainTestFiller ,
441
- env : Environment ,
492
+ genesis_environment : Environment ,
442
493
pre : Alloc ,
443
494
pre_fork_blocks : List [Block ],
444
495
post_fork_blocks : List [Block ],
@@ -449,5 +500,5 @@ def test_fork_transition_excess_blob_gas_post_blob_genesis(
449
500
pre = pre ,
450
501
post = post ,
451
502
blocks = pre_fork_blocks + post_fork_blocks ,
452
- genesis_environment = env ,
503
+ genesis_environment = genesis_environment ,
453
504
)
0 commit comments