@@ -119,6 +119,13 @@ def pytest_addoption(parser):
119
119
type = int ,
120
120
help = "The default amount of wei to fund each EOA in each test with." ,
121
121
)
122
+ pre_alloc_group .addoption (
123
+ "--skip-cleanup" ,
124
+ action = "store_true" ,
125
+ dest = "skip_cleanup" ,
126
+ default = False ,
127
+ help = "Skip cleanup phase after each test." ,
128
+ )
122
129
123
130
124
131
@pytest .hookimpl (trylast = True )
@@ -143,6 +150,12 @@ def address_stubs(request) -> AddressStubs | None:
143
150
return request .config .getoption ("address_stubs" , None )
144
151
145
152
153
+ @pytest .fixture (scope = "session" )
154
+ def skip_cleanup (request ) -> bool :
155
+ """Return whether to skip cleanup phase after each test."""
156
+ return request .config .getoption ("skip_cleanup" )
157
+
158
+
146
159
@pytest .fixture (scope = "session" )
147
160
def eoa_iterator (request ) -> Iterator [EOA ]:
148
161
"""Return an iterator that generates EOAs."""
@@ -522,6 +535,7 @@ def pre(
522
535
eoa_fund_amount_default : int ,
523
536
default_gas_price : int ,
524
537
address_stubs : AddressStubs | None ,
538
+ skip_cleanup : bool ,
525
539
request : pytest .FixtureRequest ,
526
540
) -> Generator [Alloc , None , None ]:
527
541
"""Return default pre allocation for all tests (Empty alloc)."""
@@ -544,31 +558,32 @@ def pre(
544
558
# Yield the pre-alloc for usage during the test
545
559
yield pre
546
560
547
- # Refund all EOAs (regardless of whether the test passed or failed)
548
- refund_txs = []
549
- for idx , eoa in enumerate (pre ._funded_eoa ):
550
- remaining_balance = eth_rpc .get_balance (eoa )
551
- eoa .nonce = Number (eth_rpc .get_transaction_count (eoa ))
552
- refund_gas_limit = 21_000
553
- tx_cost = refund_gas_limit * default_gas_price
554
- if remaining_balance < tx_cost :
555
- continue
556
- refund_tx = Transaction (
557
- sender = eoa ,
558
- to = sender_key ,
559
- gas_limit = 21_000 ,
560
- gas_price = default_gas_price ,
561
- value = remaining_balance - tx_cost ,
562
- ).with_signature_and_sender ()
563
- refund_tx .metadata = TransactionTestMetadata (
564
- test_id = request .node .nodeid ,
565
- phase = "cleanup" ,
566
- action = "refund_from_eoa" ,
567
- target = eoa .label ,
568
- tx_index = idx ,
569
- )
570
- refund_txs .append (refund_tx )
571
- eth_rpc .send_wait_transactions (refund_txs )
561
+ if not skip_cleanup :
562
+ # Refund all EOAs (regardless of whether the test passed or failed)
563
+ refund_txs = []
564
+ for idx , eoa in enumerate (pre ._funded_eoa ):
565
+ remaining_balance = eth_rpc .get_balance (eoa )
566
+ eoa .nonce = Number (eth_rpc .get_transaction_count (eoa ))
567
+ refund_gas_limit = 21_000
568
+ tx_cost = refund_gas_limit * default_gas_price
569
+ if remaining_balance < tx_cost :
570
+ continue
571
+ refund_tx = Transaction (
572
+ sender = eoa ,
573
+ to = sender_key ,
574
+ gas_limit = 21_000 ,
575
+ gas_price = default_gas_price ,
576
+ value = remaining_balance - tx_cost ,
577
+ ).with_signature_and_sender ()
578
+ refund_tx .metadata = TransactionTestMetadata (
579
+ test_id = request .node .nodeid ,
580
+ phase = "cleanup" ,
581
+ action = "refund_from_eoa" ,
582
+ target = eoa .label ,
583
+ tx_index = idx ,
584
+ )
585
+ refund_txs .append (refund_tx )
586
+ eth_rpc .send_wait_transactions (refund_txs )
572
587
573
588
# Record the ending balance of the sender
574
589
sender_test_ending_balance = eth_rpc .get_balance (sender_key )
0 commit comments