@@ -41,11 +41,11 @@ def env() -> Environment: # noqa: D103
4141
4242
4343@pytest .fixture
44- def pre_fork_blobs_per_block (fork : Fork ) -> int | None :
44+ def pre_fork_blobs_per_block (fork : Fork ) -> int :
4545 """Amount of blobs to produce with the pre-fork rules."""
4646 if fork .supports_blobs (timestamp = 0 ):
4747 return fork .max_blobs_per_block (timestamp = 0 )
48- return None
48+ return 0
4949
5050
5151@pytest .fixture
@@ -56,13 +56,11 @@ def sender(pre: Alloc) -> EOA:
5656
5757@pytest .fixture
5858def pre_fork_blocks (
59- pre_fork_blobs_per_block : int | None ,
59+ pre_fork_blobs_per_block : int ,
6060 destination_account : Address ,
6161 sender : EOA ,
6262) -> List [Block ]:
6363 """Generate blocks to reach the fork."""
64- if pre_fork_blobs_per_block is None :
65- return [Block (timestamp = t ) for t in range (999 , FORK_TIMESTAMP , 1_000 )]
6664 return [
6765 Block (
6866 txs = [
@@ -99,6 +97,24 @@ def pre_fork_blocks(
9997 ]
10098
10199
100+ @pytest .fixture
101+ def pre_fork_excess_blobs (
102+ fork : Fork ,
103+ pre_fork_blobs_per_block : int ,
104+ pre_fork_blocks : List [Block ],
105+ ) -> int :
106+ """
107+ Return the cummulative excess blobs up until the fork given the pre_fork_blobs_per_block
108+ and the target blobs in the fork prior.
109+ """
110+ if not fork .supports_blobs (timestamp = 0 ):
111+ return 0
112+ target_blobs = fork .target_blobs_per_block (timestamp = 0 )
113+ if pre_fork_blobs_per_block > target_blobs :
114+ return (pre_fork_blobs_per_block - target_blobs ) * (len (pre_fork_blocks ) - 1 )
115+ return 0
116+
117+
102118@pytest .fixture
103119def post_fork_block_count (fork : Fork ) -> int :
104120 """Amount of blocks to produce with the post-fork rules."""
@@ -119,45 +135,69 @@ def destination_account(pre: Alloc) -> Address: # noqa: D103
119135 return pre .deploy_contract (Op .STOP )
120136
121137
138+ @pytest .fixture
139+ def fork_block_excess_blob_gas (
140+ fork : Fork ,
141+ pre_fork_excess_blobs : int ,
142+ pre_fork_blobs_per_block : int ,
143+ ) -> int :
144+ """Calculate the expected excess blob gas for the fork block."""
145+ if pre_fork_blobs_per_block == 0 :
146+ return 0
147+ calc_excess_blob_gas_post_fork = fork .excess_blob_gas_calculator (timestamp = FORK_TIMESTAMP )
148+ return calc_excess_blob_gas_post_fork (
149+ parent_excess_blobs = pre_fork_excess_blobs ,
150+ parent_blob_count = pre_fork_blobs_per_block ,
151+ )
152+
153+
122154@pytest .fixture
123155def post_fork_blocks (
124156 destination_account : Address ,
125157 post_fork_block_count : int ,
126158 post_fork_blobs_per_block : int ,
159+ fork_block_excess_blob_gas : int ,
127160 sender : EOA ,
128161):
129162 """Generate blocks past the fork."""
130- return [
131- Block (
132- txs = [
133- Transaction (
134- ty = Spec .BLOB_TX_TYPE ,
135- to = destination_account ,
136- value = 1 ,
137- gas_limit = 3_000_000 ,
138- max_fee_per_gas = 1_000_000 ,
139- max_priority_fee_per_gas = 10 ,
140- max_fee_per_blob_gas = 100 ,
141- blob_versioned_hashes = add_kzg_version (
142- [Hash (x ) for x in range (post_fork_blobs_per_block )],
143- Spec .BLOB_COMMITMENT_VERSION_KZG ,
144- ),
145- sender = sender ,
146- )
147- if post_fork_blobs_per_block > 0
148- else Transaction (
149- ty = 2 ,
150- to = destination_account ,
151- value = 1 ,
152- gas_limit = 3_000_000 ,
153- max_fee_per_gas = 1_000_000 ,
154- max_priority_fee_per_gas = 10 ,
155- sender = sender ,
163+ blocks = []
164+ for i in range (post_fork_block_count ):
165+ txs = [
166+ Transaction (
167+ ty = Spec .BLOB_TX_TYPE ,
168+ to = destination_account ,
169+ value = 1 ,
170+ gas_limit = 3_000_000 ,
171+ max_fee_per_gas = 1_000_000 ,
172+ max_priority_fee_per_gas = 10 ,
173+ max_fee_per_blob_gas = 100 ,
174+ blob_versioned_hashes = add_kzg_version (
175+ [Hash (x ) for x in range (post_fork_blobs_per_block )],
176+ Spec .BLOB_COMMITMENT_VERSION_KZG ,
177+ ),
178+ sender = sender ,
179+ )
180+ if post_fork_blobs_per_block > 0
181+ else Transaction (
182+ ty = 2 ,
183+ to = destination_account ,
184+ value = 1 ,
185+ gas_limit = 3_000_000 ,
186+ max_fee_per_gas = 1_000_000 ,
187+ max_priority_fee_per_gas = 10 ,
188+ sender = sender ,
189+ )
190+ ]
191+ if i == 0 :
192+ blocks .append (
193+ Block (
194+ txs = txs ,
195+ excess_blob_gas = fork_block_excess_blob_gas ,
156196 )
157- ],
158- )
159- for _ in range ( post_fork_block_count )
160- ]
197+ )
198+ else :
199+ blocks . append ( Block ( txs = txs ) )
200+ return blocks
161201
162202
163203@pytest .fixture
@@ -260,8 +300,7 @@ def test_invalid_post_fork_block_without_blob_fields(
260300 )
261301
262302
263- @pytest .mark .valid_from ("Cancun" )
264- @pytest .mark .fork_transition_test ()
303+ @pytest .mark .valid_at_transition_to ("Cancun" , subsequent_forks = True )
265304@pytest .mark .parametrize_by_fork (
266305 "post_fork_block_count,post_fork_blobs_per_block" ,
267306 lambda fork : [
0 commit comments