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@0fdd974b.

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

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
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
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
@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-state_test-delegated_account
...fork_Prague-state_test-undelegated_account None
...fork_Prague-blockchain_test_from_state_test-delegated_account
...fork_Prague-blockchain_test_from_state_test-undelegated_account None
...fork_Osaka-state_test-delegated_account
...fork_Osaka-state_test-undelegated_account None
...fork_Osaka-blockchain_test_from_state_test-delegated_account
...fork_Osaka-blockchain_test_from_state_test-undelegated_account None