Skip to content

test_root_branch_arity_sixteen()

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

Generate fixtures for these test cases for Bogota with:

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

Fill a 16-way root branch from empty, or reduce one to 15 or 1 child.

pre: empty, or branch@0 -> {16 x leaf(63)} post: branch@0 -> {16 x leaf(63)}, branch@0 -> {15 x leaf(63)}, or leaf(64)

Source code in tests/mpt/test_storage_trie_structure.py
@pytest.mark.parametrize(
    "committed,writes,present,post_shape",
    [
        pytest.param(
            ROOT_SIXTEEN,
            [(s, 0) for s in ROOT_SIXTEEN[1:]],
            ROOT_SIXTEEN[:1],
            [(0, "leaf", 64)],
            id="sixteen_to_one",
        ),
        pytest.param(
            ROOT_SIXTEEN,
            [(ROOT_SIXTEEN[0], 0)],
            ROOT_SIXTEEN[1:],
            [(0, "branch", 15), (1, "leaf", 63)],
            id="sixteen_to_fifteen",
        ),
        pytest.param(
            (),
            [(s, i + 1) for i, s in enumerate(ROOT_SIXTEEN)],
            ROOT_SIXTEEN,
            [(0, "branch", 16), (1, "leaf", 63)],
            id="fill",
        ),
    ],
)
def test_root_branch_arity_sixteen(
    state_test: StateTestFiller,
    pre: Alloc,
    committed: Sequence[int],
    writes: List[Tuple[int, int]],
    present: Sequence[int],
    post_shape: Shape,
) -> None:
    """
    Fill a 16-way root branch from empty, or reduce one to 15 or 1 child.

    pre:  empty, or branch@0 -> {16 x leaf(63)}
    post: branch@0 -> {16 x leaf(63)}, branch@0 -> {15 x leaf(63)}, or
          leaf(64)
    """
    assert storage_shape(ROOT_SIXTEEN, ROOT_SIXTEEN[0]) == [
        (0, "branch", 16),
        (1, "leaf", 63),
    ]
    assert storage_shape(present, present[0]) == post_shape
    contract = pre.deploy_contract(
        code=_writer_code(writes), storage=_storage(committed)
    )
    expected = {
        s: v for s, v in _storage(ROOT_SIXTEEN).items() if s in present
    }

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

Parametrized Test Cases

This test generates 3 parametrized test cases across 3 forks.