Skip to content

test_worst_callvalue()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_callvalue@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

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

Test running a block with as many CALLVALUE opcodes as possible.

The non_zero_value parameter controls whether opcode must return non-zero value. The from_origin parameter controls whether the call frame is the immediate from the transaction or a previous CALL.

Source code in tests/benchmark/test_worst_compute.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@pytest.mark.parametrize("non_zero_value", [True, False])
@pytest.mark.parametrize("from_origin", [True, False])
def test_worst_callvalue(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
    non_zero_value: bool,
    from_origin: bool,
) -> None:
    """
    Test running a block with as many CALLVALUE opcodes as possible.

    The `non_zero_value` parameter controls whether opcode must return non-zero
    value. The `from_origin` parameter controls whether the call frame is the
    immediate from the transaction or a previous CALL.
    """
    code_address = JumpLoopGenerator(attack_block=Op.POP(Op.CALLVALUE)).deploy_contracts(
        pre=pre, fork=fork
    )

    if from_origin:
        tx_to = code_address
    else:
        entry_code = (
            Op.JUMPDEST
            + Op.CALL(address=code_address, value=1 if non_zero_value else 0)
            + Op.JUMP(Op.PUSH0)
        )
        tx_to = pre.deploy_contract(code=entry_code, balance=1_000_000)

    tx = Transaction(
        to=tx_to,
        value=1 if non_zero_value and from_origin else 0,
        sender=pre.fund_eoa(),
    )

    benchmark_test(tx=tx)

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated) from_origin non_zero_value
...fork_Prague-blockchain_test-from_origin_True-non_zero_value_True True True
...fork_Prague-blockchain_test-from_origin_True-non_zero_value_False True False
...fork_Prague-blockchain_test-from_origin_False-non_zero_value_True False True
...fork_Prague-blockchain_test-from_origin_False-non_zero_value_False False False
...fork_Osaka-blockchain_test-from_origin_True-non_zero_value_True True True
...fork_Osaka-blockchain_test-from_origin_True-non_zero_value_False True False
...fork_Osaka-blockchain_test-from_origin_False-non_zero_value_True False True
...fork_Osaka-blockchain_test-from_origin_False-non_zero_value_False False False