Skip to content

test_blobhash_opcode_contexts_tx_types()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py::test_blobhash_opcode_contexts_tx_types@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py::test_blobhash_opcode_contexts_tx_types --fork Amsterdam

Tests that the BLOBHASH opcode functions correctly when called in different contexts.

  • BLOBHASH opcode on the top level of the call stack.
  • BLOBHASH opcode on the max value.
  • BLOBHASH opcode on CALL, DELEGATECALL, STATICCALL, and CALLCODE.
  • BLOBHASH opcode on Initcode.
  • BLOBHASH opcode on CREATE and CREATE2.
  • BLOBHASH opcode on transaction types 0, 1 and 2.
Source code in tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py
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
372
@pytest.mark.with_all_tx_types(selector=lambda x: x != 3)
def test_blobhash_opcode_contexts_tx_types(
    pre: Alloc,
    tx_type: int,
    state_test: StateTestFiller,
) -> None:
    """
    Tests that the `BLOBHASH` opcode functions correctly when called in
    different contexts.

    - `BLOBHASH` opcode on the top level of the call stack.
    - `BLOBHASH` opcode on the max value.
    - `BLOBHASH` opcode on `CALL`, `DELEGATECALL`, `STATICCALL`, and
        `CALLCODE`.
    - `BLOBHASH` opcode on Initcode.
    - `BLOBHASH` opcode on `CREATE` and `CREATE2`.
    - `BLOBHASH` opcode on transaction types 0, 1 and 2.
    """
    blobhash_sstore_address = BlobhashContext.BLOBHASH_SSTORE.deploy_contract(
        pre=pre, indexes=[0]
    )
    tx_kwargs = {
        "ty": tx_type,
        "to": blobhash_sstore_address,
        "sender": pre.fund_eoa(),
        "gas_limit": 500_000,
    }
    if tx_type == 4:
        signer = pre.fund_eoa(amount=0)
        tx_kwargs["authorization_list"] = [
            AuthorizationTuple(
                signer=signer,
                address=Address(0),
                nonce=0,
            )
        ]

    state_test(
        pre=pre,
        tx=Transaction(**tx_kwargs),
        post={
            blobhash_sstore_address: Account(storage={0: 0}),
        },
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 4 forks.