Skip to content

Commit 8491c69

Browse files
committed
refactor: improve testnet cleanup doc and comments
- Change return type of batch_tx_inputs to Generator - Add comment for deduplication in return_funds_to_faucet - Update docstring for cleanup_certs - Add detailed docstring for _get_faucet_payment_rec
1 parent 60e145f commit 8491c69

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cardano_node_tests/utils/testnet_cleanup.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
LOGGER = logging.getLogger(__name__)
2525

26-
2726
TxInputGroup = list[tuple[list[clusterlib.UTXOData], pl.Path]]
2827

2928

@@ -190,7 +189,9 @@ def dedup_tx_inputs(tx_inputs: TxInputGroup) -> TxInputGroup:
190189
return unique_inputs
191190

192191

193-
def batch_tx_inputs(tx_inputs: TxInputGroup, batch_size: int = 100) -> tp.Iterator[TxInputGroup]:
192+
def batch_tx_inputs(
193+
tx_inputs: TxInputGroup, batch_size: int = 100
194+
) -> tp.Generator[TxInputGroup, None, None]:
194195
"""Batch transaction inputs."""
195196
current_batch: TxInputGroup = []
196197
current_utxo_count = 0
@@ -240,6 +241,8 @@ def return_funds_to_faucet(
240241
# The amount of "-1" means all available funds.
241242
fund_dst = [clusterlib.TxOut(address=faucet_address, amount=-1)]
242243

244+
# Tx inputs deduplication is not strictly needed, as we are deduplicating the
245+
# address files. Keeping it here for separation of concerns.
243246
for batch in batch_tx_inputs(tx_inputs=dedup_tx_inputs(tx_inputs=tx_inputs)):
244247
txins, skeys = flatten_tx_inputs(tx_inputs=batch)
245248
fund_tx_files = clusterlib.TxFiles(signing_key_files=skeys)
@@ -400,7 +403,7 @@ def _run(files: list[pl.Path], f_addr: clusterlib.AddressRecord) -> TxInputGroup
400403
def cleanup_certs(
401404
cluster_obj: clusterlib.ClusterLib, location: pl.Path, faucet_payment: clusterlib.AddressRecord
402405
) -> None:
403-
"""Cleanup DRep certs."""
406+
"""Cleanup certificates."""
404407
files_found = list(find_cert_files(location))
405408
num_threads = min(10, (len(files_found) // 10) + 1)
406409
file_chunks = [files_found[i::num_threads] for i in range(num_threads)]
@@ -461,6 +464,11 @@ def _get_faucet_payment_rec(
461464
address: str = "",
462465
skey_file: clusterlib.FileType = "",
463466
) -> clusterlib.AddressRecord:
467+
"""Get the faucet payment record.
468+
469+
If address or skey_file is provided, use them to create the record.
470+
Otherwise, infer the faucet address and keys from the cluster environment.
471+
"""
464472
if address or skey_file:
465473
if not (address and skey_file):
466474
err = "Both 'address' and 'skey_file' need to be set."

0 commit comments

Comments
 (0)