Skip to content

test_blobhash_multiple_txs_in_block()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_multiple_txs_in_block@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

Tests that the BLOBHASH opcode returns the appropriate values when there is more than 1 blob tx type within a block (for tx types 2 and 3).

Scenarios involve tx type 3 followed by tx type 2 running the same code within a block, including the opposite.

Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode.py
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
def test_blobhash_multiple_txs_in_block(
    pre: Alloc,
    fork: Fork,
    blockchain_test: BlockchainTestFiller,
    max_blobs_per_tx: int,
) -> None:
    """
    Tests that the `BLOBHASH` opcode returns the appropriate values when there
    is more than 1 blob tx type within a block (for tx types 2 and 3).

    Scenarios involve tx type 3 followed by tx type 2 running the same code
    within a block, including the opposite.
    """
    blobhash_bytecode = BlobhashScenario.generate_blobhash_bytecode(
        scenario_name="single_valid", max_blobs_per_tx=max_blobs_per_tx
    )
    addresses = [pre.deploy_contract(blobhash_bytecode) for _ in range(4)]
    sender = pre.fund_eoa()

    def blob_tx(address: Address, tx_type: int) -> Transaction:
        return Transaction(
            ty=tx_type,
            sender=sender,
            to=address,
            data=Hash(0),
            gas_limit=500_000,
            access_list=[] if tx_type >= 1 else None,
            max_fee_per_blob_gas=(fork.min_base_fee_per_blob_gas() * 10)
            if tx_type >= 3
            else None,
            blob_versioned_hashes=random_blob_hashes[0:max_blobs_per_tx]
            if tx_type >= 3
            else None,
        )

    blocks = [
        Block(
            txs=[
                blob_tx(address=addresses[0], tx_type=3),
                blob_tx(address=addresses[0], tx_type=2),
            ]
        ),
        Block(
            txs=[
                blob_tx(address=addresses[1], tx_type=2),
                blob_tx(address=addresses[1], tx_type=3),
            ]
        ),
        Block(
            txs=[
                blob_tx(address=addresses[2], tx_type=2),
                blob_tx(address=addresses[3], tx_type=3),
            ],
        ),
    ]
    post = {
        Address(address): Account(
            storage={i: random_blob_hashes[i] for i in range(max_blobs_per_tx)}
        )
        if address in (addresses[1], addresses[3])
        else Account(storage=dict.fromkeys(range(max_blobs_per_tx), 0))
        for address in addresses
    }
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 4 forks.