1616
1717rm -rf data/
1818mkdir -p data/{bitcoin,electrum,electrs}
19+ touch data/electrs/regtest-debug.log data/electrum/regtest-debug.log
1920
2021cleanup () {
2122 trap - SIGTERM SIGINT
@@ -34,19 +35,51 @@ wait_for() {
3435 shift
3536 TEST_ARGS=$*
3637 for _ in ` seq 0 9` ; do
37- test " $( $CMD | jq -c .) " $TEST_ARGS && break || sleep 2
38+ if test " $( $CMD | jq -c .) " $TEST_ARGS ; then
39+ return 0
40+ fi
41+ sleep 2
3842 done
43+
44+ echo " Timed out waiting for condition: $CMD $TEST_ARGS " >&2
45+ return 1
46+ }
47+
48+ wait_for_log () {
49+ LOG_FILE=$1
50+ PATTERN=$2
51+ DESCRIPTION=$3
52+ for _ in ` seq 0 99` ; do
53+ if grep -Fq " $PATTERN " " $LOG_FILE " ; then
54+ return 0
55+ fi
56+ sleep 0.2
57+ done
58+
59+ echo " Timed out waiting for $DESCRIPTION in $LOG_FILE " >&2
60+ tail -n +1 " $LOG_FILE " >&2 || true
61+ return 1
62+ }
63+
64+ wait_for_http () {
65+ URL=$1
66+ OUTPUT=$2
67+ for _ in ` seq 0 99` ; do
68+ if curl --silent --show-error --fail " $URL " -o " $OUTPUT " ; then
69+ return 0
70+ fi
71+ sleep 0.2
72+ done
73+
74+ echo " Timed out waiting for HTTP endpoint $URL " >&2
75+ return 1
3976}
4077
4178BTC=" $BITCOIN_MULTIPROCESS_BIN rpc -chain=regtest -datadir=$PWD /data/bitcoin"
4279ELECTRUM=" electrum --regtest"
4380EL=" $ELECTRUM --wallet=data/electrum/wallet"
4481SOCK=" $PWD /data/bitcoin/regtest/node.sock"
4582
46- tail_log () {
47- tail -n +0 -F $1 || true
48- }
49-
5083echo " Starting $( $BITCOIN_MULTIPROCESS_BIN node -version | head -n1) (multiprocess, IPC enabled)..."
5184$BITCOIN_MULTIPROCESS_BIN node \
5285 -regtest -datadir=$PWD /data/bitcoin \
@@ -80,7 +113,7 @@ electrs \
80113 --daemon-ipc-socket=" $SOCK " \
81114 2> data/electrs/regtest-debug.log &
82115ELECTRS_PID=$!
83- tail_log data/electrs/regtest-debug.log | grep -m1 " serving Electrum RPC"
116+ wait_for_log data/electrs/regtest-debug.log " serving Electrum RPC " " electrs Electrum RPC startup "
84117
85118# Confirm the IPC backend actually engaged. The Daemon::connect path logs
86119# nothing distinctive yet; instead probe the debug log for any IPC error or
@@ -89,11 +122,11 @@ if ! grep -q "ipc" data/electrs/regtest-debug.log; then
89122 : # no explicit log line yet; we rely on cargo tests + functional behaviour
90123fi
91124
92- curl localhost:24224 -o metrics.txt
125+ wait_for_http http:// localhost:24224 metrics.txt
93126
94127$ELECTRUM daemon --server localhost:60401:t -1 -vDEBUG 2> data/electrum/regtest-debug.log &
95128ELECTRUM_PID=$!
96- tail_log data/electrum/regtest-debug.log | grep -m1 " connection established"
129+ wait_for_log data/electrum/regtest-debug.log " connection established" " Electrum daemon connection "
97130$EL getinfo | jq .
98131
99132echo " Loading Electrum wallet..."
@@ -125,7 +158,7 @@ $BTC getblockcount > /dev/null
125158
126159echo " * wait for new block"
127160kill -USR1 $ELECTRS_PID # notify server to index new block
128- tail_log data/electrum/regtest-debug.log | grep -m1 " verified $TXID " > /dev/null
161+ wait_for_log data/electrum/regtest-debug.log " verified $TXID " " Electrum wallet verification of mined transaction "
129162
130163echo " * get_tx_status"
131164test " ` $EL get_tx_status $TXID | jq -c .` " == ' {"confirmations":1}'
@@ -140,7 +173,7 @@ echo "Electrum `$EL stop`" # disconnect wallet
140173wait $ELECTRUM_PID
141174
142175kill -INT $ELECTRS_PID # close server
143- tail_log data/electrs/regtest-debug.log | grep -m1 " electrs stopped "
176+ wait_for_log data/electrs/regtest-debug.log " electrs stopped " " electrs shutdown "
144177wait $ELECTRS_PID
145178
146179# When the multiprocess node has IPC clients still attached at shutdown, the
0 commit comments