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@20373115.

Generate fixtures for these test cases for Amsterdam with:

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

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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
@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, extra_data_len = exact_size_transactions(
        sender,
        fork,
        pre,
        env.gas_limit,
    )

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

    target_extra_data_len = max(extra_data_len + delta, 0)
    block.extra_data = Bytes(b"\x00" * target_extra_data_len)

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

Parametrized Test Cases

This test generates 3 parametrized test cases across 2 forks.