|
20 | 20 | TransactionException, |
21 | 21 | Withdrawal, |
22 | 22 | ) |
| 23 | +from execution_testing.exceptions.exceptions import BlockException |
23 | 24 | from execution_testing.forks import Cancun |
| 25 | +from execution_testing.specs.blockchain import Header |
24 | 26 |
|
25 | 27 | from .spec import ref_spec_4895 |
26 | 28 |
|
@@ -249,6 +251,52 @@ def test_balance_within_block( |
249 | 251 | blockchain_test(pre=pre, post=post, blocks=blocks) |
250 | 252 |
|
251 | 253 |
|
| 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 | + |
252 | 300 | @pytest.mark.parametrize("test_case", ["single_block", "multiple_blocks"]) |
253 | 301 | class TestMultipleWithdrawalsSameAddress: |
254 | 302 | """ |
|
0 commit comments