summaryrefslogtreecommitdiff
path: root/test/btc/reorg.sh
blob: a0de12d306e5a5d65ebc0b0d461171d43b012926 (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
105
106
107
108
109
110
111
112
113
114
115
#!/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 ""

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-utils -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:"
gateway_up
btc2_fork 22
check_balance 9.99826299 0.00000000
gateway_down
echo " OK"

echo -n "Recover orphaned transactions:"
next_btc 6 # More block needed to confirm
check_balance 9.99826299 0.00165000
gateway_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:"
gateway_up
btc2_fork 22
check_balance 9.99826299 0.00146311
gateway_up
echo " OK"

echo -n "Recover orphaned transactions:"
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

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 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 22
check_balance "*" 0.00000000
gateway_down
echo " OK"

echo -n "Recover orphaned transactions:"
next_btc 6 # More block needed to confirm
check_balance "*" 0.00011000
echo " OK"

echo "All tests passed!"