Skip to content

Commit 83d8717

Browse files
committed
feat(execute): Use seed directly if not running xdist
1 parent 9333360 commit 83d8717

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,6 @@ def deploy_contract(
357357

358358
# Limit the gas limit
359359
deploy_gas_limit = min(deploy_gas_limit * 2, 30_000_000)
360-
logger.info(
361-
f"Deploying contract (label={label}): gas_limit={deploy_gas_limit}, "
362-
f"code_size={len(code)} bytes, initcode_size={len(initcode)} bytes, "
363-
f"balance={Number(balance) / 10**18:.18f} ETH, storage_slots={len(storage.root)}"
364-
)
365360

366361
deploy_tx = PendingTransaction(
367362
sender=self._sender,
@@ -378,6 +373,12 @@ def deploy_contract(
378373
tx_index=len(self._pending_txs),
379374
)
380375
self._pending_txs.append(deploy_tx)
376+
logger.info(
377+
f"Contract deployment tx created (label={label}): "
378+
f"tx_nonce={deploy_tx.nonce}, gas_limit={deploy_gas_limit}, "
379+
f"code_size={len(code)} bytes, initcode_size={len(initcode)} bytes, "
380+
f"balance={Number(balance) / 10**18:.18f} ETH, storage_slots={len(storage.root)}"
381+
)
381382

382383
contract_address = deploy_tx.created_contract
383384
logger.debug(
@@ -528,9 +529,10 @@ def fund_eoa(
528529
tx_index=len(self._pending_txs),
529530
)
530531
self._pending_txs.append(fund_tx)
531-
logger.debug(
532-
f"Added funding transaction for EOA {eoa} (label={label}, "
533-
f"tx_index={len(self._pending_txs) - 1})"
532+
logger.info(
533+
f"Added funding transaction for EOA {eoa} (label={label}): "
534+
f"tx_nonce={fund_tx.nonce}, "
535+
f"tx_index={len(self._pending_txs) - 1}"
534536
)
535537
account_kwargs: Dict[str, Any] = {
536538
"nonce": eoa.nonce,
@@ -546,7 +548,8 @@ def fund_eoa(
546548
else "Deferred"
547549
)
548550
logger.info(
549-
f"EOA {eoa} funded (label={label}, nonce={eoa.nonce}, balance={balance_str})"
551+
f"EOA {eoa} funding tx created (label={label}):"
552+
f"tx_nonce={eoa.nonce}, balance={balance_str}"
550553
)
551554
return eoa
552555

@@ -590,7 +593,7 @@ def fund_address(
590593

591594
super().__setitem__(address, Account(balance=amount))
592595
logger.info(
593-
f"Address {address} funded (label={address.label}): "
596+
f"Address {address} funding tx created (label={address.label}): "
594597
f"{Number(amount) / 10**18:.18f} ETH"
595598
)
596599

packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/sender.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def worker_key_funding_amount(
110110
sender_funding_transactions_gas_price: int,
111111
sender_fund_refund_gas_limit: int,
112112
seed_account_sweep_amount: int | None,
113-
) -> int:
113+
) -> int | None:
114114
"""
115115
Calculate the initial balance of each worker key.
116116
@@ -125,7 +125,13 @@ def worker_key_funding_amount(
125125
It's not really possible to calculate the transaction costs of each test
126126
that each worker is going to run, so we can't really calculate the initial
127127
balance of each sender key based on that.
128+
129+
If we are not running tests in parallel, this method is skipped since
130+
all tests will run from the seed account.
128131
"""
132+
if worker_count <= 1:
133+
return None
134+
129135
base_name = "worker_key_funding_amount"
130136
base_file = session_temp_folder / base_name
131137
base_lock_file = session_temp_folder / f"{base_name}.lock"
@@ -202,7 +208,8 @@ def worker_key_funding_amount(
202208
def session_worker_key(
203209
request: pytest.FixtureRequest,
204210
seed_key: EOA,
205-
worker_key_funding_amount: int,
211+
worker_count: int,
212+
worker_key_funding_amount: int | None,
206213
eoa_iterator: Iterator[EOA],
207214
eth_rpc: EthRPC,
208215
session_temp_folder: Path,
@@ -216,7 +223,29 @@ def session_worker_key(
216223
217224
Each worker will have a different key, but coordination is required
218225
because all worker keys come from the same seed key.
226+
227+
If we are not running tests in parallel, this method simply returns the
228+
seed account directly.
219229
"""
230+
if worker_count <= 1:
231+
logger.info("Not running tests in parallel, using seed key directly")
232+
starting_balance = eth_rpc.get_balance(seed_key)
233+
yield seed_key
234+
235+
remaining_balance = eth_rpc.get_balance(seed_key)
236+
used_balance = starting_balance - remaining_balance
237+
logger.info(
238+
f"Seed {seed_key} used balance: {used_balance / 10**18:.18f} ETH "
239+
f"(remaining: {remaining_balance / 10**18:.18f} ETH)"
240+
)
241+
request.config.stash[metadata_key]["Senders"][str(seed_key)] = (
242+
f"Used balance={used_balance / 10**18:.18f}"
243+
)
244+
return None
245+
246+
assert worker_key_funding_amount is not None, (
247+
"`worker_key_funding_amount` is None"
248+
)
220249
# For the seed sender we do need to keep track of the nonce because it is
221250
# shared among different processes, and there might not be a new block
222251
# produced between the transactions.

0 commit comments

Comments
 (0)