summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/btc/analysis.sh65
-rw-r--r--test/btc/conflict.sh4
-rw-r--r--test/btc/hell.sh35
-rw-r--r--test/btc/reorg.sh26
-rw-r--r--test/btc/stress.sh2
-rw-r--r--test/common.sh4
6 files changed, 84 insertions, 52 deletions
diff --git a/test/btc/analysis.sh b/test/btc/analysis.sh
new file mode 100644
index 0000000..5677c2d
--- /dev/null
+++ b/test/btc/analysis.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+## Test btc_wire ability to learn and protect itself from blockchain behavior
+
+set -eu
+
+source "${BASH_SOURCE%/*}/../common.sh"
+SCHEMA=btc.sql
+
+echo "----- Setup -----"
+echo "Load config file"
+load_config
+echo "Start database"
+setup_db
+echo "Start bitcoin node"
+init_btc
+echo "Start second bitcoin node"
+init_btc2
+echo "Start btc-wire"
+btc_wire
+echo "Start gateway"
+gateway
+echo ""
+
+echo "----- Learn from reorg -----"
+
+echo "Loose second bitcoin node"
+btc2_deco
+
+echo -n "Making wire transfer to exchange:"
+btc-wire-utils -d $BTC_DIR transfer 0.042 > /dev/null
+next_btc # Trigger btc_wire
+check_balance 9.95799209 0.04200000
+echo " OK"
+
+echo -n "Perform fork and check btc-wire hard error:"
+gateway_up
+btc2_fork 5
+check_balance 9.95799209 0.00000000
+gateway_down
+echo " OK"
+
+echo -n "Recover orphaned transactions:"
+next_btc 5 # More block needed to confirm
+check_balance 9.95799209 0.04200000
+gateway_up
+echo " OK"
+
+echo "Loose second bitcoin node"
+btc2_deco
+
+echo -n "Making wire transfer to exchange:"
+btc-wire-utils -d $BTC_DIR transfer 0.064 > /dev/null
+next_btc 5 # More block needed to confirm
+check_balance 9.89398418 0.10600000
+echo " OK"
+
+echo -n "Perform fork and check btc-wire learned from previous attack:"
+gateway_up
+btc2_fork 5
+check_balance 9.89398418 0.10600000
+gateway_up
+echo " OK"
+
+echo "All tests passed!" \ No newline at end of file
diff --git a/test/btc/conflict.sh b/test/btc/conflict.sh
index 2fa6376..f4710cd 100644
--- a/test/btc/conflict.sh
+++ b/test/btc/conflict.sh
@@ -57,7 +57,7 @@ check_balance 9.96299209 0.03698010
echo " OK"
echo -n "Resend conflicting transaction:"
-sleep 5
+sleep 5 # Wait for reconnection
mine_btc
check_delta "outgoing?delta=-100" "seq 4 5" "0.00"
check_balance 9.96699209 0.03297811
@@ -106,7 +106,7 @@ check_balance 9.95994929 0.04001000
echo " OK"
echo -n "Resend conflicting transaction:"
-sleep 5
+sleep 5 # Wait for reconnection
mine_btc
check_balance 9.99993744 0.00002000
echo " OK"
diff --git a/test/btc/hell.sh b/test/btc/hell.sh
index d7c3d51..f8862d2 100644
--- a/test/btc/hell.sh
+++ b/test/btc/hell.sh
@@ -35,17 +35,11 @@ echo " OK"
echo -n "Perform fork and check btc-wire hard error:"
gateway_up
-btc2_fork
+btc2_fork 5
check_balance 9.99579209 0.00000000
gateway_down
echo " OK"
-echo -n "Check btc-wire hard error on restart:"
-btc_wire
-sleep 1
-gateway_down
-echo " OK"
-
echo -n "Generate conflict:"
restart_btc -minrelaytxfee=0.0001
btc-wire-utils -d $BTC_DIR abandon client
@@ -54,14 +48,10 @@ next_btc
check_balance 9.99457382 0.00540000
echo " OK"
-echo -n "Check btc-wire never heal on restart:"
-btc_wire
-sleep 1
+echo -n "Check btc-wire have not read the conflicting transaction:"
+sleep 5 # Wait for reconnection # Wait for reconnection
gateway_down
check_balance 9.99457382 0.00540000
-echo " OK"
-
-echo -n "Check btc-wire have not read the conflicting transaction:"
check_delta "incoming" ""
echo " OK"
@@ -93,23 +83,16 @@ btc2_deco
echo -n "Generate bounce:"
$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.042 > /dev/null
next_btc
-sleep 1
check_balance 9.99998674 0.00001000
echo " OK"
echo -n "Perform fork and check btc-wire hard error:"
gateway_up
-btc2_fork
+btc2_fork 5
check_balance 9.95799859 0.00000000
gateway_down
echo " OK"
-echo -n "Check btc-wire hard error on restart:"
-btc_wire
-sleep 1
-gateway_down
-echo " OK"
-
echo -n "Generate conflict:"
restart_btc -minrelaytxfee=0.0001
btc-wire-utils -d $BTC_DIR abandon client
@@ -118,16 +101,10 @@ next_btc
check_balance 9.94597382 0.05400000
echo " OK"
-sleep 5
-
-echo -n "Check btc-wire never heal on restart:"
-btc_wire
-sleep 1
+echo -n "Check btc-wire have not read the conflicting transaction:"
+sleep 5 # Wait for reconnection
gateway_down
check_balance 9.94597382 0.05400000
-echo " OK"
-
-echo -n "Check btc-wire have not read the conflicting transaction:"
check_delta "incoming" ""
echo " OK"
diff --git a/test/btc/reorg.sh b/test/btc/reorg.sh
index 3e4da8f..a0de12d 100644
--- a/test/btc/reorg.sh
+++ b/test/btc/reorg.sh
@@ -41,25 +41,14 @@ echo " OK"
echo -n "Perform fork and check btc-wire hard error:"
gateway_up
-btc2_fork
+btc2_fork 22
check_balance 9.99826299 0.00000000
gateway_down
echo " OK"
-echo -n "Check btc-wire hard error on restart:"
-btc_wire
-sleep 1
-gateway_down
-echo " OK"
-
echo -n "Recover orphaned transactions:"
-next_btc
+next_btc 6 # More block needed to confirm
check_balance 9.99826299 0.00165000
-echo " OK"
-
-echo -n "Check btc-wire heal on restart:"
-btc_wire
-sleep 1
gateway_up
echo " OK"
@@ -83,19 +72,20 @@ echo " OK"
echo -n "Perform fork and check btc-wire still up:"
gateway_up
-btc2_fork
+btc2_fork 22
check_balance 9.99826299 0.00146311
gateway_up
echo " OK"
echo -n "Recover orphaned transactions:"
-next_btc
+next_btc 6 # More block needed to confirm
check_balance 9.99842799 0.00146311
echo " OK"
echo "----- Handle reorg bounce -----"
clear_wallet
+check_balance "*" 0.00000000
echo "Loose second bitcoin node"
btc2_deco
@@ -105,20 +95,20 @@ for n in `$SEQ`; do
$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null
mine_btc
done
-next_btc
+next_btc 6 # More block needed to confirm
sleep 1
check_balance "*" 0.00011000
echo " OK"
echo -n "Perform fork and check btc-wire hard error:"
gateway_up
-btc2_fork
+btc2_fork 22
check_balance "*" 0.00000000
gateway_down
echo " OK"
echo -n "Recover orphaned transactions:"
-next_btc
+next_btc 6 # More block needed to confirm
check_balance "*" 0.00011000
echo " OK"
diff --git a/test/btc/stress.sh b/test/btc/stress.sh
index 48eade0..ff31563 100644
--- a/test/btc/stress.sh
+++ b/test/btc/stress.sh
@@ -99,7 +99,7 @@ done
next_btc
sleep 7
mine_btc
-sleep 5
+sleep 5 # Wait for reconnection
echo " OK"
echo -n "Check balance:"
diff --git a/test/common.sh b/test/common.sh
index 800d61e..a28165e 100644
--- a/test/common.sh
+++ b/test/common.sh
@@ -122,7 +122,7 @@ function btc2_deco() {
# Create a fork on the second node and reconnect the two node
function btc2_fork() {
- $BTC_CLI2 generatetoaddress ${1:-50} $RESERVE > /dev/null
+ $BTC_CLI2 generatetoaddress $1 $RESERVE > /dev/null
$BTC_CLI addnode 127.0.0.1:8346 onetry
sleep 1
}
@@ -160,7 +160,7 @@ function mine_btc() {
# Mine previous transactions
function next_btc() {
# Mine enough block to confirm previous transactions
- mine_btc $CONFIRMATION
+ mine_btc ${1:-$CONFIRMATION}
# Wait for btc_wire to catch up
sleep 0.2
# Mine one more block to trigger btc_wire