Skip to content

Commit 8dd0a5e

Browse files
committed
fix(tests): EIP-7702 test_ext_code_on_set_code
1 parent 1eee731 commit 8dd0a5e

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Helper types, functions and classes for testing EIP-7702 Set Code Transaction.
3+
"""
4+
5+
from enum import Enum, auto
6+
7+
8+
class AddressType(Enum):
9+
"""
10+
Different types of addresses used to specify the type of authority that signs an authorization,
11+
and the type of address to which the authority authorizes to set the code to.
12+
"""
13+
14+
EMPTY_ACCOUNT = auto()
15+
EOA = auto()
16+
CONTRACT = auto()
17+
18+
19+
class ChainIDType(Enum):
20+
"""
21+
Different types of chain IDs used in the authorization list.
22+
"""
23+
24+
GENERIC = auto()
25+
CHAIN_SPECIFIC = auto()

tests/prague/eip7702_set_code_tx/test_gas.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
parametrize_with_defaults,
3333
)
3434

35+
from .helpers import AddressType, ChainIDType
3536
from .spec import Spec, ref_spec_7702
3637

3738
REFERENCE_SPEC_GIT_PATH = ref_spec_7702.git_path
@@ -62,26 +63,6 @@ class AuthorizationInvalidityType(Enum):
6263
AUTHORITY_IS_CONTRACT = auto()
6364

6465

65-
class AddressType(Enum):
66-
"""
67-
Different types of addresses used to specify the type of authority that signs an authorization,
68-
and the type of address to which the authority authorizes to set the code to.
69-
"""
70-
71-
EMPTY_ACCOUNT = auto()
72-
EOA = auto()
73-
CONTRACT = auto()
74-
75-
76-
class ChainIDType(Enum):
77-
"""
78-
Different types of chain IDs used in the authorization list.
79-
"""
80-
81-
GENERIC = auto()
82-
CHAIN_SPECIFIC = auto()
83-
84-
8566
class AccessListType(Enum):
8667
"""
8768
Different cases of access lists for testing gas cost of set-code transactions.

tests/prague/eip7702_set_code_tx/test_set_code_txs.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from ..eip6110_deposits.helpers import DepositRequest
4242
from ..eip7002_el_triggerable_withdrawals.helpers import WithdrawalRequest
4343
from ..eip7251_consolidations.helpers import ConsolidationRequest
44+
from .helpers import AddressType
4445
from .spec import Spec, ref_spec_7702
4546

4647
REFERENCE_SPEC_GIT_PATH = ref_spec_7702.git_path
@@ -804,10 +805,16 @@ def test_call_into_chain_delegating_set_code(
804805
"balance",
805806
[0, 1],
806807
)
808+
@pytest.mark.parametrize(
809+
"set_code_type",
810+
list(AddressType),
811+
ids=lambda address_type: address_type.name,
812+
)
807813
def test_ext_code_on_set_code(
808814
state_test: StateTestFiller,
809815
pre: Alloc,
810816
balance: int,
817+
set_code_type: AddressType,
811818
):
812819
"""
813820
Test different ext*code operations on a set-code address.
@@ -835,9 +842,21 @@ def test_ext_code_on_set_code(
835842
callee_storage = Storage()
836843

837844
auth_signer_storage = Storage()
838-
set_code = Op.SSTORE(slot_call_success, Op.CALL(address=callee_address)) + Op.STOP
839-
auth_signer_storage[slot_call_success] = True
840-
set_code_to_address = pre.deploy_contract(set_code)
845+
set_code_to_address: Address
846+
847+
match set_code_type:
848+
case AddressType.EMPTY_ACCOUNT:
849+
set_code = Bytecode()
850+
set_code_to_address = pre.fund_eoa(0)
851+
case AddressType.EOA:
852+
set_code = Bytecode()
853+
set_code_to_address = pre.fund_eoa(1)
854+
case AddressType.CONTRACT:
855+
set_code = Op.SSTORE(slot_call_success, Op.CALL(address=callee_address)) + Op.STOP
856+
auth_signer_storage[slot_call_success] = True
857+
set_code_to_address = pre.deploy_contract(set_code)
858+
case _:
859+
raise ValueError(f"Unsupported set code type: {set_code_type}")
841860

842861
callee_storage[slot_caller] = auth_signer
843862
callee_storage[slot_ext_code_size_result] = len(set_code)
@@ -863,7 +882,9 @@ def test_ext_code_on_set_code(
863882
pre=pre,
864883
tx=tx,
865884
post={
866-
set_code_to_address: Account(storage={}),
885+
set_code_to_address: Account.NONEXISTENT
886+
if set_code_type == AddressType.EMPTY_ACCOUNT
887+
else Account(storage={}),
867888
auth_signer: Account(nonce=1, code=b"", storage=auth_signer_storage, balance=balance),
868889
callee_address: Account(storage=callee_storage),
869890
},

0 commit comments

Comments
 (0)