Skip to content

test_set_code_from_account_with_non_delegating_code()

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

Test that a transaction is correctly rejected, if the sender account has a non-delegating code set.

The auth transaction is sent from sender which has contract code (not delegating) But at the same time it has auth tuple that will point this sender account To be eoa, delegation, contract .. etc

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
@pytest.mark.parametrize(
    "set_code_type",
    list(AddressType),
    ids=lambda address_type: address_type.name,
)
@pytest.mark.parametrize(
    "self_sponsored",
    [True, False],
)
@pytest.mark.exception_test
@pytest.mark.pre_alloc_mutable
@pytest.mark.eels_base_coverage
def test_set_code_from_account_with_non_delegating_code(
    state_test: StateTestFiller,
    pre: Alloc,
    set_code_type: AddressType,
    self_sponsored: bool,
) -> None:
    """
    Test that a transaction is correctly rejected, if the sender account has a
    non-delegating code set.

    The auth transaction is sent from sender which has contract code (not
    delegating) But at the same time it has auth tuple that will point this
    sender account To be eoa, delegation, contract .. etc
    """
    # Set the sender account to have some code, that is specifically not a
    # delegation.
    sender = pre.fund_eoa(nonce=1, code=Op.STOP)
    random_address = pre.fund_eoa(0)

    set_code_to_address: Address
    match set_code_type:
        case AddressType.EMPTY_ACCOUNT:
            set_code_to_address = pre.fund_eoa(0)
        case AddressType.EOA:
            set_code_to_address = pre.fund_eoa(1)
        case AddressType.EOA_WITH_SET_CODE:
            set_code_account = pre.fund_eoa(0)
            set_code_to_address = pre.fund_eoa(1, delegation=set_code_account)
        case AddressType.CONTRACT:
            set_code_to_address = pre.deploy_contract(Op.STOP)
        case _:
            raise ValueError(f"Unsupported set code type: {set_code_type}")
    callee_address = pre.deploy_contract(Op.SSTORE(0, 1) + Op.STOP)

    tx = Transaction(
        gas_limit=100_000,
        to=callee_address,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=1 if self_sponsored else 0,
                signer=sender if self_sponsored else random_address,
            ),
        ],
        sender=sender,
        error=TransactionException.SENDER_NOT_EOA,
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: (
                Account.NONEXISTENT
                if set_code_type == AddressType.EMPTY_ACCOUNT
                else Account(storage={})
            ),
            random_address: Account.NONEXISTENT,
            sender: Account(nonce=1),
            callee_address: Account(storage={0: 0}),
        },
    )

Parametrized Test Cases

This test generates 8 parametrized test cases across 3 forks.