Skip to content

test_withdrawals_root()

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

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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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
@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.