blob: 7c7ed448ad110b1c718e3c55f956910bb9c5f08a (
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
|
#!/bin/bash
function load_config() {
source <(grep = test.conf | sed 's/ *= */=/' | sed 's/=\(.*\)/="\1"/g1')
BANK_ENDPOINT=http://127.0.0.1:$PORT/
}
function reset_db() {
# TODO sudo alternative ?
sudo service postgresql start > /dev/null
sudo -u postgres psql $DB_URL < wire-gateway/db/schema.sql > /dev/null
}
function init_btc() {
BTC_DIR=$(mktemp -d)
BTC_CLI="bitcoin-cli -regtest -datadir=$BTC_DIR"
bitcoind -datadir=$BTC_DIR -txindex -regtest -fallbackfee=0.00000001 &> /dev/null &
$BTC_CLI -rpcwait getnetworkinfo > /dev/null
}
function restart_btc() {
BTC_CLI="bitcoin-cli -regtest -datadir=$BTC_DIR"
bitcoind -datadir=$BTC_DIR -txindex -regtest -fallbackfee=0.00000001 &> /dev/null &
$BTC_CLI -rpcwait getnetworkinfo > /dev/null
for wallet in wire client reserve; do
$BTC_CLI loadwallet $wallet > /dev/null
done
}
function setup_btc() {
for wallet in wire client reserve; do
$BTC_CLI createwallet $wallet > /dev/null
done
RESERVE=`$BTC_CLI -rpcwallet=reserve getnewaddress`
CLIENT=`$BTC_CLI -rpcwallet=client getnewaddress`
$BTC_CLI generatetoaddress 101 $RESERVE > /dev/null
$BTC_CLI -rpcwallet=reserve sendtoaddress $CLIENT 1 > /dev/null
$BTC_CLI generatetoaddress 1 $RESERVE > /dev/null
}
function next_btc() {
# Mine one block
$BTC_CLI generatetoaddress 1 $RESERVE > /dev/null
# Wait for btc_wire to catch up
sleep 0.5
}
function check_balance() {
CLIENT_BALANCE=`$BTC_CLI -rpcwallet=client getbalance`
WIRE_BALANCE=`$BTC_CLI -rpcwallet=wire getbalance`
if [ "$CLIENT_BALANCE" != "$1" ] || [ "$WIRE_BALANCE" != "$2" ]; then
echo "expected: client $1 wire $2 got: client $CLIENT_BALANCE wire $WIRE_BALANCE"
exit 1
fi
}
function btc_wire() {
cargo build --bin btc-wire &> /dev/null
target/debug/btc-wire $BTC_DIR &> btc_wire.log &
# Can be used to test db transactions serialization
#target/debug/btc-wire $BTC_DIR &>> btc_wire.log &
#target/debug/btc-wire $BTC_DIR &>> btc_wire.log &
}
function gateway() {
cargo build --bin wire-gateway --features test &> /dev/null
target/debug/wire-gateway &> gateway.log &
for n in `seq 1 50`; do
echo -n "."
sleep 0.2
curl -s $BANK_ENDPOINT -o /dev/null && break
done
}
|