Add scripts to start bitcoin and zcash regtest daemons for running tests

This commit is contained in:
Jay Graber 2017-10-24 10:36:47 -07:00
parent 9f01f7fc30
commit 7c367b7c87
2 changed files with 123 additions and 0 deletions

31
xcat/tests/regtest.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
# load code from regtestlib
. regtestlib.sh
for arg in $@
do
case $arg in
-z*|--zcashsrc*)
ZCASHSRC="$2"
shift
shift
;;
-b*|--bitcoinsrc*)
BITCOINSRC="$2"
shift
shift
;;
esac
done
if [ "${ZCASHSRC}" != "" ]; then echo "Zcash source directory: ${ZCASHSRC}"; fi
if [ "${BITCOINSRC}" != "" ]; then echo "Bitcoin source directory: ${BITCOINSRC}"; fi
trap cleanup EXIT
start_bitcoin
start_zcash
echo "blockchains activated! sleeping foreverish..."
sleep 10000000

92
xcat/tests/regtestlib.sh Normal file
View File

@ -0,0 +1,92 @@
#!/bin/bash
export BITCOINDIR=$(pwd)/bitcoindir
ZCASHDIR=$(pwd)/zcashdir
echo $BITCOINDIR
echo $ZCASHDIR
fail() {
echo $@
exit 1
}
bitcoincli() {
if [ "${BITCOINSRC}" != "" ]; then
$BITCOINSRC/bitcoin-cli -datadir="$BITCOINDIR" -regtest -rpcserialversion=0 -rpcuser=user -rpcpassword=password $@
else
bitcoin-cli -datadir="$BITCOINDIR" -regtest -rpcserialversion=0 -rpcuser=user -rpcpassword=password $@
fi
}
bdaemon() {
if [ "${BITCOINSRC}" != "" ]; then
echo "Bitcoin source directory specified"
$BITCOINSRC/bitcoind -datadir="$BITCOINDIR" -rpcserialversion=0 -regtest -rpcuser=user -rpcpassword=password &
else
bitcoind -datadir="$BITCOINDIR" -rpcserialversion=0 -regtest -rpcuser=user -rpcpassword=password &
fi
}
start_bitcoin() {
echo "Starting bitcoin..."
mkdir "$BITCOINDIR"
bdaemon
echo $! > bitcoin_pid
sleep 5
for i in `seq 101`
do
printf "bitcoin block generate %d\r" $i
bitcoincli generate 1 > /dev/null
done
echo ""
}
stop_bitcoin() {
if [ -e bitcoin_pid ]; then kill $(cat bitcoin_pid); fi
rm -f bitcoin_pid
rm -rf "$BITCOINDIR"
}
zcashcli() {
if [ "${ZCASHSRC}" != "" ]; then
$ZCASHSRC/zcash-cli -datadir="$ZCASHDIR" -regtest $@
else
zcash-cli -datadir="$ZCASHDIR" -regtest $@
fi
}
zdaemon(){
if [ "${ZCASHSRC}" != "" ]; then
$ZCASHSRC/zcashd -datadir="$ZCASHDIR" -regtest -listen=0 &
else
zcashd -datadir="$ZCASHDIR" -regtest -listen=0 &
fi
}
start_zcash() {
echo "Starting zcash..."
mkdir "$ZCASHDIR"
echo "rpcuser=user" > "$ZCASHDIR/zcash.conf"
echo "rpcpassword=password" >> "$ZCASHDIR/zcash.conf"
zdaemon
echo $! > zcash_pid
sleep 5
for i in `seq 101`
do
printf "zcash block generate %d\r" $i
zcashcli generate 1 > /dev/null
done
echo ""
}
stop_zcash() {
if [ -e zcash_pid ]; then kill $(cat zcash_pid); fi
rm -f zcash_pid
rm -rf "$ZCASHDIR"
}
cleanup() {
stop_bitcoin
stop_zcash
}