Skip to content

test_constant_gas()

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

Generate fixtures for these test cases for Bogota with:

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

Test that constant gas opcodes work as expected.

Source code in tests/frontier/opcodes/test_all_opcodes.py
@pytest.mark.ported_from(
    [
        "state_tests/stEIP150singleCodeGasPrices/gasCostFiller.yml",
        "state_tests/stEIP150singleCodeGasPrices/gasCostBerlinFiller.yml",
    ],
)
@pytest.mark.valid_from("Berlin")
@pytest.mark.parametrize_by_fork("opcode", constant_gas_opcodes)
@pytest.mark.eels_base_coverage
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()
    if opcode.has_data_portion():
        if opcode in [Op.SWAPN, Op.DUPN]:
            opcode = opcode[17]
        else:
            opcode = opcode[0]
    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),
        out_of_gas_testing=opcode.gas_cost(fork) > 0,
    )

Parametrized Test Cases

This test generates 150 parametrized test cases across 9 forks.