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@636b5f17.

Generate fixtures for these test cases for Bogota with:

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

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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
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
@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,
                    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 4 forks.