Skip to content

test_set_code_to_non_empty_storage()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_non_empty_storage@49a16fac.

Generate fixtures for these test cases for Prague with:

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

Test the setting the code to an account that has non-empty storage.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
@pytest.mark.parametrize(
    "auth_signer_nonce",
    [
        pytest.param(
            0,
            id="zero_nonce",
            marks=pytest.mark.execute(pytest.mark.skip("unrealistic scenario")),
        ),
        pytest.param(None, id="non_zero_nonce"),
    ],
)
def test_set_code_to_non_empty_storage(
    state_test: StateTestFiller,
    pre: Alloc,
    auth_signer_nonce: int,
):
    """Test the setting the code to an account that has non-empty storage."""
    auth_signer = pre.fund_eoa(
        amount=0,
        storage=Storage({0: 1}),  # type: ignore
        nonce=auth_signer_nonce,
    )
    sender = pre.fund_eoa()

    set_code = Op.SSTORE(0, Op.ADD(Op.SLOAD(0), 1)) + Op.STOP
    set_code_to_address = pre.deploy_contract(
        set_code,
    )

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

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: Account(
                storage={},
            ),
            auth_signer: Account(
                storage={0: 2},
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) auth_signer_nonce
...fork_Prague-blockchain_test-zero_nonce 0
...fork_Prague-blockchain_test-non_zero_nonce None
...fork_Prague-state_test-zero_nonce 0
...fork_Prague-state_test-non_zero_nonce None
...fork_Osaka-blockchain_test-zero_nonce 0
...fork_Osaka-blockchain_test-non_zero_nonce None
...fork_Osaka-state_test-zero_nonce 0
...fork_Osaka-state_test-non_zero_nonce None