Skip to content

test_worst_tstore()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_tstore@v5.1.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_tstore -m benchmark

Test running a block with as many TSTORE calls as possible.

Source code in tests/benchmark/test_worst_compute.py
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
@pytest.mark.parametrize("key_mut", [True, False])
@pytest.mark.parametrize("dense_val_mut", [True, False])
def test_worst_tstore(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    key_mut: bool,
    dense_val_mut: bool,
    gas_benchmark_value: int,
):
    """Test running a block with as many TSTORE calls as possible."""
    max_code_size = fork.max_code_size()

    init_key = 42
    code_prefix = Op.PUSH1(init_key) + Op.JUMPDEST

    # If `key_mut` is True, we mutate the key on every iteration of the big loop.
    code_key_mut = Op.POP + Op.GAS if key_mut else Bytecode()
    code_suffix = code_key_mut + Op.JUMP(len(code_prefix) - 1)

    # If `dense_val_mut` is set, we use GAS as a cheap way of always storing a different value than
    # the previous one.
    loop_iter = Op.TSTORE(Op.DUP2, Op.GAS if dense_val_mut else Op.DUP1)

    code_body_len = (max_code_size - len(code_prefix) - len(code_suffix)) // len(loop_iter)
    code_body = loop_iter * code_body_len
    code = code_prefix + code_body + code_suffix
    assert len(code) <= max_code_size

    tx = Transaction(
        to=pre.deploy_contract(code),
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) dense_val_mut key_mut
...fork_Prague-state_test-dense_val_mut_True-key_mut_True True True
...fork_Prague-state_test-dense_val_mut_True-key_mut_False True False
...fork_Prague-state_test-dense_val_mut_False-key_mut_True False True
...fork_Prague-state_test-dense_val_mut_False-key_mut_False False False
...fork_Prague-blockchain_test_from_state_test-dense_val_mut_True-key_mut_True True True
...fork_Prague-blockchain_test_from_state_test-dense_val_mut_True-key_mut_False True False
...fork_Prague-blockchain_test_from_state_test-dense_val_mut_False-key_mut_True False True
...fork_Prague-blockchain_test_from_state_test-dense_val_mut_False-key_mut_False False False
...fork_Osaka-state_test-dense_val_mut_True-key_mut_True True True
...fork_Osaka-state_test-dense_val_mut_True-key_mut_False True False
...fork_Osaka-state_test-dense_val_mut_False-key_mut_True False True
...fork_Osaka-state_test-dense_val_mut_False-key_mut_False False False
...fork_Osaka-blockchain_test_from_state_test-dense_val_mut_True-key_mut_True True True
...fork_Osaka-blockchain_test_from_state_test-dense_val_mut_True-key_mut_False True False
...fork_Osaka-blockchain_test_from_state_test-dense_val_mut_False-key_mut_True False True
...fork_Osaka-blockchain_test_from_state_test-dense_val_mut_False-key_mut_False False False