Skip to content

test_invalid_history_contract_calls_input_size()

Documentation for tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py::test_invalid_history_contract_calls_input_size@14a7429a.

Generate fixtures for these test cases for Prague with:

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

Test calling the history contract with invalid input sizes.

Source code in tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
@pytest.mark.parametrize(
    "args_size,reverts",
    [
        pytest.param(0, True, id="zero_size"),
        pytest.param(33, True, id="too_large"),
        pytest.param(31, True, id="too_small"),
    ],
)
@pytest.mark.valid_from("Prague")
def test_invalid_history_contract_calls_input_size(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    reverts: bool,
    args_size: int,
):
    """Test calling the history contract with invalid input sizes."""
    storage = Storage()

    return_code_slot = storage.store_next(not reverts, "history storage call result")
    returned_block_hash_slot = storage.store_next(0)

    return_offset = 64
    return_size = 32
    block_number = 0

    # Check the first block outside of the window if any
    code = (
        Op.MSTORE(0, block_number)
        + Op.SSTORE(
            return_code_slot,
            Op.CALL(
                address=Spec.HISTORY_STORAGE_ADDRESS,
                args_offset=0,
                args_size=args_size,
                ret_offset=return_offset,
                ret_size=return_size,
            ),
        )
        + Op.SSTORE(returned_block_hash_slot, Op.MLOAD(return_offset))
    )
    check_contract_address = pre.deploy_contract(code, storage=storage.canary())

    txs = [
        Transaction(
            to=check_contract_address,
            gas_limit=10_000_000,
            sender=pre.fund_eoa(),
        )
    ]
    post = {check_contract_address: Account(storage=storage)}

    blocks = [Block(txs=txs)]
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
        reverts=reverts,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) args_size reverts
...fork_Prague-blockchain_test-zero_size 0 True
...fork_Prague-blockchain_test-too_large 33 True
...fork_Prague-blockchain_test-too_small 31 True
...fork_Osaka-blockchain_test-zero_size 0 True
...fork_Osaka-blockchain_test-too_large 33 True
...fork_Osaka-blockchain_test-too_small 31 True