commit d3ae4c7a52fc10d5e010ef61359a215f252a0130 parent d80f18e661ebe7904cfbdd85517441f82b0b4961 Author: Antoine A <> Date: Wed, 12 Jan 2022 11:14:44 +0100 Move test scripts to a new test directory Diffstat:
| D | script/generate_in_tx.sh | | | 7 | ------- |
| D | script/reset_database.sh | | | 2 | -- |
| D | script/test_btc_conflict.sh | | | 115 | ------------------------------------------------------------------------------- |
| D | script/test_btc_fail.sh | | | 82 | ------------------------------------------------------------------------------- |
| D | script/test_btc_hell.sh | | | 145 | ------------------------------------------------------------------------------- |
| D | script/test_btc_lifetime.sh | | | 54 | ------------------------------------------------------ |
| D | script/test_btc_reconnect.sh | | | 95 | ------------------------------------------------------------------------------- |
| D | script/test_btc_reorg.sh | | | 135 | ------------------------------------------------------------------------------- |
| D | script/test_btc_stress.sh | | | 130 | ------------------------------------------------------------------------------- |
| D | script/test_btc_wire.sh | | | 73 | ------------------------------------------------------------------------- |
| D | script/test_gateway.sh | | | 134 | ------------------------------------------------------------------------------- |
| A | test/btc/conflict.sh | | | 115 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/fail.sh | | | 82 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/hell.sh | | | 145 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/lifetime.sh | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/reconnect.sh | | | 95 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/reorg.sh | | | 135 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/stress.sh | | | 130 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | test/btc/wire.sh | | | 73 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| R | script/setup.sh -> test/common.sh | | | 0 | |
| R | script/conf/bitcoin.conf -> test/conf/bitcoin.conf | | | 0 | |
| R | script/conf/bitcoin2.conf -> test/conf/bitcoin2.conf | | | 0 | |
| R | script/conf/taler_lifetime.conf -> test/conf/taler_lifetime.conf | | | 0 | |
| R | script/conf/taler_test.conf -> test/conf/taler_test.conf | | | 0 | |
| A | test/gateway/api.sh | | | 134 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
25 files changed, 963 insertions(+), 972 deletions(-)
diff --git a/script/generate_in_tx.sh b/script/generate_in_tx.sh @@ -1,6 +0,0 @@ -for n in `shuf -i 000-999 -n $1`; do - btc-wire-cli transfer 0.0000$n - echo "BTC0.0000$n" -done -btc-wire-cli nblock -echo "$1 incoming transaction generated" -\ No newline at end of file diff --git a/script/reset_database.sh b/script/reset_database.sh @@ -1 +0,0 @@ -sudo -u postgres psql < wire-gateway/db/schema.sql > /dev/null -\ No newline at end of file diff --git a/script/test_btc_conflict.sh b/script/test_btc_conflict.sh @@ -1,114 +0,0 @@ -#!/bin/bash - -## Test btc_wire ability to handle conflicting outgoing transactions - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 "----- Conflict send -----" - -echo -n "Making wire transfer to exchange:" -btc-wire-cli -d $BTC_DIR transfer 0.042 > /dev/null -next_btc -check_balance 9.95799209 0.04200000 -echo " OK" - -echo -n "Making wire transfer from exchange:" -taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.004 > /dev/null -sleep 1 -check_balance 9.95799209 0.03799801 -echo " OK" - -echo -n "Abandon pending transaction:" -restart_btc -minrelaytxfee=0.0001 -btc-wire-cli -d $BTC_DIR abandon -check_balance 9.95799209 0.04200000 -echo " OK" - -echo -n "Generate conflict:" -taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.005 > /dev/null -sleep 1 -restart_btc -mine_btc -check_balance 9.96299209 0.03698010 -echo " OK" - -echo -n "Resend conflicting transaction:" -sleep 5 -mine_btc -check_delta "outgoing?delta=-100" "seq 4 5" "0.00" -check_balance 9.96699209 0.03297811 -echo " OK" - -echo "----- Reset -----" -echo "Cleanup" -cleanup -source "${BASH_SOURCE%/*}/setup.sh" -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 "----- Conflict bounce -----" - -echo -n "Bounce:" -$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.04 > /dev/null -mine_btc $CONFIRMATION -sleep 1 -check_balance 9.95999859 0.00001000 -echo " OK" - -echo -n "Abandon pending transaction:" -restart_btc -minrelaytxfee=0.0001 -btc-wire-cli -d $BTC_DIR abandon -check_balance 9.95999859 0.04000000 -echo " OK" - -echo -n "Generate conflict:" -$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.05 > /dev/null -mine_btc $CONFIRMATION -sleep 1 -restart_btc -mine_btc -check_balance 9.95994929 0.04001000 -echo " OK" - -echo -n "Resend conflicting transaction:" -sleep 5 -mine_btc -check_balance 9.99993744 0.00002000 -echo " OK" - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_btc_fail.sh b/script/test_btc_fail.sh @@ -1,81 +0,0 @@ -#!/bin/bash - -## Test btc_wire ability to recover from errors in correctness critical paths - -set -eu - -source "${BASH_SOURCE%/*}/setup.sh" -SCHEMA=btc.sql - -echo "----- Setup fail -----" -echo "Load config file" -load_config -echo "Start database" -setup_db -echo "Start bitcoin node" -init_btc -echo "Start failing btc-wire" -fail_btc_wire -echo "Start gateway" -gateway -echo "" - -SEQ="seq 10 40" - -echo "----- Handle incoming -----" - -echo -n "Making wire transfer to exchange:" -for n in `$SEQ`; do - btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null - mine_btc # Mine transactions -done -next_btc # Trigger btc_wire -echo " OK" - -echo -n "Requesting exchange incoming transaction list:" -check_delta "incoming?delta=-100" "$SEQ" "0.000" -echo " OK" - -echo -n "Check balance:" -check_balance 9.99200479 0.00775000 -echo " OK" - -echo "----- Handle outgoing -----" - -echo -n "Making wire transfer from exchange:" -for n in `$SEQ`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.0000$n > /dev/null -done -sleep 20 -mine_btc # Mine transactions -echo " OK" - -echo -n "Requesting exchange outgoing transaction list:" -check_delta "outgoing?delta=-100" "$SEQ" -echo " OK" - -echo -n "Check balance:" -check_balance 9.99277979 0.00691331 -echo " OK" - -echo "----- Handle bounce -----" - -clear_wallet - -echo -n "Making incomplete wire transfer to exchange:" -for n in `$SEQ`; do - $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null - mine_btc -done -next_btc -sleep 20 -echo " OK" - -echo -n "Check balance:" -check_balance "*" 0.00031000 -echo " OK" - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_btc_hell.sh b/script/test_btc_hell.sh @@ -1,144 +0,0 @@ -#!/bin/bash - -## Test btc_wire correctness when a blockchain reorganisation occurs leading to past incoming transaction conflict - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 "" - -# Check btc-wire is running -function up() { - check_up $WIRE_PID btc_wire -} -# Check btc-wire is not running -function down() { - check_down $WIRE_PID btc_wire -} - -echo "----- Handle reorg conflicting incoming receive -----" - -echo "Loose second bitcoin node" -btc2_deco - -echo -n "Gen incoming transactions:" -btc-wire-cli -d $BTC_DIR transfer 0.0042 > /dev/null -next_btc # Trigger btc_wire -check_balance 9.99579209 0.00420000 -echo " OK" - -echo -n "Perform fork and check btc-wire hard error:" -up -btc2_fork -check_balance 9.99579209 0.00000000 -down -echo " OK" - -echo -n "Check btc-wire hard error on restart:" -btc_wire -sleep 1 -down -echo " OK" - -echo -n "Generate conflict:" -restart_btc -minrelaytxfee=0.0001 -btc-wire-cli -d $BTC_DIR abandon client -btc-wire-cli -d $BTC_DIR transfer 0.0054 > /dev/null -next_btc -check_balance 9.99457382 0.00540000 -echo " OK" - -echo -n "Check btc-wire never heal on restart:" -btc_wire -sleep 1 -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" - -# Recover by paying for the customer ? - -echo "----- Reset -----" -echo "Cleanup" -cleanup -source "${BASH_SOURCE%/*}/setup.sh" -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 "----- Handle reorg conflicting incoming bounce -----" - -echo "Loose second bitcoin node" -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:" -up -btc2_fork -check_balance 9.95799859 0.00000000 -down -echo " OK" - -echo -n "Check btc-wire hard error on restart:" -btc_wire -sleep 1 -down -echo " OK" - -echo -n "Generate conflict:" -restart_btc -minrelaytxfee=0.0001 -btc-wire-cli -d $BTC_DIR abandon client -btc-wire-cli -d $BTC_DIR transfer 0.054 > /dev/null -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 -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" - - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_btc_lifetime.sh b/script/test_btc_lifetime.sh @@ -1,54 +0,0 @@ -#!/bin/bash - -## Check btc-wire and wire-gateway correctly stop when a lifetime limit is configured - -CONFIG=taler_lifetime.conf - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 btc-wire" -btc_wire -echo "Start gateway" -gateway -echo "" - -SEQ="seq 10 20" - -echo "---- Check lifetime -----" - -echo -n "Check up:" -check_up $WIRE_PID btc-wire -check_up $GATEWAY_PID wire-gateway -echo " OK" - -echo -n "Do some work:" -for n in `$SEQ`; do - btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null - mine_btc # Mine transactions -done -next_btc # Trigger btc_wire -check_balance 9.99826299 0.00165000 -for n in `$SEQ`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.0000$n &> /dev/null || break; -done -echo " OK" - -echo -n "Check down:" -check_down $WIRE_PID btc-wire -check_down $GATEWAY_PID wire-gateway -echo " OK" - -echo "All tests passed" diff --git a/script/test_btc_reconnect.sh b/script/test_btc_reconnect.sh @@ -1,94 +0,0 @@ -#!/bin/bash - -## Check the capacity of wire_gateway and btc_wire to recover from database loss - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 btc-wire" -btc_wire -echo "Start gateway" -gateway -echo "" - -echo "----- With DB -----" -echo "Making wire transfer to exchange:" -btc-wire-cli -d $BTC_DIR transfer 0.000042 > /dev/null -next_btc -check_balance 9.99995009 0.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" - -echo "----- Without DB -----" - -echo "Stop database" -pg_ctl stop -D $DB_DIR > /dev/null -echo "Making incomplete wire transfer to exchange" -$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.00042 &> /dev/null -echo -n "Making wire transfer to exchange:" -btc-wire-cli -d $BTC_DIR transfer 0.00004 > /dev/null -next_btc -check_balance 9.99948077 0.00050200 -echo " OK" -echo "Stop bitcoin node" -stop_btc -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" - -echo "----- Reconnect DB -----" - -echo "Start database" -pg_ctl start -D $DB_DIR > /dev/null -echo "Start bitcoin node" -resume_btc -sleep 6 # Wait for connection to be available -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:" -taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.00002 > /dev/null -sleep 1 -mine_btc -check_balance 9.99990892 0.00007001 -echo " OK" - -echo -n "Requesting exchange's outgoing transaction list:" -taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o | grep BTC:0.00002 > /dev/null -echo " OK" - -echo "----- Recover DB -----" - -echo "Reset database" -reset_db # Clear database tables -mine_btc # Trigger worker -sleep 2 - -echo -n "Checking recover incoming transactions:" -ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i`; -for amount in 0.000042 0.00004; do - echo $ALL | grep BTC:$amount > /dev/null && echo -n " OK" || echo -n " Failed" -done -echo "" - -echo -n "Requesting exchange's outgoing transaction list:" -ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o`; -for amount in 0.00002; do - echo $ALL | grep BTC:$amount > /dev/null && echo -n " OK" || echo -n " Failed" -done -echo "" - -# Balance should not have changed -check_balance 9.99990892 0.00007001 - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_btc_reorg.sh b/script/test_btc_reorg.sh @@ -1,134 +0,0 @@ -#!/bin/bash - -## Test btc_wire correctness when a blockchain reorganisation occurs - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 "" - -# Check btc-wire is running -function up() { - check_up $WIRE_PID btc_wire -} -# Check btc-wire is not running -function down() { - check_down $WIRE_PID btc_wire -} - -SEQ="seq 10 20" - -echo "----- Handle reorg incoming transactions -----" - -echo "Loose second bitcoin node" -btc2_deco - -echo -n "Gen incoming transactions:" -for n in `$SEQ`; do - btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null - mine_btc # Mine transactions -done -next_btc # Trigger btc_wire -check_delta "incoming?delta=-100" "$SEQ" "0.000" -check_balance 9.99826299 0.00165000 -echo " OK" - -echo -n "Perform fork and check btc-wire hard error:" -up -btc2_fork -check_balance 9.99826299 0.00000000 -down -echo " OK" - -echo -n "Check btc-wire hard error on restart:" -btc_wire -sleep 1 -down -echo " OK" - -echo -n "Recover orphaned transactions:" -next_btc -check_balance 9.99826299 0.00165000 -echo " OK" - -echo -n "Check btc-wire heal on restart:" -btc_wire -sleep 1 -up -echo " OK" - -echo "----- Handle reorg outgoing transactions -----" - -echo "Loose second bitcoin node" -btc2_deco - -echo -n "Gen outgoing transactions:" -for n in `$SEQ`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.0000$n > /dev/null -done -sleep 1 -mine_btc # Mine transactions -check_delta "outgoing?delta=-100" "$SEQ" -check_balance 9.99842799 0.00146311 -echo " OK" - -echo -n "Perform fork and check btc-wire still up:" -up -btc2_fork -check_balance 9.99826299 0.00146311 -up -echo " OK" - -echo -n "Recover orphaned transactions:" -next_btc -check_balance 9.99842799 0.00146311 -echo " OK" - -echo "----- Handle reorg bounce -----" - -clear_wallet - -echo "Loose second bitcoin node" -btc2_deco - -echo -n "Generate bounce:" -for n in `$SEQ`; do - $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null - mine_btc -done -next_btc -sleep 1 -check_balance "*" 0.00011000 -echo " OK" - -echo -n "Perform fork and check btc-wire hard error:" -up -btc2_fork -check_balance "*" 0.00000000 -down -echo " OK" - -echo -n "Recover orphaned transactions:" -next_btc -check_balance "*" 0.00011000 -echo " OK" - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_btc_stress.sh b/script/test_btc_stress.sh @@ -1,129 +0,0 @@ -#!/bin/bash - -## Test btc_wire behavior when ran and stressed concurrently - -set -eu - -source "${BASH_SOURCE%/*}/setup.sh" -SCHEMA=btc.sql - -echo "----- Setup stressed -----" -echo "Load config file" -load_config -echo "Start database" -setup_db -echo "Start bitcoin node" -init_btc -echo "Start btc-wire stressed" -stressed_btc_wire -echo "Start gateway" -gateway -echo "" - -SEQ="seq 10 99" - -echo "----- Handle incoming -----" - -echo -n "Making wire transfer to exchange:" -for n in `$SEQ`; do - btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null - mine_btc # Mine transactions -done -sleep 3 # Give time for btc_wire worker to process -next_btc # Confirm all transactions -sleep 3 # Give time for btc_wire worker to process -echo " OK" - -echo -n "Requesting exchange incoming transaction list:" -check_delta "incoming?delta=-100" "$SEQ" "0.000" -echo " OK" - -echo -n "Check balance:" -check_balance 9.95023810 0.04905000 -echo " OK" - -echo "----- Handle outgoing -----" - -echo -n "Making wire transfer from exchange:" -for n in `$SEQ`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.0000$n > /dev/null -done -sleep 10 # Give time for btc_wire worker to process -next_btc # Mine transactions -echo " OK" - -echo -n "Requesting exchange outgoing transaction list:" -check_delta "outgoing?delta=-100" "$SEQ" -echo " OK" - -echo -n "Check balance:" -check_balance 9.95514310 -echo " OK" - -next_btc # Mine transactions - -echo "----- Recover DB -----" - -echo "Reset database" -reset_db # Clear database tables -mine_btc # Trigger worker -sleep 10 - -echo -n "Requesting exchange incoming transaction list:" -check_delta "incoming?delta=-100" "$SEQ" "0.000" -echo " OK" - -echo -n "Requesting exchange outgoing transaction list:" -check_delta "outgoing?delta=-100" "$SEQ" -echo " OK" - -echo -n "Check balance:" -# Balance should not have changed -check_balance 9.95514310 -echo " OK" - -echo "----- Handle bounce -----" - -echo -n "Clear wire wallet:" -$BTC_CLI -rpcwallet=wire sendtoaddress $CLIENT `$BTC_CLI -rpcwallet=wire getbalance` "" "" true > /dev/null -echo " OK" - -echo -n "Making incomplete wire transfer to exchange:" -for n in `$SEQ`; do - $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null - mine_btc -done -next_btc -sleep 10 -mine_btc -sleep 10 -echo " OK" - -echo -n "Check balance:" -check_balance "*" 0.00090000 -echo " OK" - -echo "----- Recover DB -----" - -echo "Reset database" -reset_db # Clear database tables -mine_btc # Trigger worker -sleep 20 - -echo -n "Requesting exchange incoming transaction list:" -check_delta "incoming?delta=-100" "$SEQ" "0.000" -echo " OK" - -echo -n "Requesting exchange outgoing transaction list:" -check_delta "outgoing?delta=-100" "$SEQ" -echo " OK" - -echo -n "Check balance:" -# Balance should not have changed -check_balance "*" 0.00090000 -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 @@ -1,72 +0,0 @@ -#!/bin/bash - -## Test btc_wire correctly receive and sens transactions on the blockchain - -set -eu - -source "${BASH_SOURCE%/*}/setup.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 btc-wire" -btc_wire -echo "Start gateway" -gateway -echo "" - -SEQ="seq 10 20" - -echo "----- Receive -----" - -echo -n "Making wire transfer to exchange:" -for n in `$SEQ`; do - btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null - mine_btc # Mine transactions -done -next_btc # Trigger btc_wire -check_balance 9.99826299 0.00165000 -echo " OK" - -echo -n "Requesting exchange incoming transaction list:" -check_delta "incoming?delta=-100" "$SEQ" "0.000" -echo " OK" - -echo "----- Send -----" - -echo -n "Making wire transfer from exchange:" -for n in `$SEQ`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$CLIENT \ - -a BTC:0.0000$n > /dev/null -done -sleep 1 -mine_btc # Mine transactions -check_balance 9.99842799 0.00146311 -echo " OK" - -echo -n "Requesting exchange's outgoing transaction list:" -check_delta "outgoing?delta=-100" "$SEQ" -echo " OK" - -echo "----- Bounce -----" - -clear_wallet - -echo -n "Bounce:" -for n in `$SEQ`; do - $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null - mine_btc -done -next_btc -sleep 1 -check_balance "*" 0.00011000 -echo " OK" - -echo "All tests passed" -\ No newline at end of file diff --git a/script/test_gateway.sh b/script/test_gateway.sh @@ -1,134 +0,0 @@ -#!/bin/bash - -## Test wire_gateway conformance to documentation and its security - -set -eu - -# Create temp file -TEMP_FILE=$(mktemp) - -# Cleanup to run whenever we exit -function cleanup() { - rm -f $TEMP_FILE - wait -} - -# Install cleanup handler (except for kill -9) -trap cleanup EXIT - -source "${BASH_SOURCE%/*}/setup.sh" -ADDRESS=mpTJZxWPerz1Gife6mQSdHT8mMuJK6FP85 -SCHEMA=btc.sql - -echo "----- Setup -----" -echo "Load config file" -load_config -echo "Start database" -setup_db -echo "Start gateway" -gateway -echo "" - -echo "----- Gateway API -----" - -echo -n "Making wire transfer to exchange:" -for n in `seq 1 9`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -D payto://bitcoin/$ADDRESS \ - -a BTC:0.0000$n > /dev/null -done -echo " OK" - -echo -n "Requesting exchange incoming transaction list:" -ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i` -for n in `seq 1 9`; do - echo $ALL | grep BTC:0.0000$n > /dev/null -done -echo " OK" - -echo -n "Making wire transfer from exchange:" -for n in `seq 1 9`; do - taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -C payto://bitcoin/$ADDRESS \ - -a BTC:0.0000$n > /dev/null -done - -echo " OK" - -echo -n "Requesting exchange's outgoing transaction list:" -ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o` -for n in `seq 1 9`; do - echo $ALL | grep BTC:0.0000$n > /dev/null -done -echo " OK" - -echo "----- Endpoint & Method -----" - -echo -n "Unknown endpoint:" -test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}test` -eq 404 && echo " OK" || echo " Failed" - -echo -n "Method not allowed:" -test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}transfer` -eq 405 && echo " OK" || echo " Failed" - -echo "----- Request format -----" - -echo -n "Bad payto url:" -for bad_payto in http://bitcoin/$ADDRESS payto://btc/$ADDRESS payto://bitcoin/$ADDRESS?id=admin payto://bitcoin/$ADDRESS#admin; do - taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C $bad_payto -a BTC:0.00042 2>&1 | grep -q "(400/24)" && echo -n " OK" || echo " Failed" -done -echo "" - -echo -n "Bad bitcoin address:" -taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/42$ADDRESS -a BTC:0.00042 2>&1 | grep -q "(400/24)" && echo " OK" || echo " Failed" - -echo -n "Bad transaction amount:" -taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/$ADDRESS -a ATC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed" - -echo -n "Bad history delta:" -for bad_delta in incoming outgoing incoming?delta=0 outgoing?delta=0; do - test `curl -w %{http_code} -s -o /dev/null "${BANK_ENDPOINT}history/$bad_delta"` -eq 400 && echo -n " OK" || echo -n " Failed" -done -echo "" - -echo "----- History delta -----" - -for endpoint in incoming outgoing; do - echo -n "History $endpoint:" - check_delta ${endpoint}?delta=-9 "seq 1 9" && echo -n " OK" || echo -n " Failed" - check_delta ${endpoint}?delta=9 "seq 1 9" && echo -n " OK" || echo -n " Failed" - check_delta ${endpoint}?delta=-4 "seq 6 9" && echo -n " OK" || echo -n " Failed" - check_delta ${endpoint}?delta=4 "seq 1 4" && echo -n " OK" || echo -n " Failed" - check_delta "${endpoint}?delta=-3&start=5" "seq 2 4" && echo -n " OK" || echo -n " Failed" - check_delta "${endpoint}?delta=3&start=4" "seq 5 7" && echo -n " OK" || echo -n " Failed" - echo "" -done - -echo "----- Transfer idempotence -----" -DATA="{\"request_uid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"amount\":\"BTC:0.000034\",\"exchange_base_url\":\"$BASE_URL\",\"wtid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"credit_account\":\"payto://bitcoin/$ADDRESS\"}" -echo -n "Same:" -test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 200 && echo -n " OK" || echo -n " Failed" -test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 200 && echo " OK" || echo " Failed" -echo -n "Collision:" -DATA="{\"request_uid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"amount\":\"BTC:0.000042\",\"exchange_base_url\":\"$BASE_URL\",\"wtid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"credit_account\":\"payto://bitcoin/$ADDRESS\"}" -test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 409 && echo " OK" || echo " Failed" - -echo "----- Security -----" - -# Generate big random file -printf 'HelloWorld%s' {1..1000} > $TEMP_FILE - -echo -n "Handle huge body:" -test `curl -w %{http_code} -X POST -s -o /dev/null -d @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" - -echo -n "Handle body length liar:" -test `curl -w %{http_code} -X POST -H"Content-Length:1024" -s -o /dev/null -d @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" - -# Generate compression bomb -printf 'HelloWorld%s' {1..1000} | pigz -z9 > $TEMP_FILE - -echo -n "Handle compression bomb:" -test `curl -w %{http_code} -X POST -H"Content-Encoding:deflate" -s -o /dev/null --data-binary @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" - -echo "All tests passed" diff --git a/test/btc/conflict.sh b/test/btc/conflict.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +## Test btc_wire ability to handle conflicting outgoing transactions + +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 "----- Conflict send -----" + +echo -n "Making wire transfer to exchange:" +btc-wire-cli -d $BTC_DIR transfer 0.042 > /dev/null +next_btc +check_balance 9.95799209 0.04200000 +echo " OK" + +echo -n "Making wire transfer from exchange:" +taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.004 > /dev/null +sleep 1 +check_balance 9.95799209 0.03799801 +echo " OK" + +echo -n "Abandon pending transaction:" +restart_btc -minrelaytxfee=0.0001 +btc-wire-cli -d $BTC_DIR abandon +check_balance 9.95799209 0.04200000 +echo " OK" + +echo -n "Generate conflict:" +taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.005 > /dev/null +sleep 1 +restart_btc +mine_btc +check_balance 9.96299209 0.03698010 +echo " OK" + +echo -n "Resend conflicting transaction:" +sleep 5 +mine_btc +check_delta "outgoing?delta=-100" "seq 4 5" "0.00" +check_balance 9.96699209 0.03297811 +echo " OK" + +echo "----- Reset -----" +echo "Cleanup" +cleanup +source "${BASH_SOURCE%/*}/../common.sh" +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 "----- Conflict bounce -----" + +echo -n "Bounce:" +$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.04 > /dev/null +mine_btc $CONFIRMATION +sleep 1 +check_balance 9.95999859 0.00001000 +echo " OK" + +echo -n "Abandon pending transaction:" +restart_btc -minrelaytxfee=0.0001 +btc-wire-cli -d $BTC_DIR abandon +check_balance 9.95999859 0.04000000 +echo " OK" + +echo -n "Generate conflict:" +$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.05 > /dev/null +mine_btc $CONFIRMATION +sleep 1 +restart_btc +mine_btc +check_balance 9.95994929 0.04001000 +echo " OK" + +echo -n "Resend conflicting transaction:" +sleep 5 +mine_btc +check_balance 9.99993744 0.00002000 +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/fail.sh b/test/btc/fail.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +## Test btc_wire ability to recover from errors in correctness critical paths + +set -eu + +source "${BASH_SOURCE%/*}/../common.sh" +SCHEMA=btc.sql + +echo "----- Setup fail -----" +echo "Load config file" +load_config +echo "Start database" +setup_db +echo "Start bitcoin node" +init_btc +echo "Start failing btc-wire" +fail_btc_wire +echo "Start gateway" +gateway +echo "" + +SEQ="seq 10 40" + +echo "----- Handle incoming -----" + +echo -n "Making wire transfer to exchange:" +for n in `$SEQ`; do + btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null + mine_btc # Mine transactions +done +next_btc # Trigger btc_wire +echo " OK" + +echo -n "Requesting exchange incoming transaction list:" +check_delta "incoming?delta=-100" "$SEQ" "0.000" +echo " OK" + +echo -n "Check balance:" +check_balance 9.99200479 0.00775000 +echo " OK" + +echo "----- Handle outgoing -----" + +echo -n "Making wire transfer from exchange:" +for n in `$SEQ`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.0000$n > /dev/null +done +sleep 20 +mine_btc # Mine transactions +echo " OK" + +echo -n "Requesting exchange outgoing transaction list:" +check_delta "outgoing?delta=-100" "$SEQ" +echo " OK" + +echo -n "Check balance:" +check_balance 9.99277979 0.00691331 +echo " OK" + +echo "----- Handle bounce -----" + +clear_wallet + +echo -n "Making incomplete wire transfer to exchange:" +for n in `$SEQ`; do + $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null + mine_btc +done +next_btc +sleep 20 +echo " OK" + +echo -n "Check balance:" +check_balance "*" 0.00031000 +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/hell.sh b/test/btc/hell.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +## Test btc_wire correctness when a blockchain reorganisation occurs leading to past incoming transaction conflict + +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 "" + +# Check btc-wire is running +function up() { + check_up $WIRE_PID btc_wire +} +# Check btc-wire is not running +function down() { + check_down $WIRE_PID btc_wire +} + +echo "----- Handle reorg conflicting incoming receive -----" + +echo "Loose second bitcoin node" +btc2_deco + +echo -n "Gen incoming transactions:" +btc-wire-cli -d $BTC_DIR transfer 0.0042 > /dev/null +next_btc # Trigger btc_wire +check_balance 9.99579209 0.00420000 +echo " OK" + +echo -n "Perform fork and check btc-wire hard error:" +up +btc2_fork +check_balance 9.99579209 0.00000000 +down +echo " OK" + +echo -n "Check btc-wire hard error on restart:" +btc_wire +sleep 1 +down +echo " OK" + +echo -n "Generate conflict:" +restart_btc -minrelaytxfee=0.0001 +btc-wire-cli -d $BTC_DIR abandon client +btc-wire-cli -d $BTC_DIR transfer 0.0054 > /dev/null +next_btc +check_balance 9.99457382 0.00540000 +echo " OK" + +echo -n "Check btc-wire never heal on restart:" +btc_wire +sleep 1 +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" + +# Recover by paying for the customer ? + +echo "----- Reset -----" +echo "Cleanup" +cleanup +source "${BASH_SOURCE%/*}/../common.sh" +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 "----- Handle reorg conflicting incoming bounce -----" + +echo "Loose second bitcoin node" +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:" +up +btc2_fork +check_balance 9.95799859 0.00000000 +down +echo " OK" + +echo -n "Check btc-wire hard error on restart:" +btc_wire +sleep 1 +down +echo " OK" + +echo -n "Generate conflict:" +restart_btc -minrelaytxfee=0.0001 +btc-wire-cli -d $BTC_DIR abandon client +btc-wire-cli -d $BTC_DIR transfer 0.054 > /dev/null +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 +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" + + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/lifetime.sh b/test/btc/lifetime.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +## Check btc-wire and wire-gateway correctly stop when a lifetime limit is configured + +CONFIG=taler_lifetime.conf + +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 btc-wire" +btc_wire +echo "Start gateway" +gateway +echo "" + +SEQ="seq 10 20" + +echo "---- Check lifetime -----" + +echo -n "Check up:" +check_up $WIRE_PID btc-wire +check_up $GATEWAY_PID wire-gateway +echo " OK" + +echo -n "Do some work:" +for n in `$SEQ`; do + btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null + mine_btc # Mine transactions +done +next_btc # Trigger btc_wire +check_balance 9.99826299 0.00165000 +for n in `$SEQ`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.0000$n &> /dev/null || break; +done +echo " OK" + +echo -n "Check down:" +check_down $WIRE_PID btc-wire +check_down $GATEWAY_PID wire-gateway +echo " OK" + +echo "All tests passed" diff --git a/test/btc/reconnect.sh b/test/btc/reconnect.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +## Check the capacity of wire_gateway and btc_wire to recover from database loss + +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 btc-wire" +btc_wire +echo "Start gateway" +gateway +echo "" + +echo "----- With DB -----" +echo "Making wire transfer to exchange:" +btc-wire-cli -d $BTC_DIR transfer 0.000042 > /dev/null +next_btc +check_balance 9.99995009 0.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" + +echo "----- Without DB -----" + +echo "Stop database" +pg_ctl stop -D $DB_DIR > /dev/null +echo "Making incomplete wire transfer to exchange" +$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.00042 &> /dev/null +echo -n "Making wire transfer to exchange:" +btc-wire-cli -d $BTC_DIR transfer 0.00004 > /dev/null +next_btc +check_balance 9.99948077 0.00050200 +echo " OK" +echo "Stop bitcoin node" +stop_btc +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" + +echo "----- Reconnect DB -----" + +echo "Start database" +pg_ctl start -D $DB_DIR > /dev/null +echo "Start bitcoin node" +resume_btc +sleep 6 # Wait for connection to be available +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:" +taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.00002 > /dev/null +sleep 1 +mine_btc +check_balance 9.99990892 0.00007001 +echo " OK" + +echo -n "Requesting exchange's outgoing transaction list:" +taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o | grep BTC:0.00002 > /dev/null +echo " OK" + +echo "----- Recover DB -----" + +echo "Reset database" +reset_db # Clear database tables +mine_btc # Trigger worker +sleep 2 + +echo -n "Checking recover incoming transactions:" +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i`; +for amount in 0.000042 0.00004; do + echo $ALL | grep BTC:$amount > /dev/null && echo -n " OK" || echo -n " Failed" +done +echo "" + +echo -n "Requesting exchange's outgoing transaction list:" +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o`; +for amount in 0.00002; do + echo $ALL | grep BTC:$amount > /dev/null && echo -n " OK" || echo -n " Failed" +done +echo "" + +# Balance should not have changed +check_balance 9.99990892 0.00007001 + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/reorg.sh b/test/btc/reorg.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +## Test btc_wire correctness when a blockchain reorganisation occurs + +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 "" + +# Check btc-wire is running +function up() { + check_up $WIRE_PID btc_wire +} +# Check btc-wire is not running +function down() { + check_down $WIRE_PID btc_wire +} + +SEQ="seq 10 20" + +echo "----- Handle reorg incoming transactions -----" + +echo "Loose second bitcoin node" +btc2_deco + +echo -n "Gen incoming transactions:" +for n in `$SEQ`; do + btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null + mine_btc # Mine transactions +done +next_btc # Trigger btc_wire +check_delta "incoming?delta=-100" "$SEQ" "0.000" +check_balance 9.99826299 0.00165000 +echo " OK" + +echo -n "Perform fork and check btc-wire hard error:" +up +btc2_fork +check_balance 9.99826299 0.00000000 +down +echo " OK" + +echo -n "Check btc-wire hard error on restart:" +btc_wire +sleep 1 +down +echo " OK" + +echo -n "Recover orphaned transactions:" +next_btc +check_balance 9.99826299 0.00165000 +echo " OK" + +echo -n "Check btc-wire heal on restart:" +btc_wire +sleep 1 +up +echo " OK" + +echo "----- Handle reorg outgoing transactions -----" + +echo "Loose second bitcoin node" +btc2_deco + +echo -n "Gen outgoing transactions:" +for n in `$SEQ`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.0000$n > /dev/null +done +sleep 1 +mine_btc # Mine transactions +check_delta "outgoing?delta=-100" "$SEQ" +check_balance 9.99842799 0.00146311 +echo " OK" + +echo -n "Perform fork and check btc-wire still up:" +up +btc2_fork +check_balance 9.99826299 0.00146311 +up +echo " OK" + +echo -n "Recover orphaned transactions:" +next_btc +check_balance 9.99842799 0.00146311 +echo " OK" + +echo "----- Handle reorg bounce -----" + +clear_wallet + +echo "Loose second bitcoin node" +btc2_deco + +echo -n "Generate bounce:" +for n in `$SEQ`; do + $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null + mine_btc +done +next_btc +sleep 1 +check_balance "*" 0.00011000 +echo " OK" + +echo -n "Perform fork and check btc-wire hard error:" +up +btc2_fork +check_balance "*" 0.00000000 +down +echo " OK" + +echo -n "Recover orphaned transactions:" +next_btc +check_balance "*" 0.00011000 +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/stress.sh b/test/btc/stress.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +## Test btc_wire behavior when ran and stressed concurrently + +set -eu + +source "${BASH_SOURCE%/*}/../common.sh" +SCHEMA=btc.sql + +echo "----- Setup stressed -----" +echo "Load config file" +load_config +echo "Start database" +setup_db +echo "Start bitcoin node" +init_btc +echo "Start btc-wire stressed" +stressed_btc_wire +echo "Start gateway" +gateway +echo "" + +SEQ="seq 10 99" + +echo "----- Handle incoming -----" + +echo -n "Making wire transfer to exchange:" +for n in `$SEQ`; do + btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null + mine_btc # Mine transactions +done +sleep 3 # Give time for btc_wire worker to process +next_btc # Confirm all transactions +sleep 3 # Give time for btc_wire worker to process +echo " OK" + +echo -n "Requesting exchange incoming transaction list:" +check_delta "incoming?delta=-100" "$SEQ" "0.000" +echo " OK" + +echo -n "Check balance:" +check_balance 9.95023810 0.04905000 +echo " OK" + +echo "----- Handle outgoing -----" + +echo -n "Making wire transfer from exchange:" +for n in `$SEQ`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.0000$n > /dev/null +done +sleep 10 # Give time for btc_wire worker to process +next_btc # Mine transactions +echo " OK" + +echo -n "Requesting exchange outgoing transaction list:" +check_delta "outgoing?delta=-100" "$SEQ" +echo " OK" + +echo -n "Check balance:" +check_balance 9.95514310 +echo " OK" + +next_btc # Mine transactions + +echo "----- Recover DB -----" + +echo "Reset database" +reset_db # Clear database tables +mine_btc # Trigger worker +sleep 10 + +echo -n "Requesting exchange incoming transaction list:" +check_delta "incoming?delta=-100" "$SEQ" "0.000" +echo " OK" + +echo -n "Requesting exchange outgoing transaction list:" +check_delta "outgoing?delta=-100" "$SEQ" +echo " OK" + +echo -n "Check balance:" +# Balance should not have changed +check_balance 9.95514310 +echo " OK" + +echo "----- Handle bounce -----" + +echo -n "Clear wire wallet:" +$BTC_CLI -rpcwallet=wire sendtoaddress $CLIENT `$BTC_CLI -rpcwallet=wire getbalance` "" "" true > /dev/null +echo " OK" + +echo -n "Making incomplete wire transfer to exchange:" +for n in `$SEQ`; do + $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null + mine_btc +done +next_btc +sleep 10 +mine_btc +sleep 10 +echo " OK" + +echo -n "Check balance:" +check_balance "*" 0.00090000 +echo " OK" + +echo "----- Recover DB -----" + +echo "Reset database" +reset_db # Clear database tables +mine_btc # Trigger worker +sleep 20 + +echo -n "Requesting exchange incoming transaction list:" +check_delta "incoming?delta=-100" "$SEQ" "0.000" +echo " OK" + +echo -n "Requesting exchange outgoing transaction list:" +check_delta "outgoing?delta=-100" "$SEQ" +echo " OK" + +echo -n "Check balance:" +# Balance should not have changed +check_balance "*" 0.00090000 +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/test/btc/wire.sh b/test/btc/wire.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +## Test btc_wire correctly receive and sens transactions on the blockchain + +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 btc-wire" +btc_wire +echo "Start gateway" +gateway +echo "" + +SEQ="seq 10 20" + +echo "----- Receive -----" + +echo -n "Making wire transfer to exchange:" +for n in `$SEQ`; do + btc-wire-cli -d $BTC_DIR transfer 0.000$n > /dev/null + mine_btc # Mine transactions +done +next_btc # Trigger btc_wire +check_balance 9.99826299 0.00165000 +echo " OK" + +echo -n "Requesting exchange incoming transaction list:" +check_delta "incoming?delta=-100" "$SEQ" "0.000" +echo " OK" + +echo "----- Send -----" + +echo -n "Making wire transfer from exchange:" +for n in `$SEQ`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$CLIENT \ + -a BTC:0.0000$n > /dev/null +done +sleep 1 +mine_btc # Mine transactions +check_balance 9.99842799 0.00146311 +echo " OK" + +echo -n "Requesting exchange's outgoing transaction list:" +check_delta "outgoing?delta=-100" "$SEQ" +echo " OK" + +echo "----- Bounce -----" + +clear_wallet + +echo -n "Bounce:" +for n in `$SEQ`; do + $BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.000$n > /dev/null + mine_btc +done +next_btc +sleep 1 +check_balance "*" 0.00011000 +echo " OK" + +echo "All tests passed" +\ No newline at end of file diff --git a/script/setup.sh b/test/common.sh diff --git a/script/conf/bitcoin.conf b/test/conf/bitcoin.conf diff --git a/script/conf/bitcoin2.conf b/test/conf/bitcoin2.conf diff --git a/script/conf/taler_lifetime.conf b/test/conf/taler_lifetime.conf diff --git a/script/conf/taler_test.conf b/test/conf/taler_test.conf diff --git a/test/gateway/api.sh b/test/gateway/api.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +## Test wire_gateway conformance to documentation and its security + +set -eu + +# Create temp file +TEMP_FILE=$(mktemp) + +# Cleanup to run whenever we exit +function cleanup() { + rm -f $TEMP_FILE + wait +} + +# Install cleanup handler (except for kill -9) +trap cleanup EXIT + +source "${BASH_SOURCE%/*}/../common.sh" +ADDRESS=mpTJZxWPerz1Gife6mQSdHT8mMuJK6FP85 +SCHEMA=btc.sql + +echo "----- Setup -----" +echo "Load config file" +load_config +echo "Start database" +setup_db +echo "Start gateway" +gateway +echo "" + +echo "----- Gateway API -----" + +echo -n "Making wire transfer to exchange:" +for n in `seq 1 9`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -D payto://bitcoin/$ADDRESS \ + -a BTC:0.0000$n > /dev/null +done +echo " OK" + +echo -n "Requesting exchange incoming transaction list:" +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i` +for n in `seq 1 9`; do + echo $ALL | grep BTC:0.0000$n > /dev/null +done +echo " OK" + +echo -n "Making wire transfer from exchange:" +for n in `seq 1 9`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -C payto://bitcoin/$ADDRESS \ + -a BTC:0.0000$n > /dev/null +done + +echo " OK" + +echo -n "Requesting exchange's outgoing transaction list:" +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o` +for n in `seq 1 9`; do + echo $ALL | grep BTC:0.0000$n > /dev/null +done +echo " OK" + +echo "----- Endpoint & Method -----" + +echo -n "Unknown endpoint:" +test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}test` -eq 404 && echo " OK" || echo " Failed" + +echo -n "Method not allowed:" +test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}transfer` -eq 405 && echo " OK" || echo " Failed" + +echo "----- Request format -----" + +echo -n "Bad payto url:" +for bad_payto in http://bitcoin/$ADDRESS payto://btc/$ADDRESS payto://bitcoin/$ADDRESS?id=admin payto://bitcoin/$ADDRESS#admin; do + taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C $bad_payto -a BTC:0.00042 2>&1 | grep -q "(400/24)" && echo -n " OK" || echo " Failed" +done +echo "" + +echo -n "Bad bitcoin address:" +taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/42$ADDRESS -a BTC:0.00042 2>&1 | grep -q "(400/24)" && echo " OK" || echo " Failed" + +echo -n "Bad transaction amount:" +taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/$ADDRESS -a ATC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed" + +echo -n "Bad history delta:" +for bad_delta in incoming outgoing incoming?delta=0 outgoing?delta=0; do + test `curl -w %{http_code} -s -o /dev/null "${BANK_ENDPOINT}history/$bad_delta"` -eq 400 && echo -n " OK" || echo -n " Failed" +done +echo "" + +echo "----- History delta -----" + +for endpoint in incoming outgoing; do + echo -n "History $endpoint:" + check_delta ${endpoint}?delta=-9 "seq 1 9" && echo -n " OK" || echo -n " Failed" + check_delta ${endpoint}?delta=9 "seq 1 9" && echo -n " OK" || echo -n " Failed" + check_delta ${endpoint}?delta=-4 "seq 6 9" && echo -n " OK" || echo -n " Failed" + check_delta ${endpoint}?delta=4 "seq 1 4" && echo -n " OK" || echo -n " Failed" + check_delta "${endpoint}?delta=-3&start=5" "seq 2 4" && echo -n " OK" || echo -n " Failed" + check_delta "${endpoint}?delta=3&start=4" "seq 5 7" && echo -n " OK" || echo -n " Failed" + echo "" +done + +echo "----- Transfer idempotence -----" +DATA="{\"request_uid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"amount\":\"BTC:0.000034\",\"exchange_base_url\":\"$BASE_URL\",\"wtid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"credit_account\":\"payto://bitcoin/$ADDRESS\"}" +echo -n "Same:" +test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 200 && echo -n " OK" || echo -n " Failed" +test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 200 && echo " OK" || echo " Failed" +echo -n "Collision:" +DATA="{\"request_uid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"amount\":\"BTC:0.000042\",\"exchange_base_url\":\"$BASE_URL\",\"wtid\":\"0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00\",\"credit_account\":\"payto://bitcoin/$ADDRESS\"}" +test `curl -w %{http_code} -s -o /dev/null -H "Content-Type: application/json" -d $DATA ${BANK_ENDPOINT}transfer` -eq 409 && echo " OK" || echo " Failed" + +echo "----- Security -----" + +# Generate big random file +printf 'HelloWorld%s' {1..1000} > $TEMP_FILE + +echo -n "Handle huge body:" +test `curl -w %{http_code} -X POST -s -o /dev/null -d @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" + +echo -n "Handle body length liar:" +test `curl -w %{http_code} -X POST -H"Content-Length:1024" -s -o /dev/null -d @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" + +# Generate compression bomb +printf 'HelloWorld%s' {1..1000} | pigz -z9 > $TEMP_FILE + +echo -n "Handle compression bomb:" +test `curl -w %{http_code} -X POST -H"Content-Encoding:deflate" -s -o /dev/null --data-binary @$TEMP_FILE ${BANK_ENDPOINT}transfer` -eq 400 && echo " OK" || echo " Failed" + +echo "All tests passed"