Skip to content

Commit e19437d

Browse files
marioevzspencer-tb
authored andcommitted
more tests
1 parent b45889b commit e19437d

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

tests/prague/eip7702_eoa_code_tx/test_eoa_code_txs.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
Account,
1313
Alloc,
1414
AuthorizationTuple,
15+
Block,
16+
BlockchainTestFiller,
1517
Bytecode,
1618
Conditional,
1719
Environment,
@@ -111,6 +113,137 @@ def test_set_code_to_sstore(
111113
)
112114

113115

116+
def test_set_code_to_sstore_then_sload(
117+
blockchain_test: BlockchainTestFiller,
118+
pre: Alloc,
119+
):
120+
"""
121+
Test the executing a simple SSTORE then SLOAD in two separate set-code transactions.
122+
"""
123+
auth_signer = pre.fund_eoa(auth_account_start_balance)
124+
sender = pre.fund_eoa()
125+
126+
storage_key_1 = 0x1
127+
storage_key_2 = 0x2
128+
storage_value = 0x1234
129+
130+
set_code_1 = Op.SSTORE(storage_key_1, storage_value) + Op.STOP
131+
set_code_1_address = pre.deploy_contract(set_code_1)
132+
133+
set_code_2 = Op.SSTORE(storage_key_2, Op.ADD(Op.SLOAD(storage_key_1), 1)) + Op.STOP
134+
set_code_2_address = pre.deploy_contract(set_code_2)
135+
136+
tx_1 = Transaction(
137+
gas_limit=50_000,
138+
to=auth_signer,
139+
value=0,
140+
authorization_list=[
141+
AuthorizationTuple(
142+
address=set_code_1_address,
143+
nonce=0,
144+
signer=auth_signer,
145+
),
146+
],
147+
sender=sender,
148+
)
149+
150+
tx_2 = Transaction(
151+
gas_limit=50_000,
152+
to=auth_signer,
153+
value=0,
154+
authorization_list=[
155+
AuthorizationTuple(
156+
address=set_code_2_address,
157+
nonce=0,
158+
signer=auth_signer,
159+
),
160+
],
161+
sender=sender,
162+
)
163+
164+
block = Block(
165+
txs=[tx_1, tx_2],
166+
)
167+
168+
blockchain_test(
169+
pre=pre,
170+
post={
171+
auth_signer: Account(
172+
nonce=0,
173+
code=b"",
174+
storage={
175+
storage_key_1: storage_value,
176+
storage_key_2: storage_value + 1,
177+
},
178+
),
179+
},
180+
blocks=[block],
181+
)
182+
183+
184+
@pytest.mark.parametrize(
185+
"call_opcode",
186+
[
187+
Op.CALL,
188+
Op.DELEGATECALL,
189+
Op.STATICCALL,
190+
Op.CALLCODE,
191+
],
192+
)
193+
@pytest.mark.parametrize(
194+
"return_opcode",
195+
[
196+
Op.RETURN,
197+
Op.REVERT,
198+
],
199+
)
200+
def test_set_code_to_tstore_reentry(
201+
state_test: StateTestFiller,
202+
pre: Alloc,
203+
call_opcode: Op,
204+
return_opcode: Op,
205+
):
206+
"""
207+
Test the executing a simple TSTORE in a set-code transaction, which also performs a
208+
re-entry to TLOAD the value.
209+
"""
210+
auth_signer = pre.fund_eoa(auth_account_start_balance)
211+
212+
tload_value = 0x1234
213+
set_code = Conditional(
214+
condition=Op.ISZERO(Op.TLOAD(1)),
215+
if_true=Op.TSTORE(1, tload_value)
216+
+ call_opcode(address=Op.ADDRESS)
217+
+ Op.RETURNDATACOPY(0, 0, 32)
218+
+ Op.SSTORE(2, Op.MLOAD(0)),
219+
if_false=Op.MSTORE(0, Op.TLOAD(1)) + return_opcode(size=32),
220+
)
221+
set_code_to_address = pre.deploy_contract(set_code)
222+
223+
tx = Transaction(
224+
gas_limit=100_000,
225+
to=auth_signer,
226+
value=0,
227+
authorization_list=[
228+
AuthorizationTuple(
229+
address=set_code_to_address,
230+
nonce=0,
231+
signer=auth_signer,
232+
),
233+
],
234+
sender=pre.fund_eoa(),
235+
)
236+
237+
state_test(
238+
env=Environment(),
239+
pre=pre,
240+
tx=tx,
241+
post={
242+
auth_signer: Account(nonce=0, code=b"", storage={2: tload_value}),
243+
},
244+
)
245+
246+
114247
def test_set_code_to_self_destruct(
115248
state_test: StateTestFiller,
116249
pre: Alloc,

0 commit comments

Comments
 (0)