Skip to content

test_gas_usage()

Documentation for tests/cancun/eip1153_tstore/test_tstorage.py::test_gas_usage@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/cancun/eip1153_tstore/test_tstorage.py::test_gas_usage --fork Osaka

Test that tstore and tload consume the expected gas.

Source code in tests/cancun/eip1153_tstore/test_tstorage.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
@GasMeasureTestCases.parametrize()
def test_gas_usage(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    bytecode: Bytecode,
    extra_stack_items: int,
) -> None:
    """Test that tstore and tload consume the expected gas."""
    expected_gas = bytecode.gas_cost(fork)
    gas_measure_bytecode = CodeGasMeasure(
        code=bytecode,
        extra_stack_items=extra_stack_items,
    )

    env = Environment()
    code_address = pre.deploy_contract(code=gas_measure_bytecode)
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=code_address,
        gas_limit=1_000_000,
    )
    post = {
        code_address: Account(
            code=gas_measure_bytecode, storage={0: expected_gas}
        ),
    }
    state_test(env=env, pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.