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@21fb11c8.

Generate fixtures for these test cases for Prague with:

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

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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 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
@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,
):
    """
    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={k: 0 for k in storage}),
            sender: Account(
                nonce=2,
                code=Spec.delegation_designation(set_code_to_address),
                storage=storage if succeeds else {},
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) suffix succeeds tx_value
...fork_Prague-state_test-stop-tx_value_0 STOP True 0
...fork_Prague-state_test-stop-tx_value_1 STOP True 1
...fork_Prague-state_test-return-tx_value_0 True 0
...fork_Prague-state_test-return-tx_value_1 True 1
...fork_Prague-state_test-revert-tx_value_0 REVERT False 0
...fork_Prague-state_test-revert-tx_value_1 REVERT False 1
...fork_Prague-state_test-invalid-tx_value_0 INVALID False 0
...fork_Prague-state_test-invalid-tx_value_1 INVALID False 1
...fork_Prague-state_test-out-of-gas-tx_value_0 OOG False 0
...fork_Prague-state_test-out-of-gas-tx_value_1 OOG False 1
...fork_Prague-blockchain_test_from_state_test-stop-tx_value_0 STOP True 0
...fork_Prague-blockchain_test_from_state_test-stop-tx_value_1 STOP True 1
...fork_Prague-blockchain_test_from_state_test-return-tx_value_0 True 0
...fork_Prague-blockchain_test_from_state_test-return-tx_value_1 True 1
...fork_Prague-blockchain_test_from_state_test-revert-tx_value_0 REVERT False 0
...fork_Prague-blockchain_test_from_state_test-revert-tx_value_1 REVERT False 1
...fork_Prague-blockchain_test_from_state_test-invalid-tx_value_0 INVALID False 0
...fork_Prague-blockchain_test_from_state_test-invalid-tx_value_1 INVALID False 1
...fork_Prague-blockchain_test_from_state_test-out-of-gas-tx_value_0 OOG False 0
...fork_Prague-blockchain_test_from_state_test-out-of-gas-tx_value_1 OOG False 1
...fork_Osaka-state_test-stop-tx_value_0 STOP True 0
...fork_Osaka-state_test-stop-tx_value_1 STOP True 1
...fork_Osaka-state_test-return-tx_value_0 True 0
...fork_Osaka-state_test-return-tx_value_1 True 1
...fork_Osaka-state_test-revert-tx_value_0 REVERT False 0
...fork_Osaka-state_test-revert-tx_value_1 REVERT False 1
...fork_Osaka-state_test-invalid-tx_value_0 INVALID False 0
...fork_Osaka-state_test-invalid-tx_value_1 INVALID False 1
...fork_Osaka-state_test-out-of-gas-tx_value_0 OOG False 0
...fork_Osaka-state_test-out-of-gas-tx_value_1 OOG False 1
...fork_Osaka-blockchain_test_from_state_test-stop-tx_value_0 STOP True 0
...fork_Osaka-blockchain_test_from_state_test-stop-tx_value_1 STOP True 1
...fork_Osaka-blockchain_test_from_state_test-return-tx_value_0 True 0
...fork_Osaka-blockchain_test_from_state_test-return-tx_value_1 True 1
...fork_Osaka-blockchain_test_from_state_test-revert-tx_value_0 REVERT False 0
...fork_Osaka-blockchain_test_from_state_test-revert-tx_value_1 REVERT False 1
...fork_Osaka-blockchain_test_from_state_test-invalid-tx_value_0 INVALID False 0
...fork_Osaka-blockchain_test_from_state_test-invalid-tx_value_1 INVALID False 1
...fork_Osaka-blockchain_test_from_state_test-out-of-gas-tx_value_0 OOG False 0
...fork_Osaka-blockchain_test_from_state_test-out-of-gas-tx_value_1 OOG False 1