Skip to content

test_delegation_clearing_and_set()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_and_set@83970623.

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_and_set --fork Prague

Tests clearing and setting the delegation again in the same authorization list.

  • 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.
Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
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
@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_and_set(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_set_delegation_code: Bytecode | None,
):
    """
    Tests clearing and setting the delegation again in the same authorization list.

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

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

    auth_signer = pre.fund_eoa(0, delegation=pre_set_delegation_address)

    reset_code_address = pre.deploy_contract(
        Op.CALL(address=Spec.RESET_DELEGATION_ADDRESS) + Op.SSTORE(0, 1) + Op.STOP
    )

    sender = pre.fund_eoa()

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

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                nonce=auth_signer.nonce + 2,
                code=Spec.delegation_designation(reset_code_address),
                storage={
                    0: 1,
                },
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) pre_set_delegation_code
...fork_Prague-blockchain_test-delegated_account
...fork_Prague-blockchain_test-undelegated_account None
...fork_Prague-state_test-delegated_account
...fork_Prague-state_test-undelegated_account None
...fork_Osaka-blockchain_test-delegated_account
...fork_Osaka-blockchain_test-undelegated_account None
...fork_Osaka-state_test-delegated_account
...fork_Osaka-state_test-undelegated_account None