summaryrefslogtreecommitdiff
path: root/test/btc/hell.sh
blob: d7c3d51496c1af7a6aaba9af87a31a9f0da71cd5 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/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 ""

echo  "----- Handle reorg conflicting incoming receive -----"

echo "Loose second bitcoin node"
btc2_deco

echo -n "Gen incoming transactions:"
btc-wire-utils -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:"
gateway_up
btc2_fork
check_balance 9.99579209 0.00000000
gateway_down
echo " OK"

echo -n "Check btc-wire hard error on restart:"
btc_wire
sleep 1
gateway_down
echo " OK"

echo -n "Generate conflict:"
restart_btc -minrelaytxfee=0.0001
btc-wire-utils -d $BTC_DIR abandon client
btc-wire-utils -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
gateway_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:"
gateway_up
btc2_fork
check_balance 9.95799859 0.00000000
gateway_down
echo " OK"

echo -n "Check btc-wire hard error on restart:"
btc_wire
sleep 1
gateway_down
echo " OK"

echo -n "Generate conflict:"
restart_btc -minrelaytxfee=0.0001
btc-wire-utils -d $BTC_DIR abandon client
btc-wire-utils -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
gateway_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!"