Skip to content

test_withdrawals_root()

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

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
@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.