Skip to content

test_worst_selfbalance()

Documentation for tests/benchmark/test_worst_stateful_opcodes.py::test_worst_selfbalance@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_stateful_opcodes.py::test_worst_selfbalance --fork Osaka

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

Source code in tests/benchmark/test_worst_stateful_opcodes.py
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
@pytest.mark.valid_from("Cancun")
def test_worst_selfbalance(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_benchmark_value: int,
):
    """Test running a block with as many SELFBALANCE opcodes as possible."""
    max_stack_height = fork.max_stack_height()

    code_sequence = Op.SELFBALANCE * max_stack_height
    target_address = pre.deploy_contract(code=code_sequence)

    calldata = Bytecode()
    attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_address, 0, 0, 0, 0))

    code = code_loop_precompile_call(calldata, attack_block, fork)
    assert len(code) <= fork.max_code_size()

    code_address = pre.deploy_contract(code=code)

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

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

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Cancun-state_test
...fork_Cancun-blockchain_test_from_state_test
...fork_Prague-state_test
...fork_Prague-blockchain_test_from_state_test
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test