|
3 | 3 | Tests uncoupled blob txs for [EIP-7742: Uncouple blob count between CL and EL](https://eips.ethereum.org/EIPS/eip-7742) |
4 | 4 | """ # noqa: E501 |
5 | 5 |
|
6 | | -from typing import List, Optional |
7 | | - |
8 | 6 | import pytest |
9 | 7 |
|
10 | | -from ethereum_test_tools import ( |
11 | | - Alloc, |
12 | | - Block, |
13 | | - BlockchainTestFiller, |
14 | | - Environment, |
15 | | - Hash, |
16 | | - StateTestFiller, |
17 | | - Transaction, |
18 | | - add_kzg_version, |
19 | | -) |
| 8 | +from ethereum_test_tools import Alloc, Environment, StateTestFiller, Transaction |
20 | 9 |
|
21 | 10 | from .spec import Spec, ref_spec_7742 |
22 | 11 |
|
@@ -92,164 +81,3 @@ def test_large_number_of_blobs_in_tx( |
92 | 81 | tx=txs[0], |
93 | 82 | env=state_env, |
94 | 83 | ) |
95 | | - |
96 | | - |
97 | | -def multiple_blocks_with_blobs( |
98 | | - txs: List[Transaction], |
99 | | - blob_counts_per_block: List[int], |
100 | | - tx_counts_per_block: Optional[List[int]] = None, |
101 | | -) -> List[Block]: |
102 | | - """ |
103 | | - Creates multiple blocks with blob transactions. If `tx_counts_per_block` is not provided, |
104 | | - it defaults to 1 transaction per block, resulting in multiple blocks with a single blob |
105 | | - transaction. |
106 | | -
|
107 | | - Otherwise, the number of transactions in each block is specified by `tx_counts_per_block`. |
108 | | - This means we will have multiple blocks with multiple blob transactions, where the number of |
109 | | - blobs in each transaction is determined by the total blob count for the block. |
110 | | - """ |
111 | | - if tx_counts_per_block is None: |
112 | | - tx_counts_per_block = [1] * len(blob_counts_per_block) |
113 | | - |
114 | | - if len(blob_counts_per_block) != len(tx_counts_per_block): |
115 | | - raise ValueError( |
116 | | - "The lengths of `blob_counts_per_block` and `tx_counts_per_block` must match." |
117 | | - ) |
118 | | - |
119 | | - blocks = [] |
120 | | - for block_index, (total_blob_count, tx_count) in enumerate( |
121 | | - zip(blob_counts_per_block, tx_counts_per_block) |
122 | | - ): |
123 | | - txs_in_block = [] |
124 | | - base_blobs_per_tx = total_blob_count // tx_count |
125 | | - remaining_blobs = total_blob_count % tx_count |
126 | | - |
127 | | - for tx_index in range(tx_count): |
128 | | - tx = txs[0].copy() |
129 | | - # Number of blobs for this transaction |
130 | | - tx_blob_count = base_blobs_per_tx + (1 if tx_index < remaining_blobs else 0) |
131 | | - # Create a list of blob hashes for this transaction |
132 | | - blob_hashes = add_kzg_version( |
133 | | - [Hash(block_index * 10000 + tx_index * 100 + i) for i in range(tx_blob_count)], |
134 | | - Spec.BLOB_COMMITMENT_VERSION_KZG, |
135 | | - ) |
136 | | - tx.blob_versioned_hashes = [Hash(b_hash) for b_hash in blob_hashes] |
137 | | - txs_in_block.append(tx) |
138 | | - |
139 | | - block = Block(txs=txs_in_block) |
140 | | - blocks.append(block) |
141 | | - |
142 | | - return blocks |
143 | | - |
144 | | - |
145 | | -@pytest.mark.parametrize( |
146 | | - "total_blob_counts, tx_counts_per_block, account_balance_modifier", |
147 | | - [ |
148 | | - # 10 blobs over 2 txs, 20 blobs over 4 txs |
149 | | - ( |
150 | | - [10, 20], |
151 | | - [2, 4], |
152 | | - 10**18, |
153 | | - ), |
154 | | - # 30 blobs over 3 txs, 60 blobs over 6 txs, 90 blobs over 9 txs |
155 | | - ( |
156 | | - [30, 60, 90], |
157 | | - [3, 6, 9], |
158 | | - 10**18, |
159 | | - ), |
160 | | - # 50 blobs over 5 txs, 100 blobs over 10 txs, 150 blobs over 15 txs, 200 blobs over 20 txs |
161 | | - ( |
162 | | - [50, 100, 150, 200], |
163 | | - [5, 10, 15, 20], |
164 | | - 10**18, |
165 | | - ), |
166 | | - ], |
167 | | -) |
168 | | -@pytest.mark.valid_from("Prague") |
169 | | -def test_multiple_blocks_varied_blobs( |
170 | | - blockchain_test: BlockchainTestFiller, |
171 | | - pre: Alloc, |
172 | | - env: Environment, |
173 | | - txs: List[Transaction], |
174 | | - total_blob_counts: List[int], |
175 | | - tx_counts_per_block: List[int], |
176 | | -): |
177 | | - """ |
178 | | - Test multiple blocks with varied transactions and blob counts per block. |
179 | | - """ |
180 | | - blockchain_test( |
181 | | - pre=pre, |
182 | | - post={}, |
183 | | - blocks=multiple_blocks_with_blobs(txs, total_blob_counts, tx_counts_per_block), |
184 | | - genesis_environment=env, |
185 | | - ) |
186 | | - |
187 | | - |
188 | | -@pytest.mark.parametrize( |
189 | | - "blob_counts_per_block, tx_counts_per_block, account_balance_modifier", |
190 | | - [ |
191 | | - # Incremental 1: 0 to 64 blobs, 1 tx per block, 64 blocks |
192 | | - ( |
193 | | - [i for i in range(65)], |
194 | | - [1] * 65, |
195 | | - 10**18, |
196 | | - ), |
197 | | - # Incremental 2: 0 to 256 blobs, 10 txs per block, 26 blocks |
198 | | - ( |
199 | | - [i * 10 for i in range(26)], |
200 | | - [10] * 26, |
201 | | - 10**18, |
202 | | - ), |
203 | | - # Decremental 1: 64 to 0 blobs, 1 tx per block, 64 blocks |
204 | | - ( |
205 | | - [i for i in reversed(range(65))], |
206 | | - [1] * 65, |
207 | | - 10**18, |
208 | | - ), |
209 | | - # Decremental 2: 256 to 0 blobs, 10 txs per block, 26 blocks |
210 | | - ( |
211 | | - [i * 10 for i in reversed(range(26))], |
212 | | - [10] * 26, |
213 | | - 10**18, |
214 | | - ), |
215 | | - # Incremental then decremental 1: 0 to 64 to 0 blobs, 1 tx per block, 130 blocks |
216 | | - ( |
217 | | - [i for i in range(65)] + [i for i in reversed(range(65))], |
218 | | - [1] * 130, |
219 | | - 10**18, |
220 | | - ), |
221 | | - # Decremental then incremental 1: 64 to 0 to 64 blobs, 1 tx per block, 130 blocks |
222 | | - ( |
223 | | - [i for i in reversed(range(65))] + [i for i in range(65)], |
224 | | - [1] * 130, |
225 | | - 10**18, |
226 | | - ), |
227 | | - ], |
228 | | - ids=[ |
229 | | - "incremental_1_tx", |
230 | | - "incremental_10_txs", |
231 | | - "decremental_1_tx", |
232 | | - "decremental_10_txs", |
233 | | - "incremental_then_decremental", |
234 | | - "decremental_then_incremental", |
235 | | - ], |
236 | | -) |
237 | | -@pytest.mark.valid_from("Prague") |
238 | | -def test_multi_blocks_incremental_decremental( |
239 | | - blockchain_test: BlockchainTestFiller, |
240 | | - pre: Alloc, |
241 | | - env: Environment, |
242 | | - txs: List[Transaction], |
243 | | - blob_counts_per_block: List[int], |
244 | | - tx_counts_per_block: List[int], |
245 | | -): |
246 | | - """ |
247 | | - Test multiple blocks with incremental, decremental, and ascending-then-descending |
248 | | - blob counts per block. |
249 | | - """ |
250 | | - blockchain_test( |
251 | | - pre=pre, |
252 | | - post={}, |
253 | | - blocks=multiple_blocks_with_blobs(txs, blob_counts_per_block, tx_counts_per_block), |
254 | | - genesis_environment=env, |
255 | | - ) |
0 commit comments