Skip to content

test_worst_selfbalance()

Documentation for tests/zkevm/test_worst_stateful_opcodes.py::test_worst_selfbalance@64f949d0.

Generate fixtures for these test cases for Prague with:

fill -v tests/zkevm/test_worst_stateful_opcodes.py::test_worst_selfbalance --fork Prague

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

Source code in tests/zkevm/test_worst_stateful_opcodes.py
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
@pytest.mark.valid_from("Cancun")
@pytest.mark.slow()
def test_worst_selfbalance(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
):
    """Test running a block with as many SELFBALANCE opcodes as possible."""
    env = Environment()
    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=env.gas_limit,
        sender=pre.fund_eoa(),
    )

    state_test(
        genesis_environment=env,
        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