Skip to content

test_embedded_leaf_boundary()

Documentation for tests/mpt/test_storage_trie_structure.py::test_embedded_leaf_boundary@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/mpt/test_storage_trie_structure.py::test_embedded_leaf_boundary --fork Bogota

Leaf RLP of exactly 30, 31, 32 and 33 bytes.

pre: empty post: ext(n) -> branch@n -> {leaf(63-n), leaf(63-n)}, each 30 to 33 B Under 32 B the leaves are inlined in the branch, from 32 B on hashed. 32 B is reached from the key side (one more nibble at a 1-byte value) and from the value side (a 2-byte value at 53 nibbles).

Source code in tests/mpt/test_storage_trie_structure.py
@pytest.mark.parametrize(
    "pair,value,leaf_size",
    [
        pytest.param(
            EMBEDDED_LEAF_PAIR, 1, 31, id="depth8_value1_embedded_31"
        ),
        pytest.param(HASHED_LEAF_PAIR, 1, 32, id="depth7_value1_hashed_32"),
        pytest.param(
            EMBEDDED_LEAF_PAIR, 128, 33, id="depth8_value128_hashed_33"
        ),
        pytest.param(
            VALUE_BOUNDARY_PAIR, 1, 30, id="depth10_value1_embedded_30"
        ),
        pytest.param(
            VALUE_BOUNDARY_PAIR, 128, 32, id="depth10_value128_hashed_32"
        ),
    ],
)
def test_embedded_leaf_boundary(
    state_test: StateTestFiller,
    pre: Alloc,
    pair: Sequence[int],
    value: int,
    leaf_size: int,
) -> None:
    """
    Leaf RLP of exactly 30, 31, 32 and 33 bytes.

    pre:  empty
    post: ext(n) -> branch@n -> {leaf(63-n), leaf(63-n)}, each 30 to 33 B
    Under 32 B the leaves are inlined in the branch, from 32 B on hashed.
    32 B is reached from the key side (one more nibble at a 1-byte value)
    and from the value side (a 2-byte value at 53 nibbles).
    """
    a, b = pair
    depth, kind, rest = storage_shape([a, b], a)[-1]
    assert kind == "leaf"
    assert storage_leaf_size(rest, value) == leaf_size
    contract = pre.deploy_contract(code=_writer_code([(a, value), (b, value)]))

    state_test(
        pre=pre,
        tx=Transaction(sender=pre.fund_eoa(), to=contract),
        post={contract: Account(storage={a: value, b: value})},
    )

Parametrized Test Cases

This test generates 5 parametrized test cases across 3 forks.