Skip to content

test_index_trie_shapes()

Documentation for tests/mpt/test_index_trie_structure.py::test_index_trie_shapes@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/mpt/test_index_trie_structure.py::test_index_trie_shapes --fork Bogota

One block of count transfers.

along the last key, for each count:

17: branch@0 -> {.., 1: leaf(1)} 129: branch@0 -> {8: branch@1 -> {leaf(0), leaf(2)}} 130: .. -> branch@1 -> {.., 1: ext(1) -> branch@3} 145: .. -> branch@1 -> {.., 1: branch@2} 257: branch@0 -> {8: branch@1 -> {.., 2: leaf(4)}} 258: .. -> branch@1 -> {.., 2: ext(3) -> branch@5} 273: .. -> branch@1 -> {.., 2: ext(2) -> branch@4}

The receipts trie of the block has the same keys.

Source code in tests/mpt/test_index_trie_structure.py
@pytest.mark.parametrize(
    "count,last_shape",
    [
        pytest.param(
            17,
            [(0, "branch", 3), (1, "leaf", 1)],
            id="txs_17",
        ),
        pytest.param(
            129,
            [(0, "branch", 9), (1, "branch", 2), (2, "leaf", 2)],
            id="txs_129",
        ),
        pytest.param(
            130,
            [
                (0, "branch", 9),
                (1, "branch", 2),
                (2, "ext", 1),
                (3, "branch", 2),
                (4, "leaf", 0),
            ],
            id="txs_130",
        ),
        pytest.param(
            145,
            [
                (0, "branch", 9),
                (1, "branch", 2),
                (2, "branch", 2),
                (3, "leaf", 1),
            ],
            id="txs_145",
        ),
        pytest.param(
            257,
            [(0, "branch", 9), (1, "branch", 3), (2, "leaf", 4)],
            id="txs_257",
        ),
        pytest.param(
            258,
            [
                (0, "branch", 9),
                (1, "branch", 3),
                (2, "ext", 3),
                (5, "branch", 2),
                (6, "leaf", 0),
            ],
            id="txs_258",
        ),
        pytest.param(
            273,
            [
                (0, "branch", 9),
                (1, "branch", 3),
                (2, "ext", 2),
                (4, "branch", 2),
                (5, "leaf", 1),
            ],
            id="txs_273",
        ),
    ],
)
def test_index_trie_shapes(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    count: int,
    last_shape: Shape,
) -> None:
    """
    One block of `count` transfers.

    post: along the last key, for each count:
      17:  branch@0 -> {.., 1: leaf(1)}
      129: branch@0 -> {8: branch@1 -> {leaf(0), leaf(2)}}
      130: .. -> branch@1 -> {.., 1: ext(1) -> branch@3}
      145: .. -> branch@1 -> {.., 1: branch@2}
      257: branch@0 -> {8: branch@1 -> {.., 2: leaf(4)}}
      258: .. -> branch@1 -> {.., 2: ext(3) -> branch@5}
      273: .. -> branch@1 -> {.., 2: ext(2) -> branch@4}
    The receipts trie of the block has the same keys.
    """
    assert index_shape(count, count - 1) == last_shape
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(amount=0)

    blockchain_test(
        pre=pre,
        post={recipient: Account(balance=count)},
        blocks=[
            Block(
                txs=[
                    Transaction(sender=sender, to=recipient, value=1)
                    for _ in range(count)
                ]
            )
        ],
    )

Parametrized Test Cases

This test generates 7 parametrized test cases across 3 forks.