Skip to content

Commit 2ac0773

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

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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)