Skip to content

test_reset_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_reset_code@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_reset_code --fork Osaka

Test sending type-4 tx to reset the code of an account after code has been set to the account.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
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
@pytest.mark.parametrize(
    "self_sponsored",
    [
        pytest.param(False, id="not_self_sponsored"),
        pytest.param(True, id="self_sponsored"),
    ],
)
def test_reset_code(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    self_sponsored: bool,
) -> None:
    """
    Test sending type-4 tx to reset the code of an account after code has been
    set to the account.
    """
    auth_signer = pre.fund_eoa()

    set_code_1 = Op.SSTORE(1, Op.ADD(Op.SLOAD(1), 1)) + Op.STOP
    set_code_1_address = pre.deploy_contract(set_code_1)

    set_code_2 = Op.SSTORE(2, Op.ADD(Op.SLOAD(2), 1)) + Op.STOP
    set_code_2_address = pre.deploy_contract(set_code_2)

    sender = pre.fund_eoa()

    txs = [
        Transaction(
            sender=sender,
            gas_limit=500_000,
            to=auth_signer,
            value=0,
            authorization_list=[
                AuthorizationTuple(
                    address=set_code_1_address,
                    nonce=0,
                    signer=auth_signer,
                ),
            ],
        )
    ]

    auth_signer.nonce += 1  # type: ignore

    if self_sponsored:
        sender = auth_signer

    txs.append(
        Transaction(
            sender=sender,
            gas_limit=500_000,
            to=auth_signer,
            value=0,
            authorization_list=[
                AuthorizationTuple(
                    address=set_code_2_address,
                    nonce=auth_signer.nonce + 1 if self_sponsored else auth_signer.nonce,
                    signer=auth_signer,
                ),
            ],
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=txs)],
        post={
            auth_signer: Account(
                nonce=3 if self_sponsored else 2,
                code=Spec.delegation_designation(set_code_2_address),
                storage={1: 1, 2: 1},
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) self_sponsored
...fork_Prague-blockchain_test-not_self_sponsored False
...fork_Prague-blockchain_test-self_sponsored True
...fork_Osaka-blockchain_test-not_self_sponsored False
...fork_Osaka-blockchain_test-self_sponsored True