@@ -344,39 +344,44 @@ def _get_funded_addresses(
344344 caching_key : str = "" ,
345345 amount : int | None = None ,
346346) -> list :
347- """Create and fund addresses."""
348- # Initially fund the addresses with more funds, so the funds don't need to be
349- # added for each and every test.
350- init_amount = 250_000_000
351- # Refund the addresses if the amount is lower than this
347+ """Create and fund addresses.
348+
349+ If `amount` is provided, fund once and never re-fund.
350+ If `amount` is not provided, re-fund when balance drops below `min_amount`.
351+ """
352+ fund_amount = amount or 150_000_000
353+ # Re-fund the addresses if the amount is lower than this
352354 min_amount = 50_000_000
353355
354356 if caching_key :
355357 fixture_cache : cluster_management .FixtureCache [list | None ]
356358 with cluster_manager .cache_fixture (key = caching_key ) as fixture_cache :
357359 if fixture_cache .value is None :
358360 addrs = create_func ()
359- amount = amount or init_amount
360361 fixture_cache .value = addrs
361362 else :
362363 addrs = fixture_cache .value
363- # If amount was passed, fund the addresses only initially
364+ # If amount is explicitly specified, skip re-funding
364365 if amount :
365366 return addrs
366367
367368 else :
368369 addrs = create_func ()
369- amount = amount or init_amount
370370
371371 # Fund source addresses
372- fund_addrs = addrs if fund_idx is None else [addrs [i ] for i in fund_idx ]
372+ selected_addrs = addrs if fund_idx is None else [addrs [i ] for i in fund_idx ]
373+ # The `selected_addrs` can be both `AddressRecord`s or `PoolUser`s
374+ payment_addrs = ((sa .payment if hasattr (sa , "payment" ) else sa ) for sa in selected_addrs )
375+ fund_addrs : list [clusterlib .AddressRecord ] = [
376+ a for a in payment_addrs if cluster_obj .g_query .get_address_balance (a .address ) < min_amount
377+ ]
373378 if fund_addrs :
374- amount = amount or min_amount
375379 clusterlib_utils .fund_from_faucet (
376380 * fund_addrs ,
377381 cluster_obj = cluster_obj ,
378382 all_faucets = cluster_manager .cache .addrs_data ,
379- amount = amount ,
383+ amount = fund_amount ,
384+ force = True ,
380385 )
381386
382387 return addrs
0 commit comments