diff options
Diffstat (limited to 'test/btc')
-rw-r--r-- | test/btc/analysis.sh | 65 | ||||
-rw-r--r-- | test/btc/conflict.sh | 4 | ||||
-rw-r--r-- | test/btc/hell.sh | 35 | ||||
-rw-r--r-- | test/btc/reorg.sh | 26 | ||||
-rw-r--r-- | test/btc/stress.sh | 2 |
5 files changed, 82 insertions, 50 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:" |