Skip to content

test_delegation_clearing_preserves_storage()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_preserves_storage@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_preserves_storage --fork Amsterdam

Test that clearing the delegation of an account that already carries a delegation in the pre-state resets its code but leaves its storage untouched.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
@pytest.mark.parametrize(
    "self_sponsored",
    [
        pytest.param(False, id="not_self_sponsored"),
        pytest.param(True, id="self_sponsored"),
    ],
)
def test_delegation_clearing_preserves_storage(
    state_test: StateTestFiller,
    pre: Alloc,
    self_sponsored: bool,
) -> None:
    """
    Test that clearing the delegation of an account that already carries a
    delegation in the pre-state resets its code but leaves its storage
    untouched.
    """
    slot_preserved = 1

    delegation_address = pre.deploy_contract(Op.STOP)
    storage = Storage({slot_preserved: 0x2A})  # type: ignore[dict-item]

    auth_signer = pre.fund_eoa(delegation=delegation_address, storage=storage)

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

    tx = Transaction(
        to=pre.deploy_contract(Op.STOP),
        value=0,
        authorization_list=[authorization],
        sender=auth_signer if self_sponsored else pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.