Skip to content

Commit 754c3be

Browse files
authored
Merge pull request #2922 from IntersectMBO/log_testnet_faucet_balance
Log testnet faucet balance
2 parents d986f65 + 87cd087 commit 754c3be

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

cardano_node_tests/cluster_scripts/testnets/start-cluster

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ if [ -e "$SCRIPT_DIR/shell_env" ]; then
2525
source "$SCRIPT_DIR/shell_env"
2626
fi
2727

28+
get_address_balance() {
29+
local txhash txix amount total_amount _
30+
31+
# Repeat in case `query utxo` fails
32+
for _ in {1..3}; do
33+
total_amount=0
34+
while read -r txhash txix amount _; do
35+
if [ -z "$txhash" ] || [ -z "$txix" ]; then
36+
continue
37+
fi
38+
total_amount="$((total_amount + amount))"
39+
done <<< "$(cardano-cli latest query utxo "$@" | grep " lovelace")"
40+
41+
if [ "$total_amount" -gt 0 ]; then
42+
break
43+
fi
44+
done
45+
46+
echo "$total_amount"
47+
}
48+
2849
rm -rf "$STATE_CLUSTER"
2950
mkdir -p "$STATE_CLUSTER"/{byron,shelley,webserver}
3051
cd "$STATE_CLUSTER/.."
@@ -36,6 +57,12 @@ fi
3657

3758
# copy faucet address and keys
3859
cp "$TESTNET_DIR"/shelley/faucet.* "$STATE_CLUSTER/shelley"
60+
[ -e "$STATE_CLUSTER/shelley/faucet.addr" ] || \
61+
{ echo "The \`$STATE_CLUSTER/shelley/faucet.addr\` not found, line $LINENO" >&2; exit 1; } # assert
62+
[ -e "$STATE_CLUSTER/shelley/faucet.vkey" ] || \
63+
{ echo "The \`$STATE_CLUSTER/shelley/faucet.vkey\` not found, line $LINENO" >&2; exit 1; } # assert
64+
[ -e "$STATE_CLUSTER/shelley/faucet.skey" ] || \
65+
{ echo "The \`$STATE_CLUSTER/shelley/faucet.skey\` not found, line $LINENO" >&2; exit 1; } # assert
3966

4067
# copy configuration files
4168
cp "$SCRIPT_DIR"/cardano-node-* "$STATE_CLUSTER"
@@ -48,6 +75,8 @@ ln -rs "$STATE_CLUSTER/genesis-shelley.json" "$STATE_CLUSTER/shelley/genesis.jso
4875
ln -rs "$STATE_CLUSTER/genesis-alonzo.json" "$STATE_CLUSTER/shelley/genesis.alonzo.json"
4976
ln -rs "$STATE_CLUSTER/genesis-conway.json" "$STATE_CLUSTER/shelley/genesis.conway.json"
5077

78+
NETWORK_MAGIC="$(jq '.networkMagic' "$STATE_CLUSTER/shelley/genesis.json")"
79+
5180
# edit port numbers in configuration
5281
RELAY1_EKG="%%EKG_PORT_RELAY1%%"
5382
RELAY1_PROMETHEUS="%%PROMETHEUS_PORT_RELAY1%%"
@@ -174,7 +203,6 @@ done
174203
[ -S "$CARDANO_NODE_SOCKET_PATH" ] || { echo "Failed to start the relay node, line $LINENO" >&2; exit 1; } # assert
175204

176205
echo "Waiting to make sure the chain is synced"
177-
NETWORK_MAGIC="$(jq '.networkMagic' "$STATE_CLUSTER/shelley/genesis.json")"
178206
for _ in {1..600}; do
179207
sync_progress="$(cardano-cli query tip --testnet-magic "$NETWORK_MAGIC" | jq -r '.syncProgress')"
180208
if [ "$sync_progress" = "100.00" ]; then
@@ -208,4 +236,9 @@ if [ -n "${DBSYNC_REPO:-""}" ]; then
208236
done
209237
fi
210238

239+
get_address_balance \
240+
--testnet-magic "$NETWORK_MAGIC" \
241+
--address "$(<"$STATE_CLUSTER/shelley/faucet.addr")" \
242+
> "${STATE_CLUSTER}/start-cluster.log"
243+
211244
echo "Cluster started. Run \`$SCRIPT_DIR/stop-cluster\` to stop"

cardano_node_tests/utils/cluster_nodes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ def create_addrs_data(
274274
"payment": payment,
275275
}
276276

277+
faucet_balance = cluster_obj.g_query.get_address_balance(address=faucet_rec.address)
278+
LOGGER.info(f"Initial faucet balance: {faucet_balance}")
279+
277280
# Fund new addresses from faucet address
278281
LOGGER.debug("Funding created addresses.")
279282
to_fund = [d["payment"] for d in new_addrs_data.values()]
280-
faucet_balance = cluster_obj.g_query.get_address_balance(address=faucet_rec.address)
281283
amount_per_address = faucet_balance // len(self.test_addr_records)
282284
faucet.fund_from_faucet(
283285
*to_fund,

cardano_node_tests/utils/testnet_cleanup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,6 @@ def cleanup(
375375
defragment_utxos.defragment(
376376
cluster_obj=cluster_obj, address=faucet_payment.address, skey_file=faucet_payment.skey_file
377377
)
378+
379+
faucet_balance = cluster_obj.g_query.get_address_balance(address=faucet_payment.address)
380+
LOGGER.info(f"Final faucet balance: {faucet_balance}")

0 commit comments

Comments
 (0)