Skip to content

test_self_transfer_with_delegated_sender()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_value_moving_transactions.py::test_self_transfer_with_delegated_sender@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_value_moving_transactions.py::test_self_transfer_with_delegated_sender --fork Amsterdam

Gas for a self-transfer whose sender already holds a delegation.

The EIP's prose skips the delegation-target access for a self-transfer; its reference-case row charges it.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_value_moving_transactions.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
@pytest.mark.parametrize(
    "delegation_warm",
    [
        pytest.param(False, id="cold_delegation_target"),
        pytest.param(True, id="warm_delegation_target"),
    ],
)
def test_self_transfer_with_delegated_sender(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    delegation_warm: bool,
) -> None:
    """
    Gas for a self-transfer whose sender already holds a delegation.

    The EIP's prose skips the delegation-target access for a
    self-transfer; its reference-case row charges it.
    """
    value = 1
    delegated_to = pre.deploy_contract(code=Op.STOP)
    sender = pre.fund_eoa(delegation=delegated_to)

    access_list = (
        [AccessList(address=delegated_to, storage_keys=[])]
        if delegation_warm
        else []
    )

    intrinsic_recipient_type = RecipientType.SELF
    top_frame_recipient_type = RecipientType.DELEGATION_7702

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        access_list=access_list,
        sends_value=True,
        recipient_type=intrinsic_recipient_type,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_gas = fork.transaction_top_frame_gas_calculator()(
        sends_value=True,
        recipient_type=top_frame_recipient_type,
        delegation_warm=delegation_warm,
    )
    total_gas_cost = intrinsic_gas + top_frame_gas

    tx = Transaction(
        sender=sender,
        to=sender,
        value=value,
        access_list=access_list,
        gas_limit=total_gas_cost,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=total_gas_cost, logs=[]
        ),
    )

    post = {
        sender: Account(
            nonce=2, code=Spec7702.delegation_designation(delegated_to)
        ),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.