Skip to content

Commit 18f50d4

Browse files
authored
Merge pull request #2994 from IntersectMBO/imp_address_funding
Improve address funding
2 parents 1e86532 + d0da67b commit 18f50d4

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

cardano_node_tests/tests/common.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

cardano_node_tests/tests/test_delegation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _get_pool_users(
280280

281281
# Fund payment addresses
282282
clusterlib_utils.fund_from_faucet(
283-
*pool_users,
283+
*[u.payment for u in pool_users],
284284
cluster_obj=cluster,
285285
all_faucets=cluster_manager.cache.addrs_data,
286286
amount=200_000_000,

cardano_node_tests/tests/test_staking_no_rewards.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_no_reward_unmet_pledge1(
157157
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
158158
# are deducted
159159
clusterlib_utils.fund_from_faucet(
160-
pool_owner,
160+
pool_owner.payment,
161161
cluster_obj=cluster,
162162
all_faucets=cluster_manager.cache.addrs_data,
163163
amount=900_000_000,
@@ -317,7 +317,7 @@ def test_no_reward_unmet_pledge2(
317317

318318
# Fund user address so it has enough funds for fees etc.
319319
clusterlib_utils.fund_from_faucet(
320-
delegation_out.pool_user,
320+
delegation_out.pool_user.payment,
321321
cluster_obj=cluster,
322322
all_faucets=cluster_manager.cache.addrs_data,
323323
amount=900_000_000,
@@ -499,7 +499,7 @@ def test_no_reward_deregistered_stake_addr(
499499
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
500500
# are deducted
501501
clusterlib_utils.fund_from_faucet(
502-
pool_owner,
502+
pool_owner.payment,
503503
cluster_obj=cluster,
504504
all_faucets=cluster_manager.cache.addrs_data,
505505
amount=900_000_000,
@@ -695,7 +695,7 @@ def test_no_reward_deregistered_reward_addr(
695695
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
696696
# are deducted
697697
clusterlib_utils.fund_from_faucet(
698-
pool_reward,
698+
pool_reward.payment,
699699
cluster_obj=cluster,
700700
all_faucets=cluster_manager.cache.addrs_data,
701701
amount=900_000_000,
@@ -861,7 +861,7 @@ def test_deregister_reward_addr_retire_pool(
861861
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
862862
# are deducted
863863
clusterlib_utils.fund_from_faucet(
864-
pool_owner,
864+
pool_owner.payment,
865865
cluster_obj=cluster,
866866
all_faucets=cluster_manager.cache.addrs_data,
867867
amount=900_000_000,

cardano_node_tests/tests/test_staking_rewards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def test_reward_addr_delegation( # noqa: C901
663663
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
664664
# are deducted
665665
clusterlib_utils.fund_from_faucet(
666-
pool_owner,
666+
pool_owner.payment,
667667
cluster_obj=cluster,
668668
all_faucets=cluster_manager.cache.addrs_data,
669669
amount=900_000_000,
@@ -1189,7 +1189,7 @@ def test_2_pools_same_reward_addr( # noqa: C901
11891189
# Fund pool owner's addresses so balance keeps higher than pool pledge after fees etc.
11901190
# are deducted
11911191
clusterlib_utils.fund_from_faucet(
1192-
pool2_owner,
1192+
pool2_owner.payment,
11931193
cluster_obj=cluster,
11941194
all_faucets=cluster_manager.cache.addrs_data,
11951195
amount=900_000_000,

cardano_node_tests/tests/tests_conway/test_drep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ def _check_records() -> list[blockers.GH]:
19601960
no_of_addr=2,
19611961
)
19621962
clusterlib_utils.fund_from_faucet(
1963-
*drep_users,
1963+
*[d.payment for d in drep_users],
19641964
cluster_obj=cluster,
19651965
faucet_data=cluster_manager.cache.addrs_data["faucet"],
19661966
# Add a lot of funds so no action can be ratified without the new DReps

cardano_node_tests/utils/faucet.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def fund_from_faucet(
16-
*dst_addrs: clusterlib.AddressRecord | clusterlib.PoolUser,
16+
*dst_addrs: clusterlib.AddressRecord,
1717
cluster_obj: clusterlib.ClusterLib,
1818
faucet_data: dict | None = None,
1919
all_faucets: dict[str, dict] | None = None,
@@ -27,16 +27,12 @@ def fund_from_faucet(
2727
msg = "Either `faucet_data` or `all_faucets` must be provided."
2828
raise AssertionError(msg)
2929

30-
# Get payment AddressRecord out of PoolUser
31-
dst_addr_records: list[clusterlib.AddressRecord] = [
32-
(r.payment if hasattr(r, "payment") else r) for r in dst_addrs
33-
]
3430
if isinstance(amount, int):
35-
amount = [amount] * len(dst_addr_records)
31+
amount = [amount] * len(dst_addrs)
3632

3733
fund_txouts = [
3834
clusterlib.TxOut(address=d.address, amount=a)
39-
for d, a in zip(dst_addr_records, amount)
35+
for d, a in zip(dst_addrs, amount)
4036
if force or cluster_obj.g_query.get_address_balance(d.address) < a
4137
]
4238
if not fund_txouts:

cardano_node_tests/utils/governance_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def create_vote_stake(
109109

110110
# Fund the payment address with some ADA
111111
clusterlib_utils.fund_from_faucet(
112-
*pool_users,
112+
*[u.payment for u in pool_users],
113113
cluster_obj=cluster_obj,
114114
faucet_data=cluster_manager.cache.addrs_data["faucet"],
115115
amount=500_000_000_000,

0 commit comments

Comments
 (0)