Skip to content

test_delete_collapses_under_controlled_parent()

Documentation for tests/mpt/test_account_trie_structure.py::test_delete_collapses_under_controlled_parent@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/mpt/test_account_trie_structure.py::test_delete_collapses_under_controlled_parent --fork Bogota

Delete one child of a 2-child branch below a mined parent node.

pre: .. -> parent -> branch@d -> {doomed, survivor} post: .. -> parent -> survivor, extended by the branch nibble; under an extension parent the two merge into one node Mined siblings at depths 1 and 3 fix the parent kind whatever the uncontrolled accounts are; a collision fails the shape assert.

Source code in tests/mpt/test_account_trie_structure.py
@pytest.mark.parametrize(
    "funded,salt,depth,parent_kind,survivor_kind",
    [
        pytest.param(
            [TWO_ADDRS_EXT4[0]],
            COLLAPSE_SALT,
            4,
            "ext",
            "leaf",
            id="leaf_under_ext",
        ),
        pytest.param(
            [TWO_ADDRS_EXT4[0], TWO_ADDRS_EXT4_SIBLING_DEPTH3],
            COLLAPSE_SALT,
            4,
            "branch",
            "leaf",
            id="leaf_under_branch",
        ),
        pytest.param(
            [*ADDR_EXT_MERGE_TRIO[:2]],
            EXT_MERGE_SALT,
            2,
            "ext",
            "ext",
            id="ext_under_ext",
        ),
        pytest.param(
            [*TWO_ADDRS_EXT4, TWO_ADDRS_EXT4_SIBLING_DEPTH1],
            SHARE2_SALT,
            2,
            "branch",
            "ext",
            id="ext_under_branch",
        ),
        pytest.param(
            [*TWO_ADDRS_EXT4, TWO_ADDRS_EXT4_SIBLING_DEPTH1],
            SHARE3_SALT,
            3,
            "ext",
            "branch",
            id="branch_under_ext",
        ),
        pytest.param(
            [
                TWO_ADDRS_EXT4[0],
                TWO_ADDRS_EXT4_SIBLING_DEPTH3,
                TWO_ADDRS_EXT4_SIBLING_DEPTH1,
            ],
            SHARE2_SALT,
            2,
            "branch",
            "branch",
            id="branch_under_branch",
        ),
    ],
)
def test_delete_collapses_under_controlled_parent(
    state_test: StateTestFiller,
    pre: Alloc,
    funded: List[int],
    salt: int,
    depth: int,
    parent_kind: str,
    survivor_kind: str,
) -> None:
    """
    Delete one child of a 2-child branch below a mined parent node.

    pre:  .. -> parent -> branch@d -> {doomed, survivor}
    post: .. -> parent -> survivor, extended by the branch nibble; under
          an extension parent the two merge into one node
    Mined siblings at depths 1 and 3 fix the parent kind whatever the
    uncontrolled accounts are; a collision fails the shape assert.
    """
    addresses = [Address(x) for x in funded]
    sender = pre.fund_eoa()
    doomed = _fund_collapse(
        pre, addresses, salt, depth, parent_kind, survivor_kind
    )

    state_test(
        pre=pre,
        tx=_delete_tx(sender, salt),
        post={
            **{a: Account(balance=1) for a in addresses},
            doomed: Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.