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@0f7c73a7.

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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
@pytest.mark.parametrize(
    "delta",
    [
        pytest.param(-1, id="max_rlp_size_minus_1_byte"),
        pytest.param(0, id="max_rlp_size"),
        pytest.param(1, id="max_rlp_size_plus_1_byte", marks=pytest.mark.exception_test),
    ],
)
def test_block_at_rlp_size_limit_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    post: Alloc,
    block_size_limit: int,
    env: Environment,
    exact_size_transactions,
    delta: int,
):
    """
    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
    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],
        verify_sync=False if delta > 0 else True,
    )

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