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@44293f1e.

Generate fixtures for these test cases for Prague with:

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

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
318
319
320
321
322
323
324
325
326
327
328
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
@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
):
    """Test that the call opcodes can be used to call the history contract and get the block hashes."""  # noqa: E501
    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

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) call_opcode evm_code_type
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test STATICCALL LEGACY
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test DELEGATECALL LEGACY
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test CALL LEGACY
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test CALLCODE LEGACY
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test STATICCALL LEGACY
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test DELEGATECALL LEGACY
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test CALL LEGACY
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test CALLCODE LEGACY