Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix test suite configuration script #2402

Open
wants to merge 1 commit into
base: v1.8-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions scripts/configure_test_suite_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ MASTERNODE_OWNER_MASTER_PRIVATE_KEY=$(yq .hp_masternodes."$MASTERNODE_NAME".owne

if [[ "$NETWORK_STRING" == "devnet"* ]]; then
NETWORK=devnet
INSIGHT_URL="http://insight.${NETWORK_STRING#devnet-}.networks.dash.org:3001/insight-api/sync"
CERT_FLAG=":self-signed"
ST_EXECUTION_INTERVAL=5000
else
NETWORK=testnet
INSIGHT_URL="https://testnet-insight.dashevo.org/insight-api/sync"
CERT_FLAG=""
ST_EXECUTION_INTERVAL=15000
fi
SKIP_SYNC_BEFORE_HEIGHT=4800 # $(curl -s $INSIGHT_URL | jq '.height - 200')
INSIGHT_URL="http://insight.${NETWORK_STRING#devnet-}.networks.dash.org:3001/insight-api/sync"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for INSIGHT_URL construction

The dynamic URL construction using string manipulation could fail if the network string format changes. Consider adding validation:

+ if [[ ! "$NETWORK_STRING" =~ ^(devnet|devnet-.*|testnet)$ ]]; then
+   echo "Error: Invalid network string format: $NETWORK_STRING"
+   exit 1
+ fi
INSIGHT_URL="http://insight.${NETWORK_STRING#devnet-}.networks.dash.org:3001/insight-api/sync"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
INSIGHT_URL="http://insight.${NETWORK_STRING#devnet-}.networks.dash.org:3001/insight-api/sync"
if [[ ! "$NETWORK_STRING" =~ ^(devnet|devnet-.*|testnet)$ ]]; then
echo "Error: Invalid network string format: $NETWORK_STRING"
exit 1
fi
INSIGHT_URL="http://insight.${NETWORK_STRING#devnet-}.networks.dash.org:3001/insight-api/sync"

SKIP_SYNC_BEFORE_HEIGHT=$(curl -s $INSIGHT_URL | jq '.height - 200')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for height calculation

The curl command and height calculation lack error handling for network issues or invalid responses. Consider adding:

- SKIP_SYNC_BEFORE_HEIGHT=$(curl -s $INSIGHT_URL | jq '.height - 200')
+ # Add timeout and retry logic for curl
+ SYNC_DATA=$(curl -s -f --max-time 10 --retry 3 --retry-delay 2 $INSIGHT_URL)
+ if [ $? -ne 0 ]; then
+   echo "Error: Failed to fetch sync data from $INSIGHT_URL"
+   exit 1
+ fi
+ 
+ # Validate height exists and is a number
+ HEIGHT=$(echo "$SYNC_DATA" | jq -e '.height')
+ if [ $? -ne 0 ] || ! [[ "$HEIGHT" =~ ^[0-9]+$ ]]; then
+   echo "Error: Invalid height received from insight API"
+   exit 1
+ fi
+ 
+ SKIP_SYNC_BEFORE_HEIGHT=$((HEIGHT - 200))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SKIP_SYNC_BEFORE_HEIGHT=$(curl -s $INSIGHT_URL | jq '.height - 200')
# Add timeout and retry logic for curl
SYNC_DATA=$(curl -s -f --max-time 10 --retry 3 --retry-delay 2 $INSIGHT_URL)
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch sync data from $INSIGHT_URL"
exit 1
fi
# Validate height exists and is a number
HEIGHT=$(echo "$SYNC_DATA" | jq -e '.height')
if [ $? -ne 0 ] || ! [[ "$HEIGHT" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid height received from insight API"
exit 1
fi
SKIP_SYNC_BEFORE_HEIGHT=$((HEIGHT - 200))


# check variables are not empty
if [ -z "$FAUCET_ADDRESS" ] || \
Expand Down
Loading