Skip to content

test_delegation_clearing_and_set_preserves_storage()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing_and_set_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_and_set_preserves_storage --fork Amsterdam

Test that clearing a pre-state delegation and setting a new one in the same authorization list keeps the authority's storage intact and readable.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
def test_delegation_clearing_and_set_preserves_storage(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test that clearing a pre-state delegation and setting a new one in the
    same authorization list keeps the authority's storage intact and
    readable.
    """
    slot_preserved = 1
    slot_read_back = 2
    slot_marker = 3

    auth_signer = pre.fund_eoa(
        0,
        delegation=pre.deploy_contract(Op.STOP),
        storage=Storage({slot_preserved: 0x2A}),  # type: ignore[dict-item]
    )
    reader = pre.deploy_contract(
        Op.SSTORE(slot_read_back, Op.SLOAD(slot_preserved))
        # The write to an untouched slot forces the storage root to be
        # recomputed from the whole slot set.
        + Op.SSTORE(slot_marker, 1)
        + Op.STOP
    )

    tx = Transaction(
        to=auth_signer,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=Spec.RESET_DELEGATION_ADDRESS,  # Reset
                nonce=auth_signer.nonce,
                signer=auth_signer,
            ),
            AuthorizationTuple(
                address=reader,
                nonce=auth_signer.nonce + 1,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.