Skip to content

test_blockhash()

Documentation for tests/benchmark/compute/instruction/test_block_context.py::test_blockhash@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/benchmark/compute/instruction/test_block_context.py::test_blockhash --gas-benchmark-values 1

Benchmark BLOCKHASH instruction accessing oldest allowed block.

Source code in tests/benchmark/compute/instruction/test_block_context.py
@pytest.mark.repricing
@pytest.mark.parametrize(
    "index,chain_length",
    [
        pytest.param(0, 256, id="genesis"),
        pytest.param(1, 256, id="block_1"),
        pytest.param(256, 256, id="block_256"),
        pytest.param(257, 256, id="current_block"),
        pytest.param(None, 256, id="random"),
    ],
)
@pytest.mark.slow("Generates long chain")
@pytest.mark.pre_alloc_group(
    "separate",
    reason="Builds a 256-block setup chain; on a shared genesis every "
    "setup block carries the whole group alloc through t8n.",
)
def test_blockhash(
    benchmark_test: BenchmarkTestFiller,
    index: int | None,
    chain_length: int,
) -> None:
    """Benchmark BLOCKHASH instruction accessing oldest allowed block."""
    # Create `chain_length` dummy blocks to fill the blockhash window.
    with TestPhaseManager.setup():
        blocks = [Block()] * chain_length

    block_number = Op.AND(Op.GAS, 0xFF) if index is None else index

    benchmark_test(
        target_opcode=Op.BLOCKHASH,
        setup_blocks=blocks,
        code_generator=ExtCallGenerator(
            attack_block=Op.BLOCKHASH(block_number)
        ),
    )

Parametrized Test Cases

This test generates 5 parametrized test cases across 4 forks.