@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)
),
)