Skip to content

Commit 4f3a83b

Browse files
committed
fix(tests): EIP-4844, EIP-7691: Refactor EIP-4844 tests to use dynamic blob parameters
1 parent 8b1dab7 commit 4f3a83b

File tree

11 files changed

+756
-653
lines changed

11 files changed

+756
-653
lines changed

tests/cancun/eip4788_beacon_root/conftest.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,10 @@
77

88
import pytest
99

10-
from ethereum_test_tools import (
11-
AccessList,
12-
Account,
13-
Address,
14-
Alloc,
15-
Bytecode,
16-
Environment,
17-
Hash,
18-
Storage,
19-
Transaction,
20-
add_kzg_version,
21-
keccak256,
22-
)
23-
from ethereum_test_tools.vm.opcode import Opcodes as Op
10+
from ethereum_test_forks import Fork
11+
from ethereum_test_tools import AccessList, Account, Address, Alloc, Bytecode, Environment, Hash
12+
from ethereum_test_tools import Opcodes as Op
13+
from ethereum_test_tools import Storage, Transaction, add_kzg_version, keccak256
2414

2515
from .spec import Spec, SpecHelpers
2616

@@ -232,6 +222,7 @@ def tx_type() -> int:
232222
@pytest.fixture
233223
def tx(
234224
pre: Alloc,
225+
fork: Fork,
235226
tx_to_address: Address,
236227
tx_data: bytes,
237228
tx_type: int,
@@ -254,7 +245,7 @@ def tx(
254245
kwargs["access_list"] = access_list
255246

256247
if tx_type == 3:
257-
kwargs["max_fee_per_blob_gas"] = 1
248+
kwargs["max_fee_per_blob_gas"] = fork.min_base_fee_per_blob_gas()
258249
kwargs["blob_versioned_hashes"] = add_kzg_version([0], BLOB_COMMITMENT_VERSION_KZG)
259250

260251
if tx_type > 3:

tests/cancun/eip4844_blobs/common.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from ethereum_test_tools.vm.opcode import Opcodes as Op
1616

17-
from .spec import Spec, SpecHelpers
17+
from .spec import Spec
1818

1919
INF_POINT = (0xC0 << 376).to_bytes(48, byteorder="big")
2020
Z = 0x623CE31CF9759A5C8DAF3A357992F9F3DD7F9339D8998BC8E68373E54F00B75E
@@ -57,12 +57,6 @@ def blobs_to_transaction_input(
5757
return (blobs, kzg_commitments, kzg_proofs)
5858

5959

60-
# Simple list of blob versioned hashes ranging from bytes32(1 to 4)
61-
simple_blob_hashes: list[bytes] = add_kzg_version(
62-
[(1 << x) for x in range(SpecHelpers.max_blobs_per_block())],
63-
Spec.BLOB_COMMITMENT_VERSION_KZG,
64-
)
65-
6660
# Random fixed list of blob versioned hashes
6761
random_blob_hashes = add_kzg_version(
6862
[
@@ -284,7 +278,7 @@ class BlobhashScenario:
284278
"""
285279

286280
@staticmethod
287-
def create_blob_hashes_list(length: int) -> list[list[bytes]]:
281+
def create_blob_hashes_list(length: int, max_blobs_per_block: int) -> list[list[bytes]]:
288282
"""
289283
Creates a list of MAX_BLOBS_PER_BLOCK blob hashes
290284
using `random_blob_hashes`.
@@ -293,20 +287,20 @@ def create_blob_hashes_list(length: int) -> list[list[bytes]]:
293287
length: MAX_BLOBS_PER_BLOCK * length
294288
-> [0x01, 0x02, 0x03, 0x04, ..., 0x0A, 0x0B, 0x0C, 0x0D]
295289
296-
Then split list into smaller chunks of SpecHelpers.max_blobs_per_block()
290+
Then split list into smaller chunks of max_blobs_per_block
297291
-> [[0x01, 0x02, 0x03, 0x04], ..., [0x0a, 0x0b, 0x0c, 0x0d]]
298292
"""
299293
b_hashes = [
300294
random_blob_hashes[i % len(random_blob_hashes)]
301-
for i in range(SpecHelpers.max_blobs_per_block() * length)
295+
for i in range(max_blobs_per_block * length)
302296
]
303297
return [
304-
b_hashes[i : i + SpecHelpers.max_blobs_per_block()]
305-
for i in range(0, len(b_hashes), SpecHelpers.max_blobs_per_block())
298+
b_hashes[i : i + max_blobs_per_block]
299+
for i in range(0, len(b_hashes), max_blobs_per_block)
306300
]
307301

308302
@staticmethod
309-
def blobhash_sstore(index: int):
303+
def blobhash_sstore(index: int, max_blobs_per_block: int):
310304
"""
311305
Returns an BLOBHASH sstore to the given index.
312306
@@ -315,35 +309,38 @@ def blobhash_sstore(index: int):
315309
the BLOBHASH sstore.
316310
"""
317311
invalidity_check = Op.SSTORE(index, 0x01)
318-
if index < 0 or index >= SpecHelpers.max_blobs_per_block():
312+
if index < 0 or index >= max_blobs_per_block:
319313
return invalidity_check + Op.SSTORE(index, Op.BLOBHASH(index))
320314
return Op.SSTORE(index, Op.BLOBHASH(index))
321315

322316
@classmethod
323-
def generate_blobhash_bytecode(cls, scenario_name: str) -> bytes:
317+
def generate_blobhash_bytecode(cls, scenario_name: str, max_blobs_per_block: int) -> bytes:
324318
"""
325319
Returns BLOBHASH bytecode for the given scenario.
326320
"""
327321
scenarios = {
328322
"single_valid": sum(
329-
cls.blobhash_sstore(i) for i in range(SpecHelpers.max_blobs_per_block())
323+
cls.blobhash_sstore(i, max_blobs_per_block) for i in range(max_blobs_per_block)
330324
),
331325
"repeated_valid": sum(
332-
sum(cls.blobhash_sstore(i) for _ in range(10))
333-
for i in range(SpecHelpers.max_blobs_per_block())
326+
sum(cls.blobhash_sstore(i, max_blobs_per_block) for _ in range(10))
327+
for i in range(max_blobs_per_block)
334328
),
335329
"valid_invalid": sum(
336-
cls.blobhash_sstore(i)
337-
+ cls.blobhash_sstore(SpecHelpers.max_blobs_per_block())
338-
+ cls.blobhash_sstore(i)
339-
for i in range(SpecHelpers.max_blobs_per_block())
330+
cls.blobhash_sstore(i, max_blobs_per_block)
331+
+ cls.blobhash_sstore(max_blobs_per_block, max_blobs_per_block)
332+
+ cls.blobhash_sstore(i, max_blobs_per_block)
333+
for i in range(max_blobs_per_block)
340334
),
341335
"varied_valid": sum(
342-
cls.blobhash_sstore(i) + cls.blobhash_sstore(i + 1) + cls.blobhash_sstore(i)
343-
for i in range(SpecHelpers.max_blobs_per_block() - 1)
336+
cls.blobhash_sstore(i, max_blobs_per_block)
337+
+ cls.blobhash_sstore(i + 1, max_blobs_per_block)
338+
+ cls.blobhash_sstore(i, max_blobs_per_block)
339+
for i in range(max_blobs_per_block - 1)
344340
),
345341
"invalid_calls": sum(
346-
cls.blobhash_sstore(i) for i in range(-5, SpecHelpers.max_blobs_per_block() + 5)
342+
cls.blobhash_sstore(i, max_blobs_per_block)
343+
for i in range(-5, max_blobs_per_block + 5)
347344
),
348345
}
349346
scenario = scenarios.get(scenario_name)

0 commit comments

Comments
 (0)