Skip to content

test_block_hashes_call_opcodes()

Documentation for tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_block_hashes_call_opcodes@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_block_hashes_call_opcodes --fork Amsterdam

Test that the call opcodes can be used to call the history contract and get the block hashes.

Source code in tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
@pytest.mark.valid_from("Prague")
@pytest.mark.with_all_call_opcodes
def test_block_hashes_call_opcodes(
    blockchain_test: BlockchainTestFiller, pre: Alloc, call_opcode: Op
) -> None:
    """
    Test that the call opcodes can be used to call the history contract and get
    the block hashes.
    """
    blocks = []
    blocks.append(Block())

    storage = Storage()
    return_code_slot = storage.store_next(0x1)
    blockhash_value_slot = storage.store_next(
        True if call_opcode in [Op.DELEGATECALL, Op.CALLCODE] else False
    )

    code = (
        Op.MSTORE(0, 1)
        + Op.SSTORE(
            return_code_slot,
            call_opcode(
                address=Spec.HISTORY_STORAGE_ADDRESS,
                args_offset=0,
                args_size=32,
                ret_offset=32,
                ret_size=32,
            ),
        )
        + Op.SSTORE(blockhash_value_slot, Op.ISZERO(Op.MLOAD(32)))
    )

    contract_address = pre.deploy_contract(code, storage=storage.canary())
    blocks.append(
        Block(
            txs=[
                Transaction(
                    to=contract_address,
                    gas_limit=10_000_000,
                    sender=pre.fund_eoa(),
                )
            ]
        )
    )
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={contract_address: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 3 forks.