Skip to content

test_call_into_chain_delegating_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_call_into_chain_delegating_set_code@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

Test call into a set-code account that delegates to another set-code account.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
@pytest.mark.with_all_call_opcodes
def test_call_into_chain_delegating_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    fork: Fork,
) -> None:
    """
    Test call into a set-code account that delegates to another set-code
    account.
    """
    auth_signer_1 = pre.fund_eoa(auth_account_start_balance)
    auth_signer_2 = pre.fund_eoa(auth_account_start_balance)

    storage = Storage()
    return_slot = storage.store_next(
        call_return_code(
            opcode=call_opcode,
            success=False,
        )
    )
    entry_code = (
        Op.SSTORE(
            return_slot,
            call_opcode(address=auth_signer_1),
        )
        + Op.STOP
    )
    entry_address = pre.deploy_contract(entry_code)

    tx = Transaction(
        gas_limit=10_000_000,
        to=entry_address,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=auth_signer_2,
                nonce=0,
                signer=auth_signer_1,
            ),
            AuthorizationTuple(
                address=auth_signer_1,
                nonce=0,
                signer=auth_signer_2,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    expected_block_access_list = None
    if fork.is_eip_enabled(7928):
        # One-hop delegation resolution: CALL(A) resolves A->B once; B's
        # 0xef0100... bytecode aborts as INVALID. CALL returns 0, so
        # SSTORE(slot, 0) is a no-op write and is demoted to storage_reads.
        expected_block_access_list = BlockAccessListExpectation(
            account_expectations={
                tx.sender: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                entry_address: BalAccountExpectation(
                    storage_changes=[],
                    storage_reads=[return_slot],
                ),
                auth_signer_1: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                    code_changes=[
                        BalCodeChange(
                            block_access_index=1,
                            new_code=Spec.delegation_designation(
                                auth_signer_2
                            ),
                        )
                    ],
                ),
                auth_signer_2: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                    code_changes=[
                        BalCodeChange(
                            block_access_index=1,
                            new_code=Spec.delegation_designation(
                                auth_signer_1
                            ),
                        )
                    ],
                ),
            }
        )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            entry_address: Account(storage=storage),
            auth_signer_1: Account(
                nonce=1, code=Spec.delegation_designation(auth_signer_2)
            ),
            auth_signer_2: Account(
                nonce=1, code=Spec.delegation_designation(auth_signer_1)
            ),
        },
        expected_block_access_list=expected_block_access_list,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 3 forks.