Skip to content

Commit 2a0b3d3

Browse files
committed
feat(tests): make execute blob tests client agnostic.
1 parent 1109bfb commit 2a0b3d3

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

tests/osaka/eip7594_peerdas/test_get_blobs.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""
2-
abstract: Tests get blobs engine endpoint for [EIP-4844: Shard Blob Transactions](https://eips.ethereum.org/EIPS/eip-4844)
3-
Test get blobs engine endpoint for [EIP-4844: Shard Blob Transactions](https://eips.ethereum.org/EIPS/eip-4844).
2+
abstract: Tests get blobs engine endpoint for [EIP-7594: PeerDAS - Peer Data Availability Sampling](https://eips.ethereum.org/EIPS/eip-7594)
3+
Test get blobs engine endpoint for [EIP-7594: PeerDAS - Peer Data Availability Sampling](https://eips.ethereum.org/EIPS/eip-7594).
44
55
""" # noqa: E501
66

77
from typing import List, Optional
88

99
import pytest
10+
from hive.client import ClientType
1011

11-
from ethereum_test_forks import Fork
12+
from ethereum_test_forks import Fork, Osaka
1213
from ethereum_test_tools import (
1314
Address,
1415
Alloc,
@@ -137,25 +138,20 @@ def tx_max_fee_per_blob_gas( # noqa: D103
137138
return blob_gas_price
138139

139140

140-
@pytest.fixture
141-
def tx_error() -> Optional[TransactionException]:
142-
"""
143-
Even though the final block we are producing in each of these tests is invalid, and some of the
144-
transactions will be invalid due to the format in the final block, none of the transactions
145-
should be rejected by the transition tool because they are being sent to it with the correct
146-
format.
147-
"""
148-
return None
149-
150-
151141
@pytest.fixture
152142
def tx_wrapper_version() -> int | None:
153143
"""Return wrapper version used for the transactions sent during test."""
154144
return 1
155145

156146

147+
@pytest.fixture
148+
def txs_blobs(test_case_id) -> List[List[Blob]]:
149+
"""Extract blobs from the resolved test case."""
150+
return test_case_id.values[0]
151+
152+
157153
@pytest.fixture(autouse=True)
158-
def txs( # noqa: D103
154+
def txs(
159155
pre: Alloc,
160156
destination_account: Optional[Address],
161157
tx_gas: int,
@@ -193,15 +189,26 @@ def txs( # noqa: D103
193189
return txs
194190

195191

192+
def get_max_blobs_per_tx(fork: Fork, client_type: Optional[ClientType] = None) -> int:
193+
"""Get max blobs per tx considering both fork and client."""
194+
# https://github.com/ethereum/go-ethereum/issues/31792
195+
# https://github.com/ethereum/go-ethereum/pull/31837
196+
if client_type and "go-ethereum" in client_type.name and fork >= Osaka:
197+
return 7
198+
return fork.max_blobs_per_block()
199+
200+
196201
def generate_full_blob_tests(
197202
fork: Fork,
203+
client_type: Optional[ClientType] = None,
198204
) -> List:
199205
"""
200206
Return a list of tests for invalid blob transactions due to insufficient max fee per blob gas
201207
parametrized for each different fork.
202208
"""
203209
blob_size = Spec4844.FIELD_ELEMENTS_PER_BLOB * SpecHelpers.BYTES_PER_FIELD_ELEMENT
204-
max_blobs = fork.max_blobs_per_block()
210+
max_blobs_per_block = fork.max_blobs_per_block()
211+
max_blobs_per_tx = get_max_blobs_per_tx(fork, client_type)
205212
return [
206213
pytest.param(
207214
[ # Txs
@@ -223,7 +230,7 @@ def generate_full_blob_tests(
223230
kzg_commitment=INF_POINT,
224231
kzg_cell_proofs=[INF_POINT] * CELLS_PER_EXT_BLOB,
225232
)
226-
for _ in range(max_blobs)
233+
for _ in range(max_blobs_per_tx)
227234
]
228235
],
229236
id="max_blobs_transaction",
@@ -237,19 +244,38 @@ def generate_full_blob_tests(
237244
kzg_cell_proofs=[INF_POINT] * CELLS_PER_EXT_BLOB,
238245
)
239246
]
240-
for _ in range(max_blobs)
247+
for _ in range(max_blobs_per_block)
241248
],
242249
id="single_blob_max_txs",
243250
),
244251
]
245252

246253

247-
@pytest.mark.parametrize_by_fork(
248-
"txs_blobs",
249-
generate_full_blob_tests,
254+
@pytest.fixture
255+
def test_id_matcher(request, fork: Fork, client_type: ClientType):
256+
"""
257+
Match test case ID to actual test case for client aware test execution.
258+
This runs at test execution time when we have access to both the fork and client type.
259+
"""
260+
requested_id = request.param
261+
all_test_cases = generate_full_blob_tests(fork, client_type)
262+
for test_case in all_test_cases:
263+
if test_case.id == requested_id:
264+
return test_case
265+
raise ValueError(f"Test case {requested_id} not found")
266+
267+
268+
@pytest.mark.parametrize(
269+
"test_id_matcher",
270+
[
271+
"single_blob_transaction",
272+
"max_blobs_transaction",
273+
"single_blob_max_txs",
274+
],
275+
indirect=True,
250276
)
251-
@pytest.mark.exception_test
252277
@pytest.mark.valid_from("Cancun")
278+
@pytest.mark.exception_test # TODO: should we rename this to not be exception test
253279
def test_get_blobs(
254280
blobs_test: BlobsTestFiller,
255281
pre: Alloc,
@@ -259,7 +285,4 @@ def test_get_blobs(
259285
Test valid blob combinations where one or more txs in the block
260286
serialized version contain a full blob (network version) tx.
261287
"""
262-
blobs_test(
263-
pre=pre,
264-
txs=txs,
265-
)
288+
blobs_test(pre=pre, txs=txs)

0 commit comments

Comments
 (0)