Skip to content

test_embedded_leaf_boundary()

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

Generate fixtures for these test cases for Bogota with:

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

Leaf RLP of exactly 30, 31, 32 and 33 bytes.

pre: empty post: ext(n) -> branch@n -> {leaf(63-n), leaf(63-n)}, each 30 to 33 B Under 32 B the leaves are inlined in the branch, from 32 B on hashed. 32 B is reached from the key side (one more nibble at a 1-byte value) and from the value side (a 2-byte value at 53 nibbles).

Source code in tests/mpt/test_storage_trie_structure.py
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
@pytest.mark.parametrize(
    "pair,value,leaf_size",
    [
        pytest.param(
            EMBEDDED_LEAF_PAIR, 1, 31, id="depth8_value1_embedded_31"
        ),
        pytest.param(HASHED_LEAF_PAIR, 1, 32, id="depth7_value1_hashed_32"),
        pytest.param(
            EMBEDDED_LEAF_PAIR, 128, 33, id="depth8_value128_hashed_33"
        ),
        pytest.param(
            VALUE_BOUNDARY_PAIR, 1, 30, id="depth10_value1_embedded_30"
        ),
        pytest.param(
            VALUE_BOUNDARY_PAIR, 128, 32, id="depth10_value128_hashed_32"
        ),
    ],
)
def test_embedded_leaf_boundary(
    state_test: StateTestFiller,
    pre: Alloc,
    pair: Sequence[int],
    value: int,
    leaf_size: int,
) -> None:
    """
    Leaf RLP of exactly 30, 31, 32 and 33 bytes.

    pre:  empty
    post: ext(n) -> branch@n -> {leaf(63-n), leaf(63-n)}, each 30 to 33 B
    Under 32 B the leaves are inlined in the branch, from 32 B on hashed.
    32 B is reached from the key side (one more nibble at a 1-byte value)
    and from the value side (a 2-byte value at 53 nibbles).
    """
    a, b = pair
    depth, kind, rest = storage_shape([a, b], a)[-1]
    assert kind == "leaf"
    assert storage_leaf_size(rest, value) == leaf_size
    contract = pre.deploy_contract(code=_writer_code([(a, value), (b, value)]))

    state_test(
        pre=pre,
        tx=Transaction(sender=pre.fund_eoa(), to=contract),
        post={contract: Account(storage={a: value, b: value})},
    )

Parametrized Test Cases

This test generates 5 parametrized test cases across 3 forks.