Skip to content

test_blockhash()

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

Generate fixtures for these test cases for Amsterdam 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@pytest.mark.skip(reason="Temporarily disabled pending investigation")
@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")
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 3 forks.