Skip to content

test_delete_collapses_under_controlled_parent()

Documentation for tests/mpt/test_account_trie_structure.py::test_delete_collapses_under_controlled_parent@02aafd78.

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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
@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.