Skip to content

test_self_sponsored_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_self_sponsored_set_code@20373115.

Generate fixtures for these test cases for Amsterdam with:

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

Test the executing a self-sponsored set-code transaction.

The transaction is sent to the sender, and the sender is the signer of the only authorization tuple in the authorization list.

The authorization tuple has a nonce of 1 because the self-sponsored transaction increases the nonce of the sender from zero to one first.

The expected nonce at the end of the transaction is 2.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@pytest.mark.parametrize(
    "tx_value",
    [0, 1],
)
@pytest.mark.parametrize(
    "suffix,succeeds",
    [
        pytest.param(Op.STOP, True, id="stop"),
        pytest.param(Op.RETURN(0, 0), True, id="return"),
        pytest.param(Op.REVERT, False, id="revert"),
        pytest.param(Op.INVALID, False, id="invalid"),
        pytest.param(Om.OOG, False, id="out-of-gas"),
    ],
)
def test_self_sponsored_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    suffix: Bytecode,
    succeeds: bool,
    tx_value: int,
) -> None:
    """
    Test the executing a self-sponsored set-code transaction.

    The transaction is sent to the sender, and the sender is the signer of the
    only authorization tuple in the authorization list.

    The authorization tuple has a nonce of 1 because the self-sponsored
    transaction increases the nonce of the sender from zero to one first.

    The expected nonce at the end of the transaction is 2.
    """
    storage = Storage()
    sender = pre.fund_eoa()

    set_code = (
        Op.SSTORE(storage.store_next(sender), Op.ORIGIN)
        + Op.SSTORE(storage.store_next(sender), Op.CALLER)
        + Op.SSTORE(storage.store_next(tx_value), Op.CALLVALUE)
        + suffix
    )
    set_code_to_address = pre.deploy_contract(
        set_code,
    )

    tx = Transaction(
        gas_limit=10_000_000,
        to=sender,
        value=tx_value,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=1,
                signer=sender,
            ),
        ],
        sender=sender,
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: Account(storage=dict.fromkeys(storage, 0)),
            sender: Account(
                nonce=2,
                code=Spec.delegation_designation(set_code_to_address),
                storage=storage if succeeds else {},
            ),
        },
    )

Parametrized Test Cases

This test generates 10 parametrized test cases across 3 forks.