Skip to content

test_top_frame_charges_delegation_in_access_list()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_top_frame_charges_delegation_in_access_list@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_top_frame_charges_delegation_in_access_list --fork Amsterdam

Recipient holds a pre-existing EIP-7702 delegation; the delegation target is listed in the access list. The top-frame still charges COLD_ACCOUNT_ACCESS for the delegation target on top of the access-list cost itself.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_top_frame_charges_delegation_in_access_list(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    value: int,
) -> None:
    """
    Recipient holds a pre-existing EIP-7702 delegation; the delegation
    target is listed in the access list. The top-frame still charges
    ``COLD_ACCOUNT_ACCESS`` for the delegation target on top of the
    access-list cost itself.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)

    delegated_to = pre.deploy_contract(code=Op.STOP)
    target_code = Spec7702.delegation_designation(delegated_to)
    target = pre.deploy_contract(code=target_code)
    access_list = [AccessList(address=delegated_to, storage_keys=[])]

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        access_list=access_list,
        sends_value=bool(value),
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_gas = fork.transaction_top_frame_gas_calculator()(
        sends_value=bool(value),
        recipient_type=RecipientType.DELEGATION_7702,
    )

    total_gas_cost = intrinsic_gas + top_frame_gas
    gas_price = 1_000_000_000
    gas_limit = total_gas_cost + 1000

    tx = Transaction(
        ty=1,
        sender=sender,
        to=target,
        value=value,
        access_list=access_list,
        gas_limit=gas_limit,
        gas_price=gas_price,
    )

    sender_final_balance = (
        sender_initial_balance - value - total_gas_cost * gas_price
    )

    post = {
        sender: Account(nonce=1, balance=sender_final_balance),
        target: Account(balance=value, code=target_code),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.