Skip to content

test_update_inline_leaf()

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

Generate fixtures for these test cases for Bogota with:

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

Overwrite an inline leaf's value, then restore it.

pre: ext(8) -> branch@8 -> {leaf(55) 31 B, leaf(55) 31 B} post: block 1: one leaf rewritten at 33 B (hashed) or 31 B (inline); block 2: the pre state An inline leaf is rewritten inside its parent's RLP, never under a hash of its own.

Source code in tests/mpt/test_storage_trie_structure.py
@pytest.mark.parametrize(
    "new_value,new_size",
    [
        pytest.param(128, 33, id="flips_to_hashed"),
        pytest.param(2, 31, id="stays_inline"),
    ],
)
def test_update_inline_leaf(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    new_value: int,
    new_size: int,
) -> None:
    """
    Overwrite an inline leaf's value, then restore it.

    pre:  ext(8) -> branch@8 -> {leaf(55) 31 B, leaf(55) 31 B}
    post: block 1: one leaf rewritten at 33 B (hashed) or 31 B (inline);
          block 2: the pre state
    An inline leaf is rewritten inside its parent's RLP, never under a
    hash of its own.
    """
    a, b = EMBEDDED_LEAF_PAIR
    assert storage_shape([a, b], a)[-1] == (9, "leaf", 55)
    assert storage_leaf_size(55, 1) == 31
    assert storage_leaf_size(55, new_value) == new_size
    contract = pre.deploy_contract(code=SLOT_WRITER, storage={a: 1, b: 1})
    sender = pre.fund_eoa()

    blockchain_test(
        pre=pre,
        post={contract: Account(storage={a: 1, b: 1})},
        blocks=[
            Block(
                txs=[_write(sender, contract, a, new_value)],
                expected_post_state={
                    contract: Account(storage={a: new_value, b: 1})
                },
            ),
            Block(txs=[_write(sender, contract, a, 1)]),
        ],
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.