Skip to content

test_account_warm_status_reverted_by_subcall()

Documentation for tests/berlin/eip2929_gas_cost_increases/test_warm_status_revert.py::test_account_warm_status_reverted_by_subcall@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/berlin/eip2929_gas_cost_increases/test_warm_status_revert.py::test_account_warm_status_reverted_by_subcall --fork Amsterdam

Test that account warm status is reverted when a sub-call reverts.

Inner call does BALANCE(target) then REVERTs. After revert, BALANCE(target) in the outer call must be a cold access.

Source code in tests/berlin/eip2929_gas_cost_increases/test_warm_status_revert.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
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
@pytest.mark.valid_from("Berlin")
def test_account_warm_status_reverted_by_subcall(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test that account warm status is reverted when a sub-call reverts.

    Inner call does BALANCE(target) then REVERTs. After revert,
    BALANCE(target) in the outer call must be a cold access.
    """
    env = Environment()

    target = pre.fund_eoa(amount=1)

    # Inner: BALANCE(target) warms target, then reverts.
    inner = pre.deploy_contract(
        Op.POP(Op.BALANCE(target)) + Op.REVERT(offset=0, size=0)
    )

    # Overhead: PUSH for the BALANCE address argument.
    balance_push_cost = (Op.PUSH1(0) * len(Op.BALANCE.kwargs)).gas_cost(fork)
    cold_balance_cost = Op.BALANCE(address_warm=False).gas_cost(fork)

    # Outer: call inner (reverts), then measure BALANCE(target) gas.
    outer = pre.deploy_contract(
        Op.POP(Op.CALL(gas=100_000, address=inner))
        + CodeGasMeasure(
            code=Op.BALANCE(target),
            overhead_cost=balance_push_cost,
            extra_stack_items=1,
            sstore_key=0,
        )
    )

    sender = pre.fund_eoa()

    state_test(
        env=env,
        pre=pre,
        post={outer: Account(storage={0: cold_balance_cost})},
        tx=Transaction(
            sender=sender,
            to=outer,
            gas_limit=1_000_000,
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 8 forks.