Skip to content

Commit e26f5e4

Browse files
committed
test: add script to verify Cardano DB restoration from client CLI snapshot command output
1 parent a319874 commit e26f5e4

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ $# -lt 1 ]]; then
6+
echo "Usage: $0 <file containing 'mithril-client' CLI download output> [--include-ancillary]"
7+
echo "The first argument must be the file path containing the raw output (stdout) of the mithril-client CLI download command."
8+
echo "The second optional argument must be '--include-ancillary' if ancillary files are included."
9+
exit 1
10+
fi
11+
12+
if [[ ! -f "$1" ]]; then
13+
echo "Error: File '$1' not found."
14+
exit 1
15+
fi
16+
17+
CLIENT_CMD_OUTPUT=$(cat "$1")
18+
INCLUDE_ANCILLARY="$2"
19+
20+
DOCKER_CMD=$(echo "$CLIENT_CMD_OUTPUT" | grep -E '^\s*docker run')
21+
if [[ -z "$DOCKER_CMD" ]]; then
22+
echo "No Docker command found in mithril-client CLI command output."
23+
exit 1
24+
fi
25+
26+
echo "Extracted Docker command:"
27+
echo "$DOCKER_CMD"
28+
29+
DOCKER_CMD_DETACHED="${DOCKER_CMD/docker run/docker run -d}"
30+
echo "Running Docker command in detached mode:"
31+
echo "$DOCKER_CMD_DETACHED"
32+
33+
CONTAINER_ID=$(eval "$DOCKER_CMD_DETACHED")
34+
35+
wait_for_log() {
36+
local CONTAINER_ID="$1"
37+
local TIMEOUT="$2"
38+
local LOG_MESSAGE="$3"
39+
40+
echo "Waiting up to $TIMEOUT seconds for '$LOG_MESSAGE'..."
41+
for ((i=1; i<=TIMEOUT; i++)); do
42+
if docker logs "$CONTAINER_ID" 2>&1 | grep -q "$LOG_MESSAGE"; then
43+
echo "Found '$LOG_MESSAGE' in logs."
44+
return 0
45+
fi
46+
sleep 1
47+
done
48+
49+
echo "'$LOG_MESSAGE' not found within $TIMEOUT seconds."
50+
docker logs "$CONTAINER_ID"
51+
return 1
52+
}
53+
54+
if wait_for_log "$CONTAINER_ID" 15 "Started opening Immutable DB"; then
55+
echo "✅ The Cardano node started successfully from the Mithril snapshot."
56+
else
57+
echo "❌ Failed to start the Cardano node from the Mithril snapshot."
58+
exit 1
59+
fi
60+
61+
if [[ "$INCLUDE_ANCILLARY" == "--include-ancillary" ]]; then
62+
echo "Parameter '--include-ancillary' is set."
63+
if wait_for_log "$CONTAINER_ID" 30 "Chain extended, new tip"; then
64+
echo "✅ The Cardano node started successfully from the Mithril snapshot with the ancillary files."
65+
exit 0
66+
else
67+
echo "❌ Failed to start the Cardano node from the Mithril snapshot with the ancillary files."
68+
exit 1
69+
fi
70+
else
71+
echo "Parameter '--include-ancillary' is not set."
72+
echo "Skipping additional check for 'Chain extended, new tip' in logs."
73+
exit 0
74+
fi

0 commit comments

Comments
 (0)