Skip to content

test_delegation_clearing_tx_to()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_tx_to@bc691d13.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_tx_to --fork Prague

Tests directly calling the account which delegation is being cleared.

  • 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
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
@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_tx_to(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_set_delegation_code: Bytecode | None,
    self_sponsored: bool,
):
    """
    Tests directly calling the account which delegation is being cleared.

    - 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)

    sender = pre.fund_eoa() if not self_sponsored else auth_signer

    tx = Transaction(
        gas_limit=200_000,
        to=auth_signer,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=Spec.RESET_DELEGATION_ADDRESS,  # Reset
                nonce=auth_signer.nonce + (1 if self_sponsored else 0),
                signer=auth_signer,
            ),
        ],
        sender=sender,
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                nonce=auth_signer.nonce + 1,
                code=b"",
                storage={},
            ),
        },
    )

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