Skip to content

test_withdrawal_leaf_embedding_boundary()

Documentation for tests/mpt/test_withdrawals_trie_structure.py::test_withdrawal_leaf_embedding_boundary@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/mpt/test_withdrawals_trie_structure.py::test_withdrawal_leaf_embedding_boundary --fork Bogota

Two withdrawals whose leaves are exactly 31, 32 or 33 bytes.

post: branch@0 -> {8: leaf(1) index 0, 0: leaf(1) index 1} amount's byte length decides whether the leaves are inlined.

Source code in tests/mpt/test_withdrawals_trie_structure.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@pytest.mark.parametrize(
    "amount,leaf_size",
    [
        pytest.param(2**16, 31, id="embedded_31"),
        pytest.param(2**24, 32, id="hashed_32"),
        pytest.param(2**32, 33, id="hashed_33"),
    ],
)
def test_withdrawal_leaf_embedding_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    amount: int,
    leaf_size: int,
) -> None:
    """
    Two withdrawals whose leaves are exactly 31, 32 or 33 bytes.

    post: branch@0 -> {8: leaf(1) index 0, 0: leaf(1) index 1}
    `amount`'s byte length decides whether the leaves are inlined.
    """
    recipient_a = pre.fund_eoa(amount=0)
    recipient_b = pre.fund_eoa(amount=0)
    withdrawals = [
        Withdrawal(
            index=0, validator_index=1, address=recipient_a, amount=amount
        ),
        Withdrawal(
            index=1, validator_index=2, address=recipient_b, amount=amount
        ),
    ]
    assert index_shape(2, 0) == [(0, "branch", 2), (1, "leaf", 1)]
    for withdrawal in withdrawals:
        assert _leaf_size(2, withdrawal) == leaf_size, withdrawal

    blockchain_test(
        pre=pre,
        post={
            recipient_a: Account(balance=amount * GWEI),
            recipient_b: Account(balance=amount * GWEI),
        },
        blocks=[Block(withdrawals=withdrawals)],
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 3 forks.