Skip to content

test_call_insufficient_balance_refunds_new_account_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_insufficient_balance_refunds_new_account_state_gas@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_insufficient_balance_refunds_new_account_state_gas --fork Amsterdam

Refill NEW_ACCOUNT state gas on a value CALL that fails the balance check before the child frame.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
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("depth", ["top", "child"])
@pytest.mark.parametrize(
    "funding",
    [
        pytest.param("reservoir", id="reservoir"),
        pytest.param("mixed", id="mixed"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_call_insufficient_balance_refunds_new_account_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    funding: str,
    depth: str,
) -> None:
    """
    Refill NEW_ACCOUNT state gas on a value CALL that fails the balance
    check before the child frame.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    probe_storage = Storage()
    probe_code = Op.SSTORE(probe_storage.store_next(1, "probe_ran"), 1)
    probe = pre.deploy_contract(probe_code)

    probe_stipend = probe_code.execution_cost(fork)

    non_existent_account = pre.nonexistent_account()

    value_call = Op.CALL(
        gas=Op.GAS,
        address=non_existent_account,
        value=1,
        value_transfer=True,
        account_new=True,
    )
    parent = pre.deploy_contract(
        code=(
            Op.POP(value_call)
            + Op.POP(Op.CALL(gas=probe_stipend, address=probe))
        ),
        balance=0,
    )

    new_account_state_gas = value_call.state_cost(fork)
    assert new_account_state_gas > sstore_state_gas
    if funding == "mixed":
        reservoir = sstore_state_gas
    else:
        reservoir = new_account_state_gas

    if depth == "child":
        target = pre.deploy_contract(
            code=Op.POP(Op.CALL(gas=Op.GAS, address=parent))
        )
    else:
        target = parent

    tx = Transaction(
        to=target,
        state_gas_reservoir=reservoir,
        sender=pre.fund_eoa(),
    )

    post = {probe: Account(storage=probe_storage)}
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=sstore_state_gas),
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.