Skip to content

test_blobhash_invalid_blob_index()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_invalid_blob_index@21507778.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_invalid_blob_index --fork Amsterdam

Tests that the BLOBHASH opcode returns a zeroed bytes32 value for invalid indexes.

Includes cases where the index is negative (index < 0) or exceeds the maximum number of blob_versioned_hash values stored: (index >= len(tx.message.blob_versioned_hashes)).

It confirms that the returned value is a zeroed bytes32 for each case.

Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
365
366
367
368
369
370
371
@pytest.mark.parametrize(
    "scenario",
    [
        "invalid_calls",
    ],
)
@pytest.mark.eels_base_coverage
def test_blobhash_invalid_blob_index(
    pre: Alloc,
    fork: Fork,
    blockchain_test: BlockchainTestFiller,
    scenario: str,
    max_blobs_per_tx: int,
) -> None:
    """
    Tests that the `BLOBHASH` opcode returns a zeroed `bytes32` value for
    invalid indexes.

    Includes cases where the index is negative (`index < 0`) or exceeds the
    maximum number of `blob_versioned_hash` values stored:
    (`index >= len(tx.message.blob_versioned_hashes)`).

    It confirms that the returned value is a zeroed `bytes32` for each case.
    """
    total_blocks = 5
    blobhash_calls = BlobhashScenario.generate_blobhash_bytecode(
        scenario_name=scenario, max_blobs_per_tx=max_blobs_per_tx
    )
    sender = pre.fund_eoa()
    blocks: List[Block] = []
    post = {}
    for i in range(total_blocks):
        address = pre.deploy_contract(blobhash_calls)
        blob_per_block = (i % max_blobs_per_tx) + 1
        blobs = [random_blob_hashes[blob] for blob in range(blob_per_block)]
        blocks.append(
            Block(
                txs=[
                    Transaction(
                        ty=Spec.BLOB_TX_TYPE,
                        sender=sender,
                        to=address,
                        gas_limit=500_000,
                        data=Hash(0),
                        access_list=[],
                        max_fee_per_blob_gas=(
                            fork.min_base_fee_per_blob_gas() * 10
                        ),
                        blob_versioned_hashes=blobs,
                    )
                ]
            )
        )
        post[address] = Account(
            storage={
                index: (
                    0 if index < 0 or index >= blob_per_block else blobs[index]
                )
                for index in range(
                    -total_blocks,
                    blob_per_block + (total_blocks - (i % max_blobs_per_tx)),
                )
            }
        )
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 4 forks.