Skip to content

Commit 453cf09

Browse files
authored
feat(types): implement empty_account function (#1482)
* feat: implement empty_account in Alloc subclasses * refactor: clean up pre-alloc logic and simplify fund_address declaration * fix: type error and lint cleanup * docs: add changelog entry for empty_account utility function
1 parent c35b42f commit 453cf09

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Test fixtures for use by clients are available for each release on the [Github r
1010

1111
### 🛠️ Framework
1212

13+
- ✨ Add an empty account function for usage within fill and execute ([#1482](https://github.com/ethereum/execution-spec-tests/pull/1482)).
14+
1315
#### `fill`
1416

1517
#### `consume`

src/ethereum_test_types/types.py

+9
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ def fund_address(self, address: Address, amount: NumberConvertible):
298298
"""
299299
raise NotImplementedError("fund_address is not implemented in the base class")
300300

301+
def empty_account(self) -> Address:
302+
"""
303+
Return a previously unused account guaranteed to be empty.
304+
305+
This ensures the account has zero balance, zero nonce, no code, and no storage.
306+
The account is not a precompile or a system contract.
307+
"""
308+
raise NotImplementedError("empty_account is not implemented in the base class")
309+
301310

302311
class WithdrawalGeneric(CamelModel, Generic[NumberBoundTypeVar]):
303312
"""Withdrawal generic type, used as a parent class for `Withdrawal` and `FixtureWithdrawal`."""

src/pytest_plugins/execute/pre_alloc.py

+28
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,34 @@ def fund_address(self, address: Address, amount: NumberConvertible):
343343

344344
super().__setitem__(address, Account(balance=amount))
345345

346+
def empty_account(self) -> Address:
347+
"""
348+
Add a previously unused account guaranteed to be empty to the pre-alloc.
349+
350+
This ensures the account has:
351+
- Zero balance
352+
- Zero nonce
353+
- No code
354+
- No storage
355+
356+
This is different from precompiles or system contracts. The function does not
357+
send any transactions, ensuring that the account remains "empty."
358+
359+
Returns:
360+
Address: The address of the created empty account.
361+
362+
"""
363+
eoa = next(self._eoa_iterator)
364+
365+
super().__setitem__(
366+
eoa,
367+
Account(
368+
nonce=0,
369+
balance=0,
370+
),
371+
)
372+
return Address(eoa)
373+
346374
def wait_for_transactions(self) -> List[TransactionByHashResponse]:
347375
"""Wait for all transactions to be included in blocks."""
348376
return self._eth_rpc.wait_for_transactions(self._txs)

src/pytest_plugins/filler/pre_alloc.py

+21
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,27 @@ def fund_address(self, address: Address, amount: NumberConvertible):
250250
return
251251
super().__setitem__(address, Account(balance=amount))
252252

253+
def empty_account(self) -> Address:
254+
"""
255+
Add a previously unused account guaranteed to be empty to the pre-alloc.
256+
257+
This ensures the account has:
258+
- Zero balance
259+
- Zero nonce
260+
- No code
261+
- No storage
262+
263+
This is different from precompiles or system contracts. The function does not
264+
send any transactions, ensuring that the account remains "empty."
265+
266+
Returns:
267+
Address: The address of the created empty account.
268+
269+
"""
270+
eoa = next(self._eoa_iterator)
271+
272+
return Address(eoa)
273+
253274

254275
@pytest.fixture(scope="session")
255276
def alloc_mode(request: pytest.FixtureRequest) -> AllocMode:

0 commit comments

Comments
 (0)