Skip to content

test_call_into_self_delegating_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_call_into_self_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_self_delegating_set_code --fork Amsterdam

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

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
@pytest.mark.with_all_call_opcodes
def test_call_into_self_delegating_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    fork: Fork,
) -> None:
    """Test call into a set-code account that delegates to itself."""
    auth_signer = 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)) + 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,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    expected_block_access_list = None
    if fork.is_eip_enabled(7928):
        # Degenerate one-hop: auth_signer's delegation target IS itself.
        # CALL(auth_signer) resolves once, runs the 0xef0100... designator
        # as bytecode -> INVALID -> returns 0. SSTORE(slot, 0) is no-op.
        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: 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),
                        )
                    ],
                ),
            }
        )

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 3 forks.