Skip to content

test_fork_transition_block_rlp_limit()

Documentation for tests/osaka/eip7934_block_rlp_limit/test_max_block_rlp_size.py::test_fork_transition_block_rlp_limit@892e6d1e.

Generate fixtures for these test cases for Osaka with:

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

Test block RLP size limit at fork transition boundary.

  • Before fork (timestamp 14999): Block at limit +1 should be accepted
  • At fork (timestamp 15000): Block at limit should be accepted
  • At fork (timestamp 15000): Block at limit +1 should be rejected
Source code in tests/osaka/eip7934_block_rlp_limit/test_max_block_rlp_size.py
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedBeforeFork()
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedAfterFork()
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.RejectedAfterFork()
@pytest.mark.parametrize(
    "exceeds_limit_at_fork",
    [
        pytest.param(False, id="at_fork_within_limit"),
        pytest.param(
            True, marks=pytest.mark.exception_test, id="at_fork_exceeds_limit"
        ),
    ],
)
@pytest.mark.valid_at_transition_to("Osaka")
def test_fork_transition_block_rlp_limit(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    env: Environment,
    fork: TransitionFork,
    exceeds_limit_at_fork: bool,
) -> None:
    """
    Test block RLP size limit at fork transition boundary.

    - Before fork (timestamp 14999): Block at limit +1 should be accepted
    - At fork (timestamp 15000): Block at limit should be accepted
    - At fork (timestamp 15000): Block at limit +1 should be rejected
    """
    sender_before_fork = pre.fund_eoa()
    sender_at_fork = pre.fund_eoa()

    transactions_before, extra_data_len_before = exact_size_transactions(
        sender_before_fork,
        fork.transitions_to()
        if fork.transitions_from().block_rlp_size_limit() is None
        else fork.transitions_from(),
        pre,
        env.gas_limit,
    )

    transactions_at_fork, extra_data_len_at_fork = exact_size_transactions(
        sender_at_fork,
        fork.transitions_to(),
        pre,
        env.gas_limit,
    )

    # HEADER_TIMESTAMP (123456789) used in calculation takes 4 bytes in RLP
    # encoding. Transition timestamps (14_999 and 15_000) take 2 bytes.
    # Add the difference to extra_data to keep block at the limit.
    timestamp_byte_savings = 2

    extra_data_before = extra_data_len_before + timestamp_byte_savings
    extra_data_at_fork = extra_data_len_at_fork + timestamp_byte_savings

    blocks = [
        # before fork, block at limit +1 should be accepted
        Block(
            timestamp=14_999,
            txs=transactions_before,
            # +1 to exceed limit
            extra_data=Bytes(b"\x00" * (extra_data_before + 1)),
        )
    ]

    # At fork (timestamp 15000): Test behavior with and without exceeding limit
    if exceeds_limit_at_fork:
        blocks.append(
            Block(
                timestamp=15_000,
                txs=transactions_at_fork,
                # +1 to exceed limit, should be rejected
                extra_data=Bytes(b"\x00" * (extra_data_at_fork + 1)),
                exception=BlockException.RLP_BLOCK_LIMIT_EXCEEDED,
            )
        )
    else:
        blocks.append(
            Block(
                timestamp=15_000,
                txs=transactions_at_fork,
                # exact limit should be accepted
                extra_data=Bytes(b"\x00" * extra_data_at_fork),
            )
        )

    blockchain_test(
        genesis_environment=env,
        pre=pre,
        post={},
        blocks=blocks,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.