Skip to content

test_withdrawals_root()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_withdrawals_root@5f132e7c.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_withdrawals_root --fork Amsterdam

Test validation of withdrawals root.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
@pytest.mark.parametrize(
    "valid", [True, pytest.param(False, marks=pytest.mark.exception_test)]
)
@pytest.mark.parametrize("n_withdrawals", [0, 1, 16])
def test_withdrawals_root(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    valid: bool,
    n_withdrawals: int,
) -> None:
    """
    Test validation of withdrawals root.
    """
    recipient = pre.fund_eoa(ONE_GWEI)
    withdrawals = [
        Withdrawal(
            index=index,
            validator_index=0,
            address=recipient,
            amount=1,
        )
        for index in range(n_withdrawals)
    ]

    modified_fields = {
        "withdrawals_root": Withdrawal.list_root(withdrawals)
        if valid
        else b"\x01" * 32
    }

    blocks = [
        Block(
            withdrawals=withdrawals,
            rlp_modifier=Header(**modified_fields),
            exception=[
                BlockException.INVALID_WITHDRAWALS_ROOT,
                BlockException.INVALID_BLOCK_HASH,
            ]
            if not valid
            else None,
        ),
    ]

    blockchain_test(pre=pre, post={}, blocks=blocks)

Parametrized Test Cases

This test generates 6 parametrized test cases across 5 forks.