From 1c98985cdc39b6ce72c504e7fda8409439caf63e Mon Sep 17 00:00:00 2001 From: Marc Platt <97549900+mplatt8@users.noreply.github.com> Date: Tue, 28 May 2024 17:18:01 -0400 Subject: [PATCH] L1 Script Updates --- scripts/functions.sh | 73 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 7144125..7ebecd0 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1,59 +1,64 @@ +#!/bin/bash + +export RPC_USER="drivechain" +export RPC_PASSWORD="integrationtesting" +export RPC_HOST="127.0.0.1" +export RPC_PORT="18443" +export CONFIG_FILE="$HOME/.drivechain/drivechain.conf" + + function startdrivechain { - config_file=$1 + + # Ensure required binaries are present + if [ ! -f ./mainchain/src/qt/drivechain-qt ]; then + echo "ERROR: drivechain-qt binary not found" + exit 1 + fi + if [ ! -f ./mainchain/src/drivechain-cli ]; then + echo "ERROR: drivechain-cli binary not found" + exit 1 + fi if [ $REINDEX -eq 1 ]; then echo "drivechain will be reindexed" - ./mainchain/src/qt/drivechain-qt --reindex --regtest -conf=$config_file & + ./mainchain/src/qt/drivechain-qt --reindex --regtest -conf=$CONFIG_FILE & else - ./mainchain/src/qt/drivechain-qt --regtest -conf=$config_file & + ./mainchain/src/qt/drivechain-qt --regtest -conf=$CONFIG_FILE & fi sleep 15s - # start check + # Check if drivechain has started using curl for i in {1..5}; do - ./mainchain/src/drivechain-cli -conf=$config_file getblockcount > /dev/null 2>&1 + curl --user "${RPC_USER}:${RPC_PASSWORD}" --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://${RPC_HOST}:${RPC_PORT}/ > /dev/null 2>&1 if [ $? -eq 0 ]; then - echo "drivechain successfully started" - break + echo "drivechain successfully started (curl)" + break fi - echo "Checking if drivechain has started... attempt $i" + echo "Checking if drivechain has started (curl)... attempt $i" sleep 5s done if [ $? -ne 0 ]; then - echo "ERROR: drivechain failed to start" - exit 1 - fi - - testL1 $config_file - - if [ $? -ne 0 ]; then - echo "ERROR: L1 tests failed" + echo "ERROR: drivechain failed to start with curl" exit 1 fi - exit 0 -} - -# Function to perform L1 tests -function testL1 { - config_file=$1 - # mining tests - echo "Mining 1 block..." - ./mainchain/src/drivechain-cli -conf=$config_file generatetoaddress 1 $(./mainchain/src/drivechain-cli -conf=$config_file getnewaddress) > /dev/null - if [ $? -ne 0 ]; then - echo "ERROR: Failed to mine 1 block" - exit 1 - fi - echo "Successfully mined 1 block" + # Check if drivechain has started using drivechain-cli + for i in {1..5}; do + ./mainchain/src/drivechain-cli -conf=$CONFIG_FILE getblockcount > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "drivechain successfully started (cli)" + break + fi + echo "Checking if drivechain has started (cli)... attempt $i" + sleep 5s + done - echo "Mining 100 blocks..." - ./mainchain/src/drivechain-cli -conf=$config_file generatetoaddress 100 $(./mainchain/src/drivechain-cli -conf=$config_file getnewaddress) > /dev/null if [ $? -ne 0 ]; then - echo "ERROR: Failed to mine 100 blocks" + echo "ERROR: drivechain failed to start with cli" exit 1 fi - echo "Successfully mined 100 blocks" + echo "drivechain node started successfully with both curl and cli" exit 0 }