Skip to content

Commit d802fca

Browse files
committed
feat: add get_payment_addrs function
Updated test files to use the common get_payment_addrs function.
1 parent 7300d1d commit d802fca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+339
-774
lines changed

cardano_node_tests/tests/common.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,38 +326,63 @@ def get_conway_address_deposit(cluster_obj: clusterlib.ClusterLib) -> int:
326326
return stake_deposit_amt
327327

328328

329-
def get_payment_addr(
329+
def get_payment_addrs(
330330
name_template: str,
331331
cluster_manager: cluster_management.ClusterManager,
332332
cluster_obj: clusterlib.ClusterLib,
333+
num: int,
334+
fund_idx: list[int] | None = None,
333335
caching_key: str = "",
334336
amount: int | None = None,
335-
) -> clusterlib.AddressRecord:
336-
"""Create new payment address."""
337-
338-
def _create_addr() -> clusterlib.AddressRecord:
339-
addr = clusterlib_utils.create_payment_addr_records(
340-
f"{name_template}_fund_addr",
337+
) -> list[clusterlib.AddressRecord]:
338+
"""Create new payment addresses."""
339+
if num < 1:
340+
err = f"Number of addresses must be at least 1, got: {num}"
341+
raise ValueError(err)
342+
343+
def _create_addrs() -> list[clusterlib.AddressRecord]:
344+
addrs = clusterlib_utils.create_payment_addr_records(
345+
*[f"{name_template}_fund_addr_{i}" for i in range(1, num + 1)],
341346
cluster_obj=cluster_obj,
342-
)[0]
343-
return addr
347+
)
348+
return addrs
344349

345350
if caching_key:
346351
with cluster_manager.cache_fixture(key=caching_key) as fixture_cache:
347352
if fixture_cache.value:
348353
return fixture_cache.value # type: ignore
349354

350-
addr = _create_addr()
351-
fixture_cache.value = addr
355+
addrs = _create_addrs()
356+
fixture_cache.value = addrs
352357
else:
353-
addr = _create_addr()
358+
addrs = _create_addrs()
354359

355360
# Fund source address
356-
clusterlib_utils.fund_from_faucet(
357-
addr,
361+
fund_addresses = addrs if fund_idx is None else [addrs[i] for i in fund_idx]
362+
if fund_addresses:
363+
clusterlib_utils.fund_from_faucet(
364+
*fund_addresses,
365+
cluster_obj=cluster_obj,
366+
all_faucets=cluster_manager.cache.addrs_data,
367+
amount=amount,
368+
)
369+
370+
return addrs
371+
372+
373+
def get_payment_addr(
374+
name_template: str,
375+
cluster_manager: cluster_management.ClusterManager,
376+
cluster_obj: clusterlib.ClusterLib,
377+
caching_key: str = "",
378+
amount: int | None = None,
379+
) -> clusterlib.AddressRecord:
380+
"""Create a single new payment address."""
381+
return get_payment_addrs(
382+
name_template=name_template,
383+
cluster_manager=cluster_manager,
358384
cluster_obj=cluster_obj,
359-
all_faucets=cluster_manager.cache.addrs_data,
385+
num=1,
386+
caching_key=caching_key,
360387
amount=amount,
361-
)
362-
363-
return addr
388+
)[0]

cardano_node_tests/tests/test_blocks.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,12 @@ def payment_addrs(
255255
cluster: clusterlib.ClusterLib,
256256
) -> list[clusterlib.AddressRecord]:
257257
"""Create new payment addresses."""
258-
with cluster_manager.cache_fixture() as fixture_cache:
259-
if fixture_cache.value:
260-
return fixture_cache.value # type: ignore
261-
262-
addrs = clusterlib_utils.create_payment_addr_records(
263-
*[
264-
f"addr_block_prod_ci{cluster_manager.cluster_instance_num}_{i}"
265-
for i in range(20)
266-
],
267-
cluster_obj=cluster,
268-
)
269-
fixture_cache.value = addrs
270-
271-
# Fund source addresses
272-
clusterlib_utils.fund_from_faucet(
273-
*addrs,
258+
addrs = common.get_payment_addrs(
259+
name_template=common.get_test_id(cluster),
260+
cluster_manager=cluster_manager,
274261
cluster_obj=cluster,
275-
all_faucets=cluster_manager.cache.addrs_data,
262+
num=20,
263+
caching_key=helpers.get_current_line_str(),
276264
)
277265
return addrs
278266

@@ -451,17 +439,11 @@ def payment_addrs(
451439
) -> list[clusterlib.AddressRecord]:
452440
"""Create new payment addresses."""
453441
cluster = cluster_singleton
454-
455-
addrs = clusterlib_utils.create_payment_addr_records(
456-
*[f"addr_dyn_prod_ci{cluster_manager.cluster_instance_num}_{i}" for i in range(20)],
457-
cluster_obj=cluster,
458-
)
459-
460-
# Fund source addresses
461-
clusterlib_utils.fund_from_faucet(
462-
*addrs,
442+
addrs = common.get_payment_addrs(
443+
name_template=common.get_test_id(cluster),
444+
cluster_manager=cluster_manager,
463445
cluster_obj=cluster,
464-
all_faucets=cluster_manager.cache.addrs_data,
446+
num=20,
465447
)
466448
return addrs
467449

cardano_node_tests/tests/test_env_network_id.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from cardano_node_tests.cluster_management import cluster_management
1313
from cardano_node_tests.tests import common
14-
from cardano_node_tests.utils import clusterlib_utils
1514
from cardano_node_tests.utils import helpers
1615
from cardano_node_tests.utils import logfiles
1716

@@ -102,23 +101,14 @@ def payment_addrs(
102101
) -> list[clusterlib.AddressRecord]:
103102
"""Create new payment addresses."""
104103
# pylint: disable=unused-argument
105-
with cluster_manager.cache_fixture() as fixture_cache:
106-
if fixture_cache.value:
107-
return fixture_cache.value # type: ignore
108-
109-
addrs = clusterlib_utils.create_payment_addr_records(
110-
f"addr_network_env_ci{cluster_manager.cluster_instance_num}_0",
111-
f"addr_network_env_ci{cluster_manager.cluster_instance_num}_1",
112-
cluster_obj=cluster,
113-
)
114-
fixture_cache.value = addrs
115-
116-
# Fund source addresses
117-
clusterlib_utils.fund_from_faucet(
118-
addrs[0],
104+
addrs = common.get_payment_addrs(
105+
name_template=common.get_test_id(cluster),
106+
cluster_manager=cluster_manager,
119107
cluster_obj=cluster,
120-
all_faucets=cluster_manager.cache.addrs_data,
121-
amount=100_000_000,
108+
num=2,
109+
fund_idx=[0],
110+
caching_key=helpers.get_current_line_str(),
111+
amount=1_000_000_000,
122112
)
123113
return addrs
124114

cardano_node_tests/tests/test_native_tokens.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,26 +1656,14 @@ def payment_addrs(
16561656
cluster: clusterlib.ClusterLib,
16571657
) -> list[clusterlib.AddressRecord]:
16581658
"""Create new payment addresses."""
1659-
with cluster_manager.cache_fixture() as fixture_cache:
1660-
if fixture_cache.value:
1661-
return fixture_cache.value # type: ignore
1662-
1663-
addrs = clusterlib_utils.create_payment_addr_records(
1664-
*[
1665-
f"token_transfer_ci{cluster_manager.cluster_instance_num}_{i}"
1666-
for i in range(10)
1667-
],
1668-
cluster_obj=cluster,
1669-
)
1670-
fixture_cache.value = addrs
1671-
1672-
# Fund source addresses
1673-
clusterlib_utils.fund_from_faucet(
1674-
addrs[0],
1659+
addrs = common.get_payment_addrs(
1660+
name_template=common.get_test_id(cluster),
1661+
cluster_manager=cluster_manager,
16751662
cluster_obj=cluster,
1676-
all_faucets=cluster_manager.cache.addrs_data,
1663+
num=10,
1664+
fund_idx=[0],
1665+
caching_key=helpers.get_current_line_str(),
16771666
)
1678-
16791667
return addrs
16801668

16811669
@pytest.fixture

cardano_node_tests/tests/test_reconnect.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from cardano_node_tests.cluster_management import cluster_management
1515
from cardano_node_tests.tests import common
1616
from cardano_node_tests.utils import cluster_nodes
17-
from cardano_node_tests.utils import clusterlib_utils
1817
from cardano_node_tests.utils import configuration
1918
from cardano_node_tests.utils import helpers
2019
from cardano_node_tests.utils.versions import VERSIONS
@@ -44,26 +43,12 @@ def payment_addrs(
4443
) -> list[clusterlib.AddressRecord]:
4544
"""Create new payment addresses."""
4645
cluster = cluster_singleton
47-
num_addrs = 2
48-
49-
with cluster_manager.cache_fixture() as fixture_cache:
50-
if fixture_cache.value:
51-
return fixture_cache.value # type: ignore
52-
53-
addrs = clusterlib_utils.create_payment_addr_records(
54-
*[
55-
f"addr_rollback_ci{cluster_manager.cluster_instance_num}_{i}"
56-
for i in range(num_addrs)
57-
],
58-
cluster_obj=cluster,
59-
)
60-
fixture_cache.value = addrs
61-
62-
# Fund source addresses
63-
clusterlib_utils.fund_from_faucet(
64-
*addrs,
46+
addrs = common.get_payment_addrs(
47+
name_template=common.get_test_id(cluster),
48+
cluster_manager=cluster_manager,
6549
cluster_obj=cluster,
66-
all_faucets=cluster_manager.cache.addrs_data,
50+
num=2,
51+
caching_key=helpers.get_current_line_str(),
6752
)
6853
return addrs
6954

cardano_node_tests/tests/test_rollback.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from cardano_node_tests.cluster_management import cluster_management
1818
from cardano_node_tests.tests import common
1919
from cardano_node_tests.utils import cluster_nodes
20-
from cardano_node_tests.utils import clusterlib_utils
2120
from cardano_node_tests.utils import configuration
2221
from cardano_node_tests.utils import helpers
2322
from cardano_node_tests.utils.versions import VERSIONS
@@ -52,26 +51,12 @@ def payment_addrs(
5251
) -> list[clusterlib.AddressRecord]:
5352
"""Create new payment addresses."""
5453
cluster = cluster_singleton
55-
num_addrs = 4 if ROLLBACK_PAUSE else 3
56-
57-
with cluster_manager.cache_fixture() as fixture_cache:
58-
if fixture_cache.value:
59-
return fixture_cache.value # type: ignore
60-
61-
addrs = clusterlib_utils.create_payment_addr_records(
62-
*[
63-
f"addr_rollback_ci{cluster_manager.cluster_instance_num}_{i}"
64-
for i in range(num_addrs)
65-
],
66-
cluster_obj=cluster,
67-
)
68-
fixture_cache.value = addrs
69-
70-
# Fund source addresses
71-
clusterlib_utils.fund_from_faucet(
72-
*addrs,
54+
addrs = common.get_payment_addrs(
55+
name_template=common.get_test_id(cluster),
56+
cluster_manager=cluster_manager,
7357
cluster_obj=cluster,
74-
all_faucets=cluster_manager.cache.addrs_data,
58+
num=4 if ROLLBACK_PAUSE else 3,
59+
caching_key=helpers.get_current_line_str(),
7560
)
7661
return addrs
7762

0 commit comments

Comments
 (0)