From 9e7776bf1f1aebbd6e1ef21a4144ba72a54985de Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 21 Nov 2013 16:57:25 +1000 Subject: Integration tests via RPC calls qa/rpc-tests/wallet.sh runs a three-node -regtest network, generates a fresh blockchain, and then exercises basic wallet sending/receiving functionality using command-line RPC. --- qa/rpc-tests/util.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 qa/rpc-tests/util.sh (limited to 'qa/rpc-tests/util.sh') diff --git a/qa/rpc-tests/util.sh b/qa/rpc-tests/util.sh new file mode 100644 index 0000000000..dc2a319970 --- /dev/null +++ b/qa/rpc-tests/util.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +# Functions used by more than one test + +function echoerr { + echo "$@" 1>&2; +} + +# Usage: ExtractKey "" +# Warning: this will only work for the very-well-behaved +# JSON produced by bitcoind, do NOT use it to try to +# parse arbitrary/nested/etc JSON. +function ExtractKey { + echo $2 | tr -d ' "{}\n' | awk -v RS=',' -F: "\$1 ~ /$1/ { print \$2}" +} + +function CreateDataDir { + DIR=$1 + mkdir -p $DIR + CONF=$DIR/bitcoin.conf + echo "regtest=1" >> $CONF + echo "keypool=2" >> $CONF + echo "rpcuser=rt" >> $CONF + echo "rpcpassword=rt" >> $CONF + echo "rpcwait=1" >> $CONF + shift + while (( "$#" )); do + echo $1 >> $CONF + shift + done +} + +function AssertEqual { + if (( $( echo "$1 == $2" | bc ) == 0 )) + then + echoerr "AssertEqual: $1 != $2" + exit 1 + fi +} + +# CheckBalance -datadir=... amount account minconf +function CheckBalance { + B=$( $CLI $1 getbalance $3 $4 ) + if (( $( echo "$B == $2" | bc ) == 0 )) + then + echoerr "bad balance: $B (expected $2)" + exit 1 + fi +} + +# Use: Address [account] +function Address { + $CLI $1 getnewaddress $2 +} + +# Send from to amount +function Send { + from=$1 + to=$2 + amount=$3 + address=$(Address $to) + txid=$( $CLI $from sendtoaddress $address $amount ) +} + +# Use: Unspent +function Unspent { + local r=$( $CLI $1 listunspent | awk -F'[ |:,"]+' "\$2 ~ /$3/ { print \$3 }" | tail -n $2 | head -n 1) + echo $r +} + +# Use: CreateTxn1 +# produces hex from signrawtransaction +function CreateTxn1 { + TXID=$(Unspent $1 $2 txid) + AMOUNT=$(Unspent $1 $2 amount) + VOUT=$(Unspent $1 $2 vout) + RAWTXN=$( $CLI $1 createrawtransaction "[{\"txid\":\"$TXID\",\"vout\":$VOUT}]" "{\"$3\":$AMOUNT}") + ExtractKey hex "$( $CLI $1 signrawtransaction $RAWTXN )" +} + +# Use: SendRawTxn +function SendRawTxn { + $CLI $1 sendrawtransaction $2 +} -- cgit v1.2.3