Skip to content

test_block_at_rlp_size_limit_boundary()

Documentation for tests/osaka/eip7934_block_rlp_limit/test_max_block_rlp_size.py::test_block_at_rlp_size_limit_boundary@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7934_block_rlp_limit/test_max_block_rlp_size.py::test_block_at_rlp_size_limit_boundary --fork Osaka

Test the block rlp size limit.

  • At the limit - 1 byte, the block is valid
  • At the limit, the block is valid
  • At the limit + 1 byte, the block is invalid
Source code in tests/osaka/eip7934_block_rlp_limit/test_max_block_rlp_size.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
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
@EIPChecklist.BlockLevelConstraint.Test.Boundary.Under()
@EIPChecklist.BlockLevelConstraint.Test.Boundary.Exact()
@EIPChecklist.BlockLevelConstraint.Test.Boundary.Over()
@pytest.mark.parametrize(
    "delta",
    [
        pytest.param(-1, id="max_rlp_size_minus_1_byte", marks=pytest.mark.verify_sync),
        pytest.param(0, id="max_rlp_size", marks=pytest.mark.verify_sync),
        pytest.param(1, id="max_rlp_size_plus_1_byte", marks=pytest.mark.exception_test),
    ],
)
@pytest.mark.valid_from("Osaka")
def test_block_at_rlp_size_limit_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    post: Alloc,
    env: Environment,
    sender: EOA,
    fork: Fork,
    block_size_limit: int,
    delta: int,
) -> None:
    """
    Test the block rlp size limit.

    - At the limit - 1 byte, the block is valid
    - At the limit, the block is valid
    - At the limit + 1 byte, the block is invalid
    """
    transactions, gas_used = exact_size_transactions(
        sender,
        block_size_limit,
        fork,
        pre,
        env.gas_limit,
    )
    block_rlp_size = get_block_rlp_size(transactions, gas_used=gas_used)
    assert block_rlp_size == block_size_limit, (
        f"Block RLP size {block_rlp_size} does not exactly match limit {block_size_limit}, "
        f"difference: {block_rlp_size - block_size_limit} bytes"
    )

    block = Block(
        txs=transactions,
        exception=BlockException.RLP_BLOCK_LIMIT_EXCEEDED if delta > 0 else None,
    )

    if delta < 0:
        block.extra_data = Bytes(EXTRA_DATA_AT_LIMIT[: -abs(delta)])
    elif delta == 0:
        block.extra_data = Bytes(EXTRA_DATA_AT_LIMIT)
    else:  # delta > 0
        block.extra_data = Bytes(EXTRA_DATA_AT_LIMIT + b"\x00" * delta)

    block.timestamp = ZeroPaddedHexNumber(HEADER_TIMESTAMP)
    blockchain_test(
        genesis_environment=env,
        pre=pre,
        post=post,
        blocks=[block],
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) delta
...fork_Osaka-blockchain_test-max_rlp_size_minus_1_byte -1
...fork_Osaka-blockchain_test-max_rlp_size 0
...fork_Osaka-blockchain_test-max_rlp_size_plus_1_byte 1
...fork_Osaka-blockchain_test_sync-max_rlp_size_minus_1_byte -1
...fork_Osaka-blockchain_test_sync-max_rlp_size 0