Skip to content

Commit

Permalink
new(tests): EIP-7702: Sender not EOA test
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Mar 7, 2025
1 parent 42a066a commit 35cdfa3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ethereum_clis/clis/execution_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ class ExecutionSpecsExceptionMapper(ExceptionMapper):
@property
def _mapping_data(self):
return [
ExceptionMessage(
TransactionException.SENDER_NOT_EOA,
"Failed transaction: InvalidSenderError('not EOA')",
),
ExceptionMessage(
TransactionException.TYPE_4_TX_CONTRACT_CREATION,
"Failed transaction: ",
Expand Down
73 changes: 73 additions & 0 deletions tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3460,3 +3460,76 @@ def test_authorization_reusing_nonce(
sender: Account(nonce=1),
},
)


@pytest.mark.parametrize(
"set_code_type",
list(AddressType),
ids=lambda address_type: address_type.name,
)
@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,
):
"""
Test that a transaction is correctly rejected if the sender account has a non-delegating code
set.
"""
sender = pre.fund_eoa()
auth_signer = pre.fund_eoa(0)

set_code_to_address: Address
set_code: Bytecode | Bytes
match set_code_type:
case AddressType.EMPTY_ACCOUNT:
set_code = Bytecode()
set_code_to_address = pre.fund_eoa(0)
case AddressType.EOA:
set_code = Bytecode()
set_code_to_address = pre.fund_eoa(1)
case AddressType.EOA_WITH_SET_CODE:
set_code_account = pre.fund_eoa(0)
set_code = Spec.delegation_designation(set_code_account)
set_code_to_address = pre.fund_eoa(1, delegation=set_code_account)
case AddressType.CONTRACT:
set_code = Op.STOP
set_code_to_address = pre.deploy_contract(set_code)
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=0,
signer=auth_signer,
),
],
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={})
),
auth_signer: Account.NONEXISTENT,
callee_address: Account(storage={0: 0}),
},
)

0 comments on commit 35cdfa3

Please # to comment.