test_constant_gas()
Documentation for tests/frontier/opcodes/test_all_opcodes.py::test_constant_gas@tests-bal@v5.7.0.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/frontier/opcodes/test_all_opcodes.py::test_constant_gas --fork Amsterdam
Test that constant gas opcodes work as expected.
Source code in tests/frontier/opcodes/test_all_opcodes.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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 | @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),
)
|
Parametrized Test Cases
This test generates 147 parametrized test cases across 8 forks.