Skip to content

Commit 16316e2

Browse files
spencer-tbfselmo
andauthored
chore(test-specs): fix fork transition tests (ethereum#2065)
* chore(test-specs): fix fork transition tests * fix(test-forks): don't collect BPO tests w/ unchanged params on transition - Use `fork.excess_blob_gas_calculator` to account for fork-specific blob gas calculations. * refactor(test-forks): clearer definitions for transition forks --------- Co-authored-by: fselmo <fselmo2@gmail.com>
1 parent 6e5f1f8 commit 16316e2

7 files changed

Lines changed: 99 additions & 14 deletions

File tree

packages/testing/src/execution_testing/cli/pytest_commands/plugins/forks/forks.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,24 @@ def add_fork_covariant_parameters(
11811181
fp for fp in fork_parametrizers if fp.fork >= param_min_fork
11821182
]
11831183

1184+
# Filter out forks where blob params don't change for valid_for_bpo_forks
1185+
if list(metafunc.definition.iter_markers(name="valid_for_bpo_forks")):
1186+
filtered_forks = [
1187+
fp.fork
1188+
for fp in fork_parametrizers
1189+
if not blob_params_changed_at_transition(fp.fork)
1190+
]
1191+
if filtered_forks:
1192+
logger.debug(
1193+
f"Skipping {metafunc.function.__name__} for forks with "
1194+
f"unchanged blob params: {[f.name() for f in filtered_forks]}"
1195+
)
1196+
fork_parametrizers[:] = [
1197+
fp
1198+
for fp in fork_parametrizers
1199+
if blob_params_changed_at_transition(fp.fork)
1200+
]
1201+
11841202
for covariant_descriptor in fork_covariant_decorators:
11851203
if list(
11861204
metafunc.definition.iter_markers(covariant_descriptor.marker_name)
@@ -1272,6 +1290,48 @@ def parametrize_fork(
12721290
)
12731291

12741292

1293+
def blob_params_changed_at_transition(fork: Fork) -> bool:
1294+
"""
1295+
Check if BPO-relevant blob parameters change at a fork transition.
1296+
1297+
For transition forks, compares the 3 blob parameters that BPO forks modify
1298+
between the from_fork and to_fork:
1299+
1300+
- target_blobs_per_block
1301+
- max_blobs_per_block
1302+
- blob_base_fee_update_fraction
1303+
1304+
Returns True if any parameter changed, False otherwise.
1305+
1306+
For non-transition forks, returns True (no filtering needed).
1307+
"""
1308+
# Check if this is a transition fork
1309+
if not hasattr(fork, "transitions_from") or not hasattr(
1310+
fork, "transitions_to"
1311+
):
1312+
return True
1313+
1314+
from_fork = fork.transitions_from()
1315+
to_fork = fork.transitions_to()
1316+
1317+
# Compare the 3 blob parameters that BPO forks modify
1318+
bpo_blob_params = [
1319+
"target_blobs_per_block",
1320+
"max_blobs_per_block",
1321+
"blob_base_fee_update_fraction",
1322+
]
1323+
1324+
for param in bpo_blob_params:
1325+
from_method = getattr(from_fork, param, None)
1326+
to_method = getattr(to_fork, param, None)
1327+
if from_method is None or to_method is None:
1328+
continue
1329+
if from_method() != to_method():
1330+
return True
1331+
1332+
return False
1333+
1334+
12751335
def pytest_collection_modifyitems(
12761336
config: pytest.Config, items: List[pytest.Item]
12771337
) -> None:

packages/testing/src/execution_testing/forks/forks/transition.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
BPO2,
77
BPO3,
88
BPO4,
9+
Amsterdam,
910
Berlin,
1011
Cancun,
1112
London,
@@ -66,6 +67,17 @@ class BPO1ToBPO2AtTime15k(BPO1):
6667
pass
6768

6869

70+
@transition_fork(to_fork=Amsterdam, at_timestamp=15_000)
71+
class BPO2ToAmsterdamAtTime15k(BPO2):
72+
"""BPO2 to Amsterdam transition at Timestamp 15k."""
73+
74+
# TODO: We may need to adjust which BPO Amsterdam inherits from as the
75+
# related Amsterdam specs change over time, and before Amsterdam is
76+
# live on mainnet.
77+
78+
pass
79+
80+
6981
@transition_fork(to_fork=BPO3, at_timestamp=15_000)
7082
class BPO2ToBPO3AtTime15k(BPO2):
7183
"""BPO2 to BPO3 transition at Timestamp 15k."""

tests/cancun/eip4844_blobs/test_excess_blob_gas_fork_transition.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,36 @@ def pre_fork_blocks(
158158

159159

160160
@pytest.fixture
161-
def pre_fork_excess_blobs(
161+
def pre_fork_excess_blob_gas(
162162
fork: Fork,
163163
pre_fork_blobs_per_block: int,
164164
pre_fork_blocks: List[Block],
165+
block_base_fee_per_gas: int,
165166
) -> int:
166167
"""
167-
Return the cumulative excess blobs up until the fork given the
168-
pre_fork_blobs_per_block and the target blobs in the fork prior.
168+
Return the cumulative excess blob gas up until the fork.
169+
170+
Calculates the expected excess blob gas by iterating through pre-fork
171+
blocks using the fork's calculator, which handles EIP-7918 reserve price
172+
for >=Osaka.
169173
"""
170174
if not fork.supports_blobs(timestamp=0):
171175
return 0
172176

173-
target_blobs = fork.target_blobs_per_block(timestamp=0)
174-
if pre_fork_blobs_per_block > target_blobs:
175-
return (pre_fork_blobs_per_block - target_blobs) * (
176-
len(pre_fork_blocks) - 1
177+
calc_excess_blob_gas = fork.excess_blob_gas_calculator(timestamp=0)
178+
excess_blob_gas = 0
179+
180+
# Calculate excess accumulation for each pre-fork block
181+
# First block is built on genesis which has 0 blobs
182+
for i in range(len(pre_fork_blocks)):
183+
parent_blob_count = 0 if i == 0 else pre_fork_blobs_per_block
184+
excess_blob_gas = calc_excess_blob_gas(
185+
parent_excess_blob_gas=excess_blob_gas,
186+
parent_blob_count=parent_blob_count,
187+
parent_base_fee_per_gas=block_base_fee_per_gas,
177188
)
178-
return 0
189+
190+
return excess_blob_gas
179191

180192

181193
@pytest.fixture
@@ -204,7 +216,7 @@ def gas_spender_account(pre: Alloc) -> Address: # noqa: D103
204216
@pytest.fixture
205217
def fork_block_excess_blob_gas(
206218
fork: Fork,
207-
pre_fork_excess_blobs: int,
219+
pre_fork_excess_blob_gas: int,
208220
pre_fork_blobs_per_block: int,
209221
block_base_fee_per_gas: int,
210222
) -> int:
@@ -215,7 +227,7 @@ def fork_block_excess_blob_gas(
215227
timestamp=FORK_TIMESTAMP
216228
)
217229
return calc_excess_blob_gas_post_fork(
218-
parent_excess_blobs=pre_fork_excess_blobs,
230+
parent_excess_blob_gas=pre_fork_excess_blob_gas,
219231
parent_blob_count=pre_fork_blobs_per_block,
220232
parent_base_fee_per_gas=block_base_fee_per_gas,
221233
)
@@ -463,6 +475,7 @@ def test_fork_transition_excess_blob_gas_at_blob_genesis(
463475
)
464476

465477

478+
@pytest.mark.valid_for_bpo_forks
466479
@pytest.mark.valid_at_transition_to("Prague", subsequent_forks=True)
467480
@pytest.mark.parametrize_by_fork(
468481
"post_fork_block_count,pre_fork_blobs_per_block,post_fork_blobs_per_block",

tests/osaka/eip7823_modexp_upper_bounds/test_modexp_upper_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_modexp_upper_bounds(
283283
),
284284
],
285285
)
286-
@pytest.mark.valid_at_transition_to("Osaka", subsequent_forks=True)
286+
@pytest.mark.valid_at_transition_to("Osaka")
287287
def test_modexp_upper_bounds_fork_transition(
288288
blockchain_test: BlockchainTestFiller,
289289
pre: Alloc,

tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit_transition_fork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedBeforeFork()
2929
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedAfterFork()
3030
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedAfterFork()
31-
@pytest.mark.valid_at_transition_to("Osaka", subsequent_forks=True)
31+
@pytest.mark.valid_at_transition_to("Osaka")
3232
@pytest.mark.parametrize(
3333
"transaction_at_cap",
3434
[

tests/osaka/eip7883_modexp_gas_increase/test_modexp_thresholds_transition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
REFERENCE_SPEC_GIT_PATH = ref_spec_7883.git_path
2222
REFERENCE_SPEC_VERSION = ref_spec_7883.version
2323

24-
pytestmark = pytest.mark.valid_at_transition_to("Osaka", subsequent_forks=True)
24+
pytestmark = pytest.mark.valid_at_transition_to("Osaka")
2525

2626

2727
@pytest.mark.parametrize(

tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_clz_push_operation_same_value(
284284

285285
@EIPChecklist.Opcode.Test.ForkTransition.Invalid()
286286
@EIPChecklist.Opcode.Test.ForkTransition.At()
287-
@pytest.mark.valid_at_transition_to("Osaka", subsequent_forks=True)
287+
@pytest.mark.valid_at_transition_to("Osaka")
288288
def test_clz_fork_transition(
289289
blockchain_test: BlockchainTestFiller, pre: Alloc
290290
) -> None:

0 commit comments

Comments
 (0)