Skip to content

Commit f46babc

Browse files
committed
Merge pull request #3451
5fe19d6 qt: make wallet test consistent (Wladimir J. van der Laan)
2 parents 3653501 + 5fe19d6 commit f46babc

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

qa/rpc-tests/util.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ function CreateTxn1 {
8282
function SendRawTxn {
8383
$CLI $1 sendrawtransaction $2
8484
}
85+
86+
# Use: GetBlocks <datadir>
87+
# returns number of blocks from getinfo
88+
function GetBlocks {
89+
ExtractKey blocks "$( $CLI $1 getinfo )"
90+
}

qa/rpc-tests/wallet.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,27 @@ B3PID=$!
3737

3838
trap "kill -9 $B1PID $B2PID $B3PID; rm -rf $D" EXIT
3939

40+
# Wait until all three nodes are at the same block number
41+
function WaitBlocks {
42+
while :
43+
do
44+
sleep 1
45+
BLOCKS1=$( GetBlocks $B1ARGS )
46+
BLOCKS2=$( GetBlocks $B2ARGS )
47+
BLOCKS3=$( GetBlocks $B3ARGS )
48+
if (( $BLOCKS1 == $BLOCKS2 && $BLOCKS2 == $BLOCKS3 ))
49+
then
50+
break
51+
fi
52+
done
53+
}
54+
4055
# 1 block, 50 XBT each == 50 XBT
4156
$CLI $B1ARGS setgenerate true 1
42-
sleep 1 # sleep is necessary to let block broadcast
57+
WaitBlocks
4358
# 101 blocks, 1 mature == 50 XBT
4459
$CLI $B2ARGS setgenerate true 101
45-
sleep 1
60+
WaitBlocks
4661

4762
CheckBalance $B1ARGS 50
4863
CheckBalance $B2ARGS 50
@@ -56,11 +71,11 @@ Send $B1ARGS $B3ARGS 10
5671
# Have B1 mine a new block, and mature it
5772
# to recover transaction fees
5873
$CLI $B1ARGS setgenerate true 1
59-
sleep 1
74+
WaitBlocks
6075

6176
# Have B2 mine 100 blocks so B1's block is mature:
6277
$CLI $B2ARGS setgenerate true 100
63-
sleep 1
78+
WaitBlocks
6479

6580
# B1 should end up with 100 XBT in block rewards plus fees,
6681
# minus the 21 XBT sent to B3:
@@ -77,7 +92,7 @@ RAWTXID2=$(SendRawTxn $B2ARGS $RAW2)
7792

7893
# Have B2 mine a block to confirm transactions:
7994
$CLI $B2ARGS setgenerate true 1
80-
sleep 1 # allow time for block to be relayed
95+
WaitBlocks
8196

8297
# Check balances after confirmation
8398
CheckBalance $B1ARGS 0

0 commit comments

Comments
 (0)