Skip to content

test_root_branch_arity_sixteen()

Documentation for tests/mpt/test_storage_trie_structure.py::test_root_branch_arity_sixteen@02aafd78.

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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
@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.