Skip to content

test_worst_blockhash()

Documentation for tests/benchmark/test_worst_stateful_opcodes.py::test_worst_blockhash@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_stateful_opcodes.py::test_worst_blockhash --fork Osaka

Test running a block with as many blockhash accessing oldest allowed block as possible.

Source code in tests/benchmark/test_worst_stateful_opcodes.py
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
482
483
@pytest.mark.valid_from("Cancun")
def test_worst_blockhash(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    gas_benchmark_value: int,
):
    """Test running a block with as many blockhash accessing oldest allowed block as possible."""
    # Create 256 dummy blocks to fill the blockhash window.
    blocks = [Block()] * 256

    # Always ask for the oldest allowed BLOCKHASH block.
    execution_code = Op.PUSH1(1) + While(
        body=Op.POP(Op.BLOCKHASH(Op.DUP1)),
    )
    execution_code_address = pre.deploy_contract(code=execution_code)
    op_tx = Transaction(
        to=execution_code_address,
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
    )
    blocks.append(Block(txs=[op_tx]))

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

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_Cancun-blockchain_test
...fork_Prague-blockchain_test
...fork_Osaka-blockchain_test