daemon: clean up test dirs.

Move final helpers out of test-cli/

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-05-02 16:02:56 +09:30
parent 064309df1a
commit 4bbb86ae30
10 changed files with 7 additions and 49 deletions

View File

@@ -0,0 +1,21 @@
#! /bin/sh
# Generate a block.
set -e
. `dirname $0`/vars.sh
INIT=$1
# Initially we need 100 blocks so coinbase matures, giving us funds.
if [ -n "$INIT" ]; then
# To activate segwit via BIP9, we need at least 432 blocks!
$CLI generate 432
if $CLI getblockchaininfo | tr -s '\012\011 ' ' ' | grep -q '{ "id": "witness", "status": "active" }'; then :
else
echo "Segwit not activated after 432 blocks?" >&2
$CLI getblockchaininfo >&2
exit 1
fi
else
$CLI generate 1
fi

View File

@@ -0,0 +1,17 @@
#! /bin/sh
# Alpha defaults to confidential addresses. We don't handle those (yet?)
# so extract the unconfidential address.
set -e
. `dirname $0`/vars.sh
case $STYLE in
alpha)
A=`$CLI getnewaddress`
$CLI validateaddress $A | sed -n 's/.*"unconfidential" : "\([A-Za-z0-9]*\)".*/\1/p'
;;
bitcoin)
$CLI getnewaddress
;;
esac

29
daemon/test/scripts/getinput.sh Executable file
View File

@@ -0,0 +1,29 @@
#! /bin/sh
# Query bitcoind to get (first) unspent output to spend.
###
# Nobody should *EVER* write code like this. EVER!!
###
set -e
. `dirname $0`/vars.sh
NUM=1
if [ $# = 1 ]; then
NUM=$1
shift
fi
if [ $# -gt 0 ]; then
echo "Usage: getinput.sh [INPUT-INDEX]"
exit 1
fi
TXID=`$CLI listunspent | sed -n 's/^ *"txid" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
OUTNUM=`$CLI listunspent | sed -n 's/^ *"vout" *: *\([0-9]*\),$/\1/p' | tail -n +$NUM | head -n1`
AMOUNT=`$CLI listunspent | sed -n 's/^ *"amount" *: *\([0-9.]*\),$/\1/p' | tail -n +$NUM | head -n1 | tr -d . | sed 's/^0*//'`
SCRIPT=`$CLI listunspent | sed -n 's/^ *"scriptPubKey" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
ADDR=`$CLI listunspent | sed -n 's/^ *"address" *: *"\([0-9a-zA-Z]*\)",$/\1/p' | tail -n +$NUM | head -n1`
PRIVKEY=`$CLI dumpprivkey $ADDR`
echo $TXID/$OUTNUM/$AMOUNT/$SCRIPT/$PRIVKEY

43
daemon/test/scripts/setup.sh Executable file
View File

@@ -0,0 +1,43 @@
#! /bin/sh -e
. `dirname $0`/vars.sh
if $CLI getinfo 2>/dev/null; then
echo $DAEMON already running >&2
exit 1
fi
# Start clean
rm -rf $DATADIR
mkdir $DATADIR
# Create appropriate config file so cmdline matches.
cat > $DATADIR/bitcoin.conf <<EOF
regtest=1
testnet=0
EOF
$DAEMON &
i=0
while ! $CLI getinfo >/dev/null 2>&1; do
if [ $i -gt 30 ]; then
echo $DAEMON start failed? >&1
exit 1
fi
sleep 1
i=$(($i + 1))
done
# Make sure they have segwit support!
if $CLI getblockchaininfo | grep -q '"witness"'; then :
else
echo This bitcoind does not have segwit support. >&2
echo Please install one from https://github.com/sipa/bitcoin/tree/segwit4 >&2
exit 1
fi
scripts/generate-block.sh init
A1=`scripts/get-new-address.sh`
TX=`$CLI sendmany "" "{ \"$A1\":0.01 }"`
scripts/generate-block.sh

View File

@@ -0,0 +1,6 @@
#! /bin/sh -e
. `dirname $0`/vars.sh
$CLI stop
sleep 1 # Make sure socket is closed.

View File

@@ -0,0 +1,14 @@
# Sourced by other scripts
STYLE=bitcoin
DATADIR=/tmp/bitcoin-lightning
CLI="bitcoin-cli -datadir=$DATADIR"
REGTESTDIR=regtest
DAEMON="bitcoind -datadir=$DATADIR"
if grep ^FEATURES ../Makefile | cut -d'#' -f1 | grep -q BIP68; then
SEQ_ENFORCEMENT=true
else
SEQ_ENFORCEMENT=false
fi
#PREFIX="valgrind --vgdb-error=1"