Skip to content

test_withdrawals_root()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_withdrawals_root@02aafd78.

Generate fixtures for these test cases for Bogota with:

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

Test validation of withdrawals root.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
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
312
313
314
315
316
317
@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 6 forks.