Skip to content

test_update_inline_leaf()

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

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
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
@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.