Skip to content

Commit

Permalink
L1 Script Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mplatt8 authored May 28, 2024
1 parent 1d90258 commit 1c98985
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1c98985

Please sign in to comment.