Skip to content

test_reset_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_reset_code@v5.1.0.

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
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
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
@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