@@ -336,48 +336,44 @@ def get_conway_address_deposit(cluster_obj: clusterlib.ClusterLib) -> int:
336336 return stake_deposit_amt
337337
338338
339- def get_payment_addrs (
340- name_template : str ,
339+ def _get_funded_addresses (
341340 cluster_manager : cluster_management .ClusterManager ,
342341 cluster_obj : clusterlib .ClusterLib ,
343- num : int ,
342+ create_func : tp . Callable [[], list ] ,
344343 fund_idx : list [int ] | None = None ,
345344 caching_key : str = "" ,
346- fund_just_once : bool = False ,
347345 amount : int | None = None ,
348- ) -> list [clusterlib .AddressRecord ]:
349- """Create new payment addresses."""
350- if num < 1 :
351- err = f"Number of addresses must be at least 1, got: { num } "
352- raise ValueError (err )
353-
354- def _create_addrs () -> list [clusterlib .AddressRecord ]:
355- addrs = clusterlib_utils .create_payment_addr_records (
356- * [f"{ name_template } _fund_addr_{ i } " for i in range (1 , num + 1 )],
357- cluster_obj = cluster_obj ,
358- )
359- return addrs
346+ ) -> 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
352+ min_amount = 50_000_000
360353
361354 if caching_key :
362- fixture_cache : cluster_management .FixtureCache [list [ clusterlib . AddressRecord ] | None ]
355+ fixture_cache : cluster_management .FixtureCache [list | None ]
363356 with cluster_manager .cache_fixture (key = caching_key ) as fixture_cache :
364357 if fixture_cache .value is None :
365- addrs = _create_addrs ()
358+ addrs = create_func ()
359+ amount = amount or init_amount
366360 fixture_cache .value = addrs
367361 else :
368362 addrs = fixture_cache .value
369- if fund_just_once :
363+ # If amount was passed, fund the addresses only initially
364+ if amount :
370365 return addrs
366+
371367 else :
372- addrs = _create_addrs ()
368+ addrs = create_func ()
369+ amount = amount or init_amount
373370
374371 # Fund source addresses
375- fund_addresses = addrs if fund_idx is None else [addrs [i ] for i in fund_idx ]
376- if fund_addresses :
377- if amount is None :
378- amount = 200_000_000
372+ fund_addrs = addrs if fund_idx is None else [addrs [i ] for i in fund_idx ]
373+ if fund_addrs :
374+ amount = amount or min_amount
379375 clusterlib_utils .fund_from_faucet (
380- * fund_addresses ,
376+ * fund_addrs ,
381377 cluster_obj = cluster_obj ,
382378 all_faucets = cluster_manager .cache .addrs_data ,
383379 amount = amount ,
@@ -386,12 +382,42 @@ def _create_addrs() -> list[clusterlib.AddressRecord]:
386382 return addrs
387383
388384
385+ def get_payment_addrs (
386+ name_template : str ,
387+ cluster_manager : cluster_management .ClusterManager ,
388+ cluster_obj : clusterlib .ClusterLib ,
389+ num : int ,
390+ fund_idx : list [int ] | None = None ,
391+ caching_key : str = "" ,
392+ amount : int | None = None ,
393+ ) -> list [clusterlib .AddressRecord ]:
394+ """Create new payment addresses."""
395+ if num < 1 :
396+ err = f"Number of addresses must be at least 1, got: { num } "
397+ raise ValueError (err )
398+
399+ def _create_addrs () -> list [clusterlib .AddressRecord ]:
400+ addrs = clusterlib_utils .create_payment_addr_records (
401+ * [f"{ name_template } _fund_addr_{ i } " for i in range (1 , num + 1 )],
402+ cluster_obj = cluster_obj ,
403+ )
404+ return addrs
405+
406+ return _get_funded_addresses (
407+ cluster_manager = cluster_manager ,
408+ cluster_obj = cluster_obj ,
409+ create_func = _create_addrs ,
410+ fund_idx = fund_idx ,
411+ caching_key = caching_key ,
412+ amount = amount ,
413+ )
414+
415+
389416def get_payment_addr (
390417 name_template : str ,
391418 cluster_manager : cluster_management .ClusterManager ,
392419 cluster_obj : clusterlib .ClusterLib ,
393420 caching_key : str = "" ,
394- fund_just_once : bool = False ,
395421 amount : int | None = None ,
396422) -> clusterlib .AddressRecord :
397423 """Create a single new payment address."""
@@ -401,7 +427,6 @@ def get_payment_addr(
401427 cluster_obj = cluster_obj ,
402428 num = 1 ,
403429 caching_key = caching_key ,
404- fund_just_once = fund_just_once ,
405430 amount = amount ,
406431 )[0 ]
407432
@@ -413,7 +438,6 @@ def get_pool_users(
413438 num : int ,
414439 fund_idx : list [int ] | None = None ,
415440 caching_key : str = "" ,
416- fund_just_once : bool = False ,
417441 amount : int | None = None ,
418442) -> list [clusterlib .PoolUser ]:
419443 """Create new pool users."""
@@ -429,41 +453,21 @@ def _create_pool_users() -> list[clusterlib.PoolUser]:
429453 )
430454 return users
431455
432- if caching_key :
433- fixture_cache : cluster_management .FixtureCache [list [clusterlib .PoolUser ] | None ]
434- with cluster_manager .cache_fixture (key = caching_key ) as fixture_cache :
435- if fixture_cache .value is None :
436- users = _create_pool_users ()
437- fixture_cache .value = users
438- else :
439- users = fixture_cache .value
440- if fund_just_once :
441- return users
442-
443- else :
444- users = _create_pool_users ()
445-
446- # Fund source addresses
447- fund_users = users if fund_idx is None else [users [i ] for i in fund_idx ]
448- if fund_users :
449- if amount is None :
450- amount = 200_000_000
451- clusterlib_utils .fund_from_faucet (
452- * fund_users ,
453- cluster_obj = cluster_obj ,
454- all_faucets = cluster_manager .cache .addrs_data ,
455- amount = amount ,
456- )
457-
458- return users
456+ return _get_funded_addresses (
457+ cluster_manager = cluster_manager ,
458+ cluster_obj = cluster_obj ,
459+ create_func = _create_pool_users ,
460+ fund_idx = fund_idx ,
461+ caching_key = caching_key ,
462+ amount = amount ,
463+ )
459464
460465
461466def get_pool_user (
462467 name_template : str ,
463468 cluster_manager : cluster_management .ClusterManager ,
464469 cluster_obj : clusterlib .ClusterLib ,
465470 caching_key : str = "" ,
466- fund_just_once : bool = False ,
467471 amount : int | None = None ,
468472) -> clusterlib .PoolUser :
469473 """Create a single new pool user."""
@@ -473,7 +477,6 @@ def get_pool_user(
473477 cluster_obj = cluster_obj ,
474478 num = 1 ,
475479 caching_key = caching_key ,
476- fund_just_once = fund_just_once ,
477480 amount = amount ,
478481 )[0 ]
479482
@@ -483,7 +486,6 @@ def get_registered_pool_user(
483486 cluster_manager : cluster_management .ClusterManager ,
484487 cluster_obj : clusterlib .ClusterLib ,
485488 caching_key : str = "" ,
486- fund_just_once : bool = False ,
487489 amount : int | None = None ,
488490) -> clusterlib .PoolUser :
489491 """Create new registered pool users."""
@@ -492,7 +494,6 @@ def get_registered_pool_user(
492494 cluster_manager = cluster_manager ,
493495 cluster_obj = cluster_obj ,
494496 caching_key = caching_key ,
495- fund_just_once = fund_just_once ,
496497 amount = amount ,
497498 )
498499
0 commit comments