summaryrefslogtreecommitdiff
path: root/script/test_btc_stress.sh
blob: b3b6ed741f67a0054b2a42782d398c24b82106f4 (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
103
104
#!/bin/bash

## Test btc_wire behavior when ran and stressed concurrently 

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 stressed -----"
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 ""

SEQ="seq 10 99"

function check() {
    check_delta "$1?delta=-100" "$SEQ"
}

echo "----- Handle incoming -----"

echo -n "Making wire transfer to exchange:"
for n in `$SEQ`; do
    btc-wire-cli -d $BTC_DIR transfer 0.0000$n
    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 incoming
echo " OK"

echo -n "Check balance:"
check_balance 9.99438310  1.00490500
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 outgoing
echo " OK"

echo -n "Check balance:"
check_balance 9.99928810
echo " OK"

next_btc # Mine transactions
echo "----- Recover DB -----"

echo "Reset database"
reset_db # Clear database tables
mine_btc # Trigger worker
sleep 3

echo -n "Requesting exchange incoming transaction list:"
check incoming
echo " OK"

echo -n "Requesting exchange outgoing transaction list:"
check outgoing
echo " OK"

echo -n "Check balance:"
# Balance should not have changed
check_balance 9.99928810
echo " OK"

echo "All tests passed"