depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit d0a58b074225b5c277253b3aae4bcd52fa7714c3
parent d799aac4e997154557b0c28eec1ba7d87d71c4eb
Author: Antoine A <>
Date:   Wed, 15 Dec 2021 11:55:22 +0100

Improve test documentation and add btc_wire stress test

Diffstat:
Mbtc-wire/src/main.rs | 2+-
Mmakefile | 5+++--
Mscript/setup.sh | 16+++++++++++-----
Ascript/test_btc_stress.sh | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscript/test_btc_wire.sh | 6++----
Mscript/test_gateway.sh | 2++
Mscript/test_recover_db.sh | 13+++++--------
7 files changed, 94 insertions(+), 20 deletions(-)

diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs @@ -437,7 +437,7 @@ impl Config { port: conf.get("PORT").unwrap().parse().unwrap(), payto: Url::parse(&conf.get("PAYTO").unwrap()).unwrap(), address: conf.get("ADDRESS").unwrap().to_string(), - confirmation: 5 //conf.get("CONFIRMATION").unwrap().parse().unwrap(), + confirmation: conf.get("CONFIRMATION").unwrap().parse().unwrap(), } } } diff --git a/makefile b/makefile @@ -5,4 +5,5 @@ install: test: script/test_gateway.sh script/test_btc_wire.sh - script/test_recover_db.sh -\ No newline at end of file + script/test_recover_db.sh + script/test_btc_stress.sh +\ No newline at end of file diff --git a/script/setup.sh b/script/setup.sh @@ -40,19 +40,26 @@ function setup_btc() { CLIENT=`$BTC_CLI -rpcwallet=client getnewaddress` WIRE=`$BTC_CLI -rpcwallet=wire getnewaddress` $BTC_CLI generatetoaddress 101 $RESERVE > /dev/null - $BTC_CLI -rpcwallet=reserve sendtoaddress $CLIENT 1 > /dev/null + $BTC_CLI -rpcwallet=reserve sendtoaddress $CLIENT 10 > /dev/null $BTC_CLI -rpcwallet=reserve sendtoaddress $WIRE 1 > /dev/null $BTC_CLI generatetoaddress 1 $RESERVE > /dev/null + mine_btc + check_balance 10.00000000 1.00000000 +} + +# Mine blocks +function mine_btc() { + $BTC_CLI generatetoaddress "${1:-1}" $RESERVE > /dev/null } # Mine previous transactions function next_btc() { # Mine enough block to confirm previous transactions - $BTC_CLI generatetoaddress $CONFIRMATION $RESERVE > /dev/null + mine_btc $CONFIRMATION # Wait for btc_wire to catch up sleep 0.3 # Mine one more block to trigger btc_wire - $BTC_CLI generatetoaddress 1 $RESERVE > /dev/null + mine_btc # Wait for btc_wire to catch up sleep 0.5 } @@ -74,10 +81,9 @@ function btc_wire() { } # Start multiple btc_wire in parralel in fail mode -function stress_btc_wire() { +function stressed_btc_wire() { cargo build --bin btc-wire &> /dev/null target/debug/btc-wire $BTC_DIR &> btc_wire.log & - # Can be used to test db transactions serialization target/debug/btc-wire $BTC_DIR &>> btc_wire.log & target/debug/btc-wire $BTC_DIR &>> btc_wire.log & } diff --git a/script/test_btc_stress.sh b/script/test_btc_stress.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -eu + +# Cleanup to run whenever we exit +function cleanup() { + for n in `jobs -p`; do + kill $n 2> /dev/null || true + done + rm -rf $BTC_DIR 2> /dev/null + wait +} + +# Install cleanup handler (except for kill -9) +trap cleanup EXIT + +source "${BASH_SOURCE%/*}/setup.sh" + +echo "---- Setup -----" +echo "Load config file" +load_config +echo "Reset database" +reset_db +echo "Start bitcoin node" +init_btc +echo "Init bitcoin regtest" +setup_btc +echo "Start btc-wire stressed" +stressed_btc_wire +echo "Start gateway" +gateway +echo "" + +echo "----- Generate many transactions -----" + +echo -n "Making wire transfer to exchange:" +for n in `seq 10 99`; do + btc-wire-cli -d $BTC_DIR transfer 0.0000$n + mine_btc # Mine transactions +done +next_btc # Trigger btc_wire +next_btc # Trigger watcher twice, never sure +check_balance 9.99438310 1.00490500 +echo " OK" + +echo -n "Requesting exchange incoming transaction list:" +ALL=`curl -s ${BANK_ENDPOINT}history/incoming?delta=-100` +test `echo $ALL | grep -o BTC | wc -l` -eq 90 || exit 1; +for n in `seq 10 99`; do + echo $ALL | grep BTC:0.0000$n > /dev/null || exit 1; +done +echo " OK" + +echo "----- Recover DB -----" + +echo "Reset database" +reset_db # Clear database tables +next_btc # Trigger watcher +sleep 2 + +echo -n "Requesting exchange incoming transaction list:" +ALL=`curl -s ${BANK_ENDPOINT}history/incoming?delta=-100` +test `echo $ALL | grep -o BTC | wc -l` -eq 90 || exit 1; +for n in `seq 10 99`; do + echo $ALL | grep BTC:0.0000$n > /dev/null || exit 1; +done +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/script/test_btc_wire.sh b/script/test_btc_wire.sh @@ -26,8 +26,6 @@ echo "Start bitcoin node" init_btc echo "Init bitcoin regtest" setup_btc -next_btc -check_balance 1.00000000 1.00000000 echo "Start btc-wire" btc_wire echo "Start gateway" @@ -39,7 +37,7 @@ echo "---- Gateway API -----" echo -n "Making wire transfer to exchange:" btc-wire-cli -d $BTC_DIR transfer 0.00004 next_btc -check_balance 0.99995209 1.00004000 +check_balance 9.99995209 1.00004000 echo " OK" echo -n "Requesting exchange incoming transaction list:" @@ -52,7 +50,7 @@ taler-exchange-wire-gateway-client \ -C payto://bitcoin/$CLIENT \ -a BTC:0.00002 > /dev/null next_btc -check_balance 0.99997209 1.00001801 +check_balance 9.99997209 1.00001801 echo " OK" echo -n "Requesting exchange's outgoing transaction list:" diff --git a/script/test_gateway.sh b/script/test_gateway.sh @@ -93,6 +93,8 @@ echo "" echo "----- History delta -----" +# Check history endpoint request return a specific amount of transactions of specific amounts +# usage: check_delta endpoint nb_txs amount_sequence function check_delta() { ALL=`curl -s ${BANK_ENDPOINT}history/$1` test `echo $ALL | grep -o BTC | wc -l` -eq $2 || return 1; diff --git a/script/test_recover_db.sh b/script/test_recover_db.sh @@ -25,8 +25,6 @@ echo "Start bitcoin node" init_btc echo "Init bitcoin regtest" setup_btc -next_btc -check_balance 1.00000000 1.00000000 echo "Start btc-wire" btc_wire echo "Start gateway" @@ -37,7 +35,7 @@ echo "---- With DB -----" echo "Making wire transfer to exchange:" btc-wire-cli -d $BTC_DIR transfer 0.000042 next_btc -check_balance 0.99995009 1.00004200 +check_balance 9.99995009 1.00004200 echo -n "Requesting exchange incoming transaction list:" taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i | grep BTC:0.000042 > /dev/null && echo " OK" || echo " Failed" @@ -48,7 +46,7 @@ sudo service postgresql stop > /dev/null echo "Making wire transfer to exchange:" btc-wire-cli -d $BTC_DIR transfer 0.00004 next_btc -check_balance 0.99990218 1.00008200 +check_balance 9.99990218 1.00008200 echo -n "Requesting exchange incoming transaction list:" taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i 2>&1 | grep -q "504" && echo " OK" || echo " Failed" @@ -56,7 +54,7 @@ echo "---- Reconnect DB -----" echo "Start database" sudo service postgresql start > /dev/null -sleep 5 # Wait for connection to be avaible +sleep 6 # Wait for connection to be avaible echo -n "Requesting exchange incoming transaction list:" taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i | grep BTC:0.00004 > /dev/null && echo " OK" || echo " Failed" echo -n "Making wire transfer from exchange:" @@ -65,7 +63,7 @@ taler-exchange-wire-gateway-client \ -C payto://bitcoin/$CLIENT \ -a BTC:0.00002 > /dev/null next_btc -check_balance 0.99992218 1.00006001 +check_balance 9.99992218 1.00006001 echo " OK" echo -n "Requesting exchange's outgoing transaction list:" @@ -77,7 +75,6 @@ echo "---- Recover DB -----" echo "Reset database" reset_db # Clear database tables next_btc # Trigger watcher - sleep 2 echo -n "Checking recover incoming transactions:" @@ -95,6 +92,6 @@ done echo "" # Balance should not have changed -check_balance 0.99992218 1.00006001 +check_balance 9.99992218 1.00006001 echo "All tests passed" \ No newline at end of file