Skip to content

Commit 60fa840

Browse files
committed
feat(tests): Add test for bad withdrawals root
1 parent 9674b7a commit 60fa840

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2929
- ✨ Expand cases to test *CALL opcodes causing OOG ([#1703](https://github.com/ethereum/execution-specs/pull/1703)).
3030
- ✨ Add tests for `modexp` and `ripemd` precompiled contracts ([#1691](https://github.com/ethereum/execution-specs/pull/1691)).
3131
- ✨ Add `ecrecover` precompile tests originating form `evmone` unittests ([#1685](https://github.com/ethereum/execution-specs/pull/1685)).
32+
- ✨ Add test to validate withdarawls root ([#1746](https://github.com/ethereum/execution-specs/pull/1746)).
3233

3334
## [v5.3.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v5.3.0) - 2025-10-09
3435

tests/shanghai/eip4895_withdrawals/test_withdrawals.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
TransactionException,
2121
Withdrawal,
2222
)
23+
from execution_testing.exceptions.exceptions import BlockException
2324
from execution_testing.forks import Cancun
25+
from execution_testing.specs.blockchain import Header
2426

2527
from .spec import ref_spec_4895
2628

@@ -249,6 +251,52 @@ def test_balance_within_block(
249251
blockchain_test(pre=pre, post=post, blocks=blocks)
250252

251253

254+
@pytest.mark.parametrize(
255+
"valid", [True, pytest.param(False, marks=pytest.mark.exception_test)]
256+
)
257+
@pytest.mark.parametrize("n_withdrawals", [0, 1, 16])
258+
def test_withdrawals_root(
259+
blockchain_test: BlockchainTestFiller,
260+
pre: Alloc,
261+
valid: bool,
262+
n_withdrawals: int,
263+
) -> None:
264+
"""
265+
Test validation of withdrawals root.
266+
"""
267+
recipient = pre.fund_eoa(ONE_GWEI)
268+
withdrawals = [
269+
Withdrawal(
270+
index=index,
271+
validator_index=0,
272+
address=recipient,
273+
amount=1,
274+
)
275+
for index in range(n_withdrawals)
276+
]
277+
278+
modified_fields = {
279+
"withdrawals_root": Withdrawal.list_root(withdrawals)
280+
if valid
281+
else b"\x01" * 32
282+
}
283+
284+
blocks = [
285+
Block(
286+
withdrawals=withdrawals,
287+
rlp_modifier=Header(**modified_fields),
288+
exception=[
289+
BlockException.INVALID_WITHDRAWALS_ROOT,
290+
BlockException.INVALID_BLOCK_HASH,
291+
]
292+
if not valid
293+
else None,
294+
),
295+
]
296+
297+
blockchain_test(pre=pre, post={}, blocks=blocks)
298+
299+
252300
@pytest.mark.parametrize("test_case", ["single_block", "multiple_blocks"])
253301
class TestMultipleWithdrawalsSameAddress:
254302
"""

0 commit comments

Comments
 (0)