Skip to content

test_call_insufficient_balance()

Documentation for tests/berlin/eip2929_gas_cost_increases/test_call.py::test_call_insufficient_balance@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/berlin/eip2929_gas_cost_increases/test_call.py::test_call_insufficient_balance --fork Amsterdam

Test a regular CALL to see if it warms the destination with insufficient balance.

Source code in tests/berlin/eip2929_gas_cost_increases/test_call.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@pytest.mark.valid_from("Berlin")
@pytest.mark.eels_base_coverage
def test_call_insufficient_balance(
    state_test: StateTestFiller, pre: Alloc, env: Environment, fork: Fork
) -> None:
    """
    Test a regular CALL to see if it warms the destination with insufficient
    balance.
    """
    destination = pre.fund_eoa(1)
    warm_code = Op.BALANCE(destination, address_warm=True)
    contract_address = pre.deploy_contract(
        # Perform the aborted external calls
        Op.SSTORE(
            0,
            Op.CALL(
                gas=Op.GAS,
                address=destination,
                value=1,
                args_offset=0,
                args_size=0,
                ret_offset=0,
                ret_size=0,
            ),
        )
        # Measure the gas cost for BALANCE operation
        + CodeGasMeasure(
            code=warm_code,
            extra_stack_items=1,  # BALANCE puts balance on stack
            sstore_key=1,
        ),
        balance=0,
    )

    tx = Transaction(
        to=contract_address,
        sender=pre.fund_eoa(),
    )

    post = {
        destination: Account(
            balance=1,
        ),
        contract_address: Account(
            storage={
                0: 0,  # The CALL is aborted
                1: warm_code.gas_cost(fork),
            },
        ),
    }
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 8 forks.