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@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_from_account_with_non_delegating_code --fork Osaka

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
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
@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,
) -> 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
    """
    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