summaryrefslogtreecommitdiff
path: root/script/test_recover_db.sh
blob: d90a54116995cbc8fa391fac7fa0a3a61f193cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

## Check the capacity of wire_gateway and btc_wire to recover from database loss

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"
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
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"
sudo service postgresql stop > /dev/null
echo "Making incomplete wire transfer to exchange"
$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.00042 &> /dev/null
echo "Making wire transfer to exchange:"
btc-wire-cli -d $BTC_DIR transfer 0.00004
next_btc
check_balance 9.99948077 0.00050200
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"
sudo service postgresql start > /dev/null
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"