Skip to content

test_delegation_clearing()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing --fork Osaka

Test clearing the delegation of an account under a variety of circumstances.

  • pre_set_delegation_code: The code to set on the account before clearing delegation, or None if the account should not have any code set.
  • self_sponsored: Whether the delegation clearing transaction is self-sponsored.
Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
@pytest.mark.parametrize(
    "self_sponsored",
    [
        pytest.param(False, id="not_self_sponsored"),
        pytest.param(True, id="self_sponsored"),
    ],
)
@pytest.mark.parametrize(
    "pre_set_delegation_code",
    [
        pytest.param(Op.RETURN(0, 1), id="delegated_account"),
        pytest.param(None, id="undelegated_account"),
    ],
)
def test_delegation_clearing(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_set_delegation_code: Bytecode | None,
    self_sponsored: bool,
) -> None:
    """
    Test clearing the delegation of an account under a variety of
    circumstances.

    - pre_set_delegation_code: The code to set on the account before clearing
                               delegation, or None if the account should not
                               have any code set.
    - self_sponsored: Whether the delegation clearing transaction is
                      self-sponsored.
    """  # noqa: D417
    pre_set_delegation_address: Address | None = None
    if pre_set_delegation_code is not None:
        pre_set_delegation_address = pre.deploy_contract(pre_set_delegation_code)

    if self_sponsored:
        auth_signer = pre.fund_eoa(delegation=pre_set_delegation_address)
    else:
        auth_signer = pre.fund_eoa(0, delegation=pre_set_delegation_address)

    success_slot = 1
    return_slot = 2
    ext_code_size_slot = 3
    ext_code_hash_slot = 4
    ext_code_copy_slot = 5
    entry_code = (
        Op.SSTORE(success_slot, 1)
        + Op.CALL(address=auth_signer)
        + Op.SSTORE(return_slot, Op.RETURNDATASIZE)
        + Op.SSTORE(ext_code_size_slot, Op.EXTCODESIZE(address=auth_signer))
        + Op.SSTORE(ext_code_hash_slot, Op.EXTCODEHASH(address=auth_signer))
        + Op.EXTCODECOPY(address=auth_signer, size=32)
        + Op.SSTORE(ext_code_copy_slot, Op.MLOAD(0))
        + Op.STOP
    )
    entry_address = pre.deploy_contract(entry_code)

    authorization = AuthorizationTuple(
        address=Spec.RESET_DELEGATION_ADDRESS,  # Reset
        nonce=auth_signer.nonce + (1 if self_sponsored else 0),
        signer=auth_signer,
    )

    tx = Transaction(
        gas_limit=200_000,
        to=entry_address,
        value=0,
        authorization_list=[authorization],
        sender=pre.fund_eoa() if not self_sponsored else auth_signer,
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                nonce=auth_signer.nonce + 1,
                code=b"",
                storage={},
            ),
            entry_address: Account(
                storage={
                    success_slot: 1,
                    return_slot: 0,
                    ext_code_size_slot: 0,
                    ext_code_hash_slot: Bytes().keccak256(),
                    ext_code_copy_slot: 0,
                },
            ),
        },
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) pre_set_delegation_code self_sponsored
...fork_Prague-state_test-delegated_account-not_self_sponsored False
...fork_Prague-state_test-delegated_account-self_sponsored True
...fork_Prague-state_test-undelegated_account-not_self_sponsored None False
...fork_Prague-state_test-undelegated_account-self_sponsored None True
...fork_Prague-blockchain_test_from_state_test-delegated_account-not_self_sponsored False
...fork_Prague-blockchain_test_from_state_test-delegated_account-self_sponsored True
...fork_Prague-blockchain_test_from_state_test-undelegated_account-not_self_sponsored None False
...fork_Prague-blockchain_test_from_state_test-undelegated_account-self_sponsored None True
...fork_Osaka-state_test-delegated_account-not_self_sponsored False
...fork_Osaka-state_test-delegated_account-self_sponsored True
...fork_Osaka-state_test-undelegated_account-not_self_sponsored None False
...fork_Osaka-state_test-undelegated_account-self_sponsored None True
...fork_Osaka-blockchain_test_from_state_test-delegated_account-not_self_sponsored False
...fork_Osaka-blockchain_test_from_state_test-delegated_account-self_sponsored True
...fork_Osaka-blockchain_test_from_state_test-undelegated_account-not_self_sponsored None False
...fork_Osaka-blockchain_test_from_state_test-undelegated_account-self_sponsored None True