Skip to content

test_blobhash_scenarios()

Documentation for tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_scenarios@verkle@v0.0.6.

Generate fixtures for these test cases for Cancun with:

Cancun only:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_scenarios --fork=Cancun --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Cancun:

fill -v tests/cancun/eip4844_blobs/test_blobhash_opcode.py::test_blobhash_scenarios --until=Cancun

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@pytest.mark.parametrize(
    "scenario",
    [
        "single_valid",
        "repeated_valid",
        "valid_invalid",
        "varied_valid",
    ],
)
def test_blobhash_scenarios(
    pre: Alloc,
    scenario: str,
    blockchain_test: BlockchainTestFiller,
):
    """
    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)
    blobhash_calls = BlobhashScenario.generate_blobhash_bytecode(scenario)
    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=3_000_000,
                        access_list=[],
                        max_fee_per_gas=10,
                        max_priority_fee_per_gas=10,
                        max_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(SpecHelpers.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.

Skipped Parameters

For more concise readability, the table below does not list the following parameter values: fork, blockchain_test, state_test, state_test_only, eof_test, eof_state_test.

Test ID scenario
scenario_single_valid single_valid
scenario_repeated_valid repeated_valid
scenario_valid_invalid valid_invalid
scenario_varied_valid varied_valid