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@14a7429a.

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_from_account_with_non_delegating_code --fork Prague

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
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
@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.execute(pytest.mark.skip(reason="Requires contract-eoa address collision"))
def test_set_code_from_account_with_non_delegating_code(
    state_test: StateTestFiller,
    pre: Alloc,
    set_code_type: AddressType,
    self_sponsored: bool,
):
    """
    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
    """
    sender = pre.fund_eoa(nonce=1)
    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)

    # Set the sender account to have some code, that is specifically not a delegation.
    sender_account = pre[sender]
    assert sender_account is not None
    sender_account.code = Bytes(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

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

Test ID (Abbreviated) self_sponsored set_code_type
...fork_Prague-state_test-self_sponsored_True-EMPTY_ACCOUNT True AddressType.EMPTY_ACCOUNT
...fork_Prague-state_test-self_sponsored_True-EOA True AddressType.EOA
...fork_Prague-state_test-self_sponsored_True-EOA_WITH_SET_CODE True AddressType.EOA_WITH_SET_CODE
...fork_Prague-state_test-self_sponsored_True-CONTRACT True AddressType.CONTRACT
...fork_Prague-state_test-self_sponsored_False-EMPTY_ACCOUNT False AddressType.EMPTY_ACCOUNT
...fork_Prague-state_test-self_sponsored_False-EOA False AddressType.EOA
...fork_Prague-state_test-self_sponsored_False-EOA_WITH_SET_CODE False AddressType.EOA_WITH_SET_CODE
...fork_Prague-state_test-self_sponsored_False-CONTRACT False AddressType.CONTRACT
...fork_Prague-blockchain_test_from_state_test-self_sponsored_True-EMPTY_ACCOUNT True AddressType.EMPTY_ACCOUNT
...fork_Prague-blockchain_test_from_state_test-self_sponsored_True-EOA True AddressType.EOA
...fork_Prague-blockchain_test_from_state_test-self_sponsored_True-EOA_WITH_SET_CODE True AddressType.EOA_WITH_SET_CODE
...fork_Prague-blockchain_test_from_state_test-self_sponsored_True-CONTRACT True AddressType.CONTRACT
...fork_Prague-blockchain_test_from_state_test-self_sponsored_False-EMPTY_ACCOUNT False AddressType.EMPTY_ACCOUNT
...fork_Prague-blockchain_test_from_state_test-self_sponsored_False-EOA False AddressType.EOA
...fork_Prague-blockchain_test_from_state_test-self_sponsored_False-EOA_WITH_SET_CODE False AddressType.EOA_WITH_SET_CODE
...fork_Prague-blockchain_test_from_state_test-self_sponsored_False-CONTRACT False AddressType.CONTRACT
...fork_Osaka-state_test-self_sponsored_True-EMPTY_ACCOUNT True AddressType.EMPTY_ACCOUNT
...fork_Osaka-state_test-self_sponsored_True-EOA True AddressType.EOA
...fork_Osaka-state_test-self_sponsored_True-EOA_WITH_SET_CODE True AddressType.EOA_WITH_SET_CODE
...fork_Osaka-state_test-self_sponsored_True-CONTRACT True AddressType.CONTRACT
...fork_Osaka-state_test-self_sponsored_False-EMPTY_ACCOUNT False AddressType.EMPTY_ACCOUNT
...fork_Osaka-state_test-self_sponsored_False-EOA False AddressType.EOA
...fork_Osaka-state_test-self_sponsored_False-EOA_WITH_SET_CODE False AddressType.EOA_WITH_SET_CODE
...fork_Osaka-state_test-self_sponsored_False-CONTRACT False AddressType.CONTRACT
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_True-EMPTY_ACCOUNT True AddressType.EMPTY_ACCOUNT
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_True-EOA True AddressType.EOA
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_True-EOA_WITH_SET_CODE True AddressType.EOA_WITH_SET_CODE
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_True-CONTRACT True AddressType.CONTRACT
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_False-EMPTY_ACCOUNT False AddressType.EMPTY_ACCOUNT
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_False-EOA False AddressType.EOA
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_False-EOA_WITH_SET_CODE False AddressType.EOA_WITH_SET_CODE
...fork_Osaka-blockchain_test_from_state_test-self_sponsored_False-CONTRACT False AddressType.CONTRACT