Skip to content

test_blobhash_scenarios()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_scenarios@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_scenarios --fork Bogota

Tests that the BLOBHASH opcode returns the correct versioned hash for various valid indexes.

Covers various scenarios with random blob_versioned_hash values within the valid range [0, 2**256-1].

Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode.py
@pytest.mark.parametrize(
    "scenario",
    [
        "single_valid",
        "repeated_valid",
        "valid_invalid",
        "varied_valid",
    ],
)
def test_blobhash_scenarios(
    pre: Alloc,
    fork: Fork,
    scenario: str,
    blockchain_test: BlockchainTestFiller,
    max_blobs_per_tx: int,
) -> None:
    """
    Tests that the `BLOBHASH` opcode returns the correct versioned hash for
    various valid indexes.

    Covers various scenarios with random `blob_versioned_hash` values within
    the valid range `[0, 2**256-1]`.
    """
    total_blocks = 5
    b_hashes_list = BlobhashScenario.create_blob_hashes_list(
        length=total_blocks, max_blobs_per_tx=max_blobs_per_tx
    )
    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)
        blocks.append(
            Block(
                txs=[
                    Transaction(
                        ty=Spec.BLOB_TX_TYPE,
                        sender=sender,
                        to=address,
                        data=Hash(0),
                        access_list=[],
                        max_fee_per_blob_gas=(
                            fork.min_base_fee_per_blob_gas() * 10
                        ),
                        blob_versioned_hashes=b_hashes_list[i],
                    )
                ]
            )
        )
        post[address] = Account(
            storage={
                index: b_hashes_list[i][index]
                for index in range(max_blobs_per_tx)
            }
        )
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 5 forks.