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@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_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
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
@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,
) -> 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