aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/txnmall.sh
diff options
context:
space:
mode:
Diffstat (limited to 'qa/rpc-tests/txnmall.sh')
-rwxr-xr-xqa/rpc-tests/txnmall.sh58
1 files changed, 28 insertions, 30 deletions
diff --git a/qa/rpc-tests/txnmall.sh b/qa/rpc-tests/txnmall.sh
index 06e4f7102d..11e0276494 100755
--- a/qa/rpc-tests/txnmall.sh
+++ b/qa/rpc-tests/txnmall.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# Test block generation and basic wallet sending
+# Test proper accounting with malleable transactions
if [ $# -lt 1 ]; then
echo "Usage: $0 path_to_binaries"
@@ -35,16 +35,14 @@ B2ARGS="-datadir=$D2"
$BITCOIND $B2ARGS &
B2PID=$!
-trap "kill -9 $B1PID $B2PID; rm -rf $D" EXIT
-
-# Wait until all four nodes are at the same block number
+# Wait until both nodes are at the same block number
function WaitBlocks {
while :
do
sleep 1
- BLOCKS1=$( GetBlocks $B1ARGS )
- BLOCKS2=$( GetBlocks $B2ARGS )
- if (( $BLOCKS1 == $BLOCKS2 ))
+ declare -i BLOCKS1=$( GetBlocks $B1ARGS )
+ declare -i BLOCKS2=$( GetBlocks $B2ARGS )
+ if (( BLOCKS1 == BLOCKS2 ))
then
break
fi
@@ -55,8 +53,8 @@ function WaitBlocks {
function WaitPeers {
while :
do
- PEERS=$( $CLI $1 getconnectioncount )
- if (( "$PEERS" == $2 ))
+ declare -i PEERS=$( $CLI $1 getconnectioncount )
+ if (( PEERS == "$2" ))
then
break
fi
@@ -64,6 +62,8 @@ function WaitPeers {
done
}
+echo "Generating test blockchain..."
+
# Start with B2 connected to B1:
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
WaitPeers "$B1ARGS" 1
@@ -76,8 +76,8 @@ WaitBlocks
$CLI $B2ARGS setgenerate true 100
WaitBlocks
-CheckBalance $B1ARGS 50
-CheckBalance $B2ARGS 0
+CheckBalance "$B1ARGS" 50
+CheckBalance "$B2ARGS" 0
# restart B2 with no connection
$CLI $B2ARGS stop > /dev/null 2>&1
@@ -85,20 +85,18 @@ wait $B2PID
$BITCOIND $B2ARGS &
B2PID=$!
-B2ADDRESS=$( $CLI $B2ARGS getnewaddress )
+B2ADDRESS=$( $CLI $B2ARGS getaccountaddress "from1" )
# Have B1 create two transactions; second will
# spend change from first, since B1 starts with only a single
# 50 bitcoin output:
-$CLI $B1ARGS move "" "foo" 10.0
-$CLI $B1ARGS move "" "bar" 10.0
+$CLI $B1ARGS move "" "foo" 10.0 > /dev/null
+$CLI $B1ARGS move "" "bar" 10.0 > /dev/null
TXID1=$( $CLI $B1ARGS sendfrom foo $B2ADDRESS 1.0 0)
TXID2=$( $CLI $B1ARGS sendfrom bar $B2ADDRESS 2.0 0)
# Mutate TXID1 and add it to B2's memory pool:
RAWTX1=$( $CLI $B1ARGS getrawtransaction $TXID1 )
-RAWTX2=$( $CLI $B1ARGS getrawtransaction $TXID2 )
-# ... mutate RAWTX1:
# RAWTX1 is hex-encoded, serialized transaction. So each
# byte is two characters; we'll prepend the first
# "push" in the scriptsig with OP_PUSHDATA1 (0x4c),
@@ -123,28 +121,28 @@ echo "TXID1: " $TXID1
echo "Mutated: " $MUTATEDTXID
# Re-connect nodes, and have B2 mine a block
+# containing the mutant:
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
-WaitPeers "$B1ARGS" 1
-
-$CLI $B2ARGS setgenerate true 3
-WaitBlocks
-$CLI $B1ARGS setgenerate true 3
+$CLI $B2ARGS setgenerate true 1
WaitBlocks
+# B1 should have 49 BTC; the 2 BTC send is
+# conflicted, and should not count in
+# balances.
+CheckBalance "$B1ARGS" 49
+CheckBalance "$B1ARGS" 49 "*"
+CheckBalance "$B1ARGS" 9 "foo"
+CheckBalance "$B1ARGS" 10 "bar"
+
+# B2 should have 51 BTC
+CheckBalance "$B2ARGS" 51
+CheckBalance "$B2ARGS" 1 "from1"
+
$CLI $B2ARGS stop > /dev/null 2>&1
wait $B2PID
$CLI $B1ARGS stop > /dev/null 2>&1
wait $B1PID
-trap "" EXIT
-
-echo "Done, bitcoind's shut down. To rerun/poke around:"
-echo "${1}/bitcoind -datadir=$D1 -daemon"
-echo "${1}/bitcoind -datadir=$D2 -daemon -connect=127.0.0.1:11000"
-echo "To cleanup:"
-echo "killall bitcoind; rm -rf test.*"
-exit 0
-
echo "Tests successful, cleaning up"
rm -rf $D
exit 0