Skip to content

test_gas_usage()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test that tstore and tload consume the expected gas.

Source code in tests/cancun/eip1153_tstore/test_tstorage.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/17_tstoreGasFiller.yml",  # noqa: E501
    ],
    pr=["https://github.com/ethereum/execution-specs/pull/2385"],
)
@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,
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 4 forks.