Skip to content

test_gas_usage()

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

Generate fixtures for these test cases for Prague with:

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

Test that tstore and tload consume the expected gas.

Source code in tests/cancun/eip1153_tstore/test_tstorage.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
@GasMeasureTestCases.parametrize()
def test_gas_usage(
    state_test: StateTestFiller,
    pre: Alloc,
    bytecode: Bytecode,
    expected_gas: int,
    overhead_cost: int,
    extra_stack_items: int,
):
    """Test that tstore and tload consume the expected gas."""
    gas_measure_bytecode = CodeGasMeasure(
        code=bytecode, overhead_cost=overhead_cost, 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

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) bytecode expected_gas extra_stack_items overhead_cost
...fork_Cancun-blockchain_test-tload 100 1 3
...fork_Cancun-blockchain_test-tstore_tload 200 1 9
...fork_Cancun-blockchain_test-tstore_cold 100 0 6
...fork_Cancun-blockchain_test-tstore_warm 200 0 12
...fork_Cancun-state_test-tload 100 1 3
...fork_Cancun-state_test-tstore_tload 200 1 9
...fork_Cancun-state_test-tstore_cold 100 0 6
...fork_Cancun-state_test-tstore_warm 200 0 12
...fork_Prague-blockchain_test-tload 100 1 3
...fork_Prague-blockchain_test-tstore_tload 200 1 9
...fork_Prague-blockchain_test-tstore_cold 100 0 6
...fork_Prague-blockchain_test-tstore_warm 200 0 12
...fork_Prague-state_test-tload 100 1 3
...fork_Prague-state_test-tstore_tload 200 1 9
...fork_Prague-state_test-tstore_cold 100 0 6
...fork_Prague-state_test-tstore_warm 200 0 12
...fork_Osaka-blockchain_test-tload 100 1 3
...fork_Osaka-blockchain_test-tstore_tload 200 1 9
...fork_Osaka-blockchain_test-tstore_cold 100 0 6
...fork_Osaka-blockchain_test-tstore_warm 200 0 12
...fork_Osaka-state_test-tload 100 1 3
...fork_Osaka-state_test-tstore_tload 200 1 9
...fork_Osaka-state_test-tstore_cold 100 0 6
...fork_Osaka-state_test-tstore_warm 200 0 12