Skip to content

Commit bf46ecd

Browse files
authored
new(tests): EIP-7702: Set code of non-empty-storage account (#948)
* fix(plugins/filler): More accurate nonce in `fund_eoa` for edge-case * new(tests): EIP-7702: test_set_code_to_non_empty_storage * docs: changelog
1 parent fe37ca2 commit bf46ecd

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Test fixtures for use by clients are available for each release on the [Github r
1616
- 💥 `PragueEIP7692` fork in tests has been updated to `Osaka` ([#869](https://github.com/ethereum/execution-spec-tests/pull/869))
1717
- ✨ Update [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110), [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002), [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251), [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685), and [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) tests for Devnet-4 ([#832](https://github.com/ethereum/execution-spec-tests/pull/832))
1818
-[EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) many delegations test ([#923](https://github.com/ethereum/execution-spec-tests/pull/923))
19+
-[EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) set code of non-empty-storage account test ([#948](https://github.com/ethereum/execution-spec-tests/pull/948))
1920

2021
### 🛠️ Framework
2122

src/pytest_plugins/filler/pre_alloc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ def fund_eoa(
228228
# Type-4 transaction is sent to the EOA to set the storage, so the nonce must be 1
229229
if not isinstance(delegation, Address) and delegation == "Self":
230230
delegation = eoa
231-
nonce = Number(1 if nonce is None else nonce)
231+
# If delegation is None but storage is not, realistically the nonce should be 2
232+
# because the account must have delegated to set the storage and then again to
233+
# reset the delegation (but can be overridden by the test for a non-realistic
234+
# scenario)
235+
real_nonce = 2 if delegation is None else 1
236+
nonce = Number(real_nonce if nonce is None else nonce)
232237
account = Account(
233238
nonce=nonce,
234239
balance=amount,

tests/prague/eip7702_set_code_tx/test_set_code_txs.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,66 @@ def test_set_code_to_sstore(
216216
)
217217

218218

219+
@pytest.mark.parametrize(
220+
"auth_signer_nonce",
221+
[
222+
pytest.param(
223+
0,
224+
id="zero_nonce",
225+
marks=pytest.mark.execute(pytest.mark.skip("unrealistic scenario")),
226+
),
227+
pytest.param(None, id="non_zero_nonce"),
228+
],
229+
)
230+
def test_set_code_to_non_empty_storage(
231+
state_test: StateTestFiller,
232+
pre: Alloc,
233+
auth_signer_nonce: int,
234+
):
235+
"""
236+
Test the setting the code to an account that has non-empty storage.
237+
"""
238+
auth_signer = pre.fund_eoa(
239+
amount=0,
240+
storage=Storage({0: 1}), # type: ignore
241+
nonce=auth_signer_nonce,
242+
)
243+
sender = pre.fund_eoa()
244+
245+
set_code = Op.SSTORE(0, Op.ADD(Op.SLOAD(0), 1)) + Op.STOP
246+
set_code_to_address = pre.deploy_contract(
247+
set_code,
248+
)
249+
250+
tx = Transaction(
251+
gas_limit=500_000,
252+
to=auth_signer,
253+
value=0,
254+
authorization_list=[
255+
AuthorizationTuple(
256+
address=set_code_to_address,
257+
nonce=auth_signer.nonce,
258+
signer=auth_signer,
259+
),
260+
],
261+
sender=sender,
262+
)
263+
264+
state_test(
265+
env=Environment(),
266+
pre=pre,
267+
tx=tx,
268+
post={
269+
set_code_to_address: Account(
270+
storage={},
271+
),
272+
auth_signer: Account(
273+
storage={0: 2},
274+
),
275+
},
276+
)
277+
278+
219279
def test_set_code_to_sstore_then_sload(
220280
blockchain_test: BlockchainTestFiller,
221281
pre: Alloc,

0 commit comments

Comments
 (0)