Skip to content

test_reset_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_reset_code@8f516ce0.

Generate fixtures for these test cases for Prague with:

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

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
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
@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,
):
    """
    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