Skip to content

test_blobhash_scenarios()

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

Generate fixtures for these test cases for Prague with:

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

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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
@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_block: int,
):
    """
    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_block=max_blobs_per_block
    )
    blobhash_calls = BlobhashScenario.generate_blobhash_bytecode(
        scenario_name=scenario, max_blobs_per_block=max_blobs_per_block
    )
    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),
                        gas_limit=500_000,
                        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_block)}
        )
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) scenario
...fork_Cancun-blockchain_test-scenario_single_valid single_valid
...fork_Cancun-blockchain_test-scenario_repeated_valid repeated_valid
...fork_Cancun-blockchain_test-scenario_valid_invalid valid_invalid
...fork_Cancun-blockchain_test-scenario_varied_valid varied_valid
...fork_Prague-blockchain_test-scenario_single_valid single_valid
...fork_Prague-blockchain_test-scenario_repeated_valid repeated_valid
...fork_Prague-blockchain_test-scenario_valid_invalid valid_invalid
...fork_Prague-blockchain_test-scenario_varied_valid varied_valid
...fork_Osaka-blockchain_test-scenario_single_valid single_valid
...fork_Osaka-blockchain_test-scenario_repeated_valid repeated_valid
...fork_Osaka-blockchain_test-scenario_valid_invalid valid_invalid
...fork_Osaka-blockchain_test-scenario_varied_valid varied_valid