Skip to content

Commit 14ed88d

Browse files
authored
fix(tests): Restrict extra args being passed to BaseTest; fix valid BAL tests (#2102)
* - fix(fw): Restrict extra fields for ``BaseTest`` types - refactor(tests): Remove benign extra args to blockchain tests After restricting extra args, some tests were failing because they passed extra args that do not exist on the `BlockchainTest` class. This does not affect the test itself but now will cause failure. Thankfully, mypy caught all of these so it was easier to identify. * fix(tests,bal): Fix unreleased BAL tests from old design - BAL tests were wrongly passing the expected BAL to the ``blockchain_test`` itself. This was updated to live on the ``Block`` itself, but the tests were not updated. With the recent changes to restrict extra fields on the ``BlockchainTest`` (``BaseTest`` classess), this now correctly raises an error and allows us to have a sanity check.
1 parent 484ebb6 commit 14ed88d

File tree

8 files changed

+67
-56
lines changed

8 files changed

+67
-56
lines changed

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Users can select any of the artifacts depending on their testing needs for their
142142
- ✨ Add a `pytest.mark.with_all_typed_transactions` marker that creates default typed transactions for each `tx_type` supported by the current `fork` ([#1890](https://github.com/ethereum/execution-spec-tests/pull/1890)).
143143
- ✨ Add basic support for ``Amsterdam`` fork in order to begin testing Glamsterdam ([#2069](https://github.com/ethereum/execution-spec-tests/pull/2069)).
144144
-[EIP-7928](https://eips.ethereum.org/EIPS/eip-7928): Add initial framework support for `Block Level Access Lists (BAL)` testing for Amsterdam ([#2067](https://github.com/ethereum/execution-spec-tests/pull/2067)).
145+
- 🔀 Restrict extra args from being passed to ``BaseTest`` implementations (e.g. ``BlockchainTest``) ([#2102](https://github.com/ethereum/execution-spec-tests/pull/2102)).
145146

146147
### 🧪 Test Cases
147148

@@ -162,6 +163,7 @@ Users can select any of the artifacts depending on their testing needs for their
162163
- 🔀 Adds the max blob transaction limit to the tests including updates to [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) for Osaka ([#1884](https://github.com/ethereum/execution-spec-tests/pull/1884)).
163164
- 🐞 Fix issues when filling block rlp size limit tests with ``--generate-pre-alloc-groups`` ([#1989](https://github.com/ethereum/execution-spec-tests/pull/1989)).
164165
-[EIP-7928](https://eips.ethereum.org/EIPS/eip-7928): Add test cases for `Block Level Access Lists (BAL)` to Amsterdam ([#2067](https://github.com/ethereum/execution-spec-tests/pull/2067)).
166+
- 🐞 Fix valid BAL cases to pass the expected block access list via each block, not the blockchain test itself ([2102](https://github.com/ethereum/execution-spec-tests/pull/2102)).
165167

166168
## [v4.5.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.5.0) - 2025-05-14
167169

src/ethereum_test_specs/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Callable, ClassVar, Dict, Generator, List, Sequence, Type
1010

1111
import pytest
12-
from pydantic import BaseModel, Field, PrivateAttr
12+
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
1313
from typing_extensions import Self
1414

1515
from ethereum_clis import Result, TransitionTool
@@ -61,6 +61,8 @@ class OpMode(StrEnum):
6161
class BaseTest(BaseModel):
6262
"""Represents a base Ethereum test which must return a single test fixture."""
6363

64+
model_config = ConfigDict(extra="forbid")
65+
6466
tag: str = ""
6567

6668
_request: pytest.FixtureRequest | None = PrivateAttr(None)

src/ethereum_test_specs/tests/test_expect.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,6 @@ def test_block_intermediate_state(
418418
with pytest.raises(expected_exception) as _:
419419
BlockchainTest(
420420
genesis_environment=env,
421-
fork=fork,
422-
t8n=default_t8n,
423421
pre=pre,
424422
post=block_3.expected_post_state,
425423
blocks=[block_1, block_2, block_3],
@@ -428,8 +426,6 @@ def test_block_intermediate_state(
428426
else:
429427
BlockchainTest(
430428
genesis_environment=env,
431-
fork=fork,
432-
t8n=default_t8n,
433429
pre=pre,
434430
post=block_3.expected_post_state,
435431
blocks=[block_1, block_2, block_3],

src/pytest_plugins/filler/tests/test_prealloc_group.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class MockTest(BaseTest):
2424

2525
def __init__(self, pre: Alloc, genesis_environment: Environment, request=None):
2626
"""Initialize mock test."""
27-
super().__init__(pre=pre, genesis_environment=genesis_environment)
27+
super().__init__( # type: ignore
28+
pre=pre,
29+
genesis_environment=genesis_environment,
30+
)
2831
self._request = request
2932

3033
def generate(self, *args, **kwargs):

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ def test_bal_nonce_changes(
4343
value=100,
4444
)
4545

46-
block = Block(txs=[tx])
46+
block = Block(
47+
txs=[tx],
48+
expected_block_access_list=BlockAccessListExpectation(
49+
account_expectations={
50+
alice: BalAccountExpectation(
51+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
52+
),
53+
}
54+
),
55+
)
4756

4857
blockchain_test(
4958
pre=pre,
@@ -52,13 +61,6 @@ def test_bal_nonce_changes(
5261
alice: Account(nonce=1),
5362
bob: Account(balance=100),
5463
},
55-
expected_block_access_list=BlockAccessListExpectation(
56-
account_expectations={
57-
alice: BalAccountExpectation(
58-
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
59-
),
60-
}
61-
),
6264
)
6365

6466

@@ -88,21 +90,15 @@ def test_bal_balance_changes(
8890
gas_price=1_000_000_000,
8991
)
9092

91-
block = Block(txs=[tx])
9293
alice_account = pre[alice]
9394
assert alice_account is not None, "Alice account should exist"
9495
alice_initial_balance = alice_account.balance
9596

9697
# Account for both the value sent and gas cost (gas_price * gas_used)
9798
alice_final_balance = alice_initial_balance - 100 - (intrinsic_gas_cost * 1_000_000_000)
9899

99-
blockchain_test(
100-
pre=pre,
101-
blocks=[block],
102-
post={
103-
alice: Account(nonce=1, balance=alice_final_balance),
104-
bob: Account(balance=100),
105-
},
100+
block = Block(
101+
txs=[tx],
106102
expected_block_access_list=BlockAccessListExpectation(
107103
account_expectations={
108104
alice: BalAccountExpectation(
@@ -118,6 +114,15 @@ def test_bal_balance_changes(
118114
),
119115
)
120116

117+
blockchain_test(
118+
pre=pre,
119+
blocks=[block],
120+
post={
121+
alice: Account(nonce=1, balance=alice_final_balance),
122+
bob: Account(balance=100),
123+
},
124+
)
125+
121126

122127
@pytest.mark.valid_from("Amsterdam")
123128
def test_bal_storage_writes(
@@ -139,15 +144,8 @@ def test_bal_storage_writes(
139144
gas_limit=100000,
140145
)
141146

142-
block = Block(txs=[tx])
143-
144-
blockchain_test(
145-
pre=pre,
146-
blocks=[block],
147-
post={
148-
alice: Account(nonce=1),
149-
storage_contract: Account(storage={0x01: 0x42}),
150-
},
147+
block = Block(
148+
txs=[tx],
151149
expected_block_access_list=BlockAccessListExpectation(
152150
account_expectations={
153151
storage_contract: BalAccountExpectation(
@@ -162,6 +160,15 @@ def test_bal_storage_writes(
162160
),
163161
)
164162

163+
blockchain_test(
164+
pre=pre,
165+
blocks=[block],
166+
post={
167+
alice: Account(nonce=1),
168+
storage_contract: Account(storage={0x01: 0x42}),
169+
},
170+
)
171+
165172

166173
@pytest.mark.valid_from("Amsterdam")
167174
def test_bal_storage_reads(
@@ -181,7 +188,16 @@ def test_bal_storage_reads(
181188
gas_limit=100000,
182189
)
183190

184-
block = Block(txs=[tx])
191+
block = Block(
192+
txs=[tx],
193+
expected_block_access_list=BlockAccessListExpectation(
194+
account_expectations={
195+
storage_contract: BalAccountExpectation(
196+
storage_reads=[0x01],
197+
),
198+
}
199+
),
200+
)
185201

186202
blockchain_test(
187203
pre=pre,
@@ -190,13 +206,6 @@ def test_bal_storage_reads(
190206
alice: Account(nonce=1),
191207
storage_contract: Account(storage={0x01: 0x42}),
192208
},
193-
expected_block_access_list=BlockAccessListExpectation(
194-
account_expectations={
195-
storage_contract: BalAccountExpectation(
196-
storage_reads=[0x01],
197-
),
198-
}
199-
),
200209
)
201210

202211

@@ -244,21 +253,10 @@ def test_bal_code_changes(
244253
gas_limit=500000,
245254
)
246255

247-
block = Block(txs=[tx])
248-
249256
created_contract = compute_create_address(address=factory_contract, nonce=1)
250257

251-
blockchain_test(
252-
pre=pre,
253-
blocks=[block],
254-
post={
255-
alice: Account(nonce=1),
256-
factory_contract: Account(nonce=2), # incremented by CREATE to 2
257-
created_contract: Account(
258-
code=runtime_code_bytes,
259-
storage={},
260-
),
261-
},
258+
block = Block(
259+
txs=[tx],
262260
expected_block_access_list=BlockAccessListExpectation(
263261
account_expectations={
264262
alice: BalAccountExpectation(
@@ -273,3 +271,16 @@ def test_bal_code_changes(
273271
}
274272
),
275273
)
274+
275+
blockchain_test(
276+
pre=pre,
277+
blocks=[block],
278+
post={
279+
alice: Account(nonce=1),
280+
factory_contract: Account(nonce=2), # incremented by CREATE to 2
281+
created_contract: Account(
282+
code=runtime_code_bytes,
283+
storage={},
284+
),
285+
},
286+
)

tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_tx_gas_larger_than_block_gas_limit(
198198
exception=TransactionException.GAS_ALLOWANCE_EXCEEDED if exceed_block_gas_limit else None,
199199
)
200200

201-
blockchain_test(env=env, pre=pre, post={}, blocks=[block])
201+
blockchain_test(pre=pre, post={}, blocks=[block])
202202

203203

204204
@pytest.fixture

tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ def test_invalid_history_contract_calls(
430430
pre=pre,
431431
blocks=blocks,
432432
post=post,
433-
reverts=reverts,
434433
)
435434

436435

@@ -490,5 +489,4 @@ def test_invalid_history_contract_calls_input_size(
490489
pre=pre,
491490
blocks=blocks,
492491
post=post,
493-
reverts=reverts,
494492
)

tests/unscheduled/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ def test_jumpf_with_inputs_stack_overflow(
628628
def test_jumpf_infinite_loop(eof_state_test: EOFStateTestFiller, container: Container):
629629
"""Tests JUMPF causing an infinite loop."""
630630
eof_state_test(
631-
tx_gas=100_000,
632631
container=container,
633632
container_post=Account(storage={slot_code_worked: 0}),
634633
)

0 commit comments

Comments
 (0)