Skip to content

test_constant_gas()

Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_constant_gas@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/frontier/opcodes/test_all_opcodes.py::test_constant_gas --fork Osaka

Test that constant gas opcodes work as expected.

Source code in tests/frontier/opcodes/test_all_opcodes.py
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
@pytest.mark.valid_from("Berlin")
@pytest.mark.parametrize_by_fork("opcode", constant_gas_opcodes)
def test_constant_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Opcode,
    fork: Fork,
) -> None:
    """Test that constant gas opcodes work as expected."""
    # Using Op.GAS as salt to guarantee no address collision on CREATE2.
    create2_salt = Op.GAS if opcode == Op.CREATE2 else Bytecode()
    setup_code = (
        Op.MLOAD(0)
        + Op.POP
        + prepare_stack_constant_gas_oog(opcode)
        + create2_salt
    )
    warm_opcode_metadata = {}
    if "address_warm" in opcode.metadata:
        warm_opcode_metadata["address_warm"] = True
    if "key_warm" in opcode.metadata:
        warm_opcode_metadata["key_warm"] = True
    if warm_opcode_metadata:
        warm_opcode = opcode(**warm_opcode_metadata)
    else:
        warm_opcode = opcode
    gas_test(
        fork=fork,
        state_test=state_test,
        pre=pre,
        setup_code=setup_code,
        subject_code=opcode,
        subject_code_warm=warm_opcode,
        tear_down_code=prepare_suffix(opcode),
    )

Parametrized Test Cases

This test generates 145 parametrized test cases across 7 forks.