-
Notifications
You must be signed in to change notification settings - Fork 21
/
harness.sh
executable file
·182 lines (155 loc) · 4.92 KB
/
harness.sh
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
#
# Copyright (c) 2020-2024 The Decred developers
# Use of this source code is governed by an ISC
# license that can be found in the LICENSE file.
#
# Tmux script that sets up a testnet vspd deployment with multiple voting wallets.
#
# To use the script simply run `./harness.sh` from the repo root.
#
# By default, the harness script will use `/tmp/vspd-harness` as a working
# directory. This can be changed using the `-r` flag, eg:
#
# ./harness.sh -r /my/harness/path
#
# The harness script makes a few assumptions about the system it is running on:
# - tmux is installed
# - dcrd, dcrwallet and vspd are available on $PATH
# - Decred testnet chain is already downloaded and sync'd
# - dcrd transaction index is already built
# - The following files exist:
# - ${HOME}/.dcrd/rpc.cert
# - ${HOME}/.dcrd/rpc.key
# - ${HOME}/.dcrwallet/rpc.cert
# - ${HOME}/.dcrwallet/rpc.key
set -e
TMUX_SESSION="vspd-harness"
RPC_USER="user"
RPC_PASS="pass"
NUMBER_OF_WALLETS=3
DCRD_RPC_CERT="${HOME}/.dcrd/rpc.cert"
DCRD_RPC_KEY="${HOME}/.dcrd/rpc.key"
WALLET_PASS="12345"
WALLET_RPC_CERT="${HOME}/.dcrwallet/rpc.cert"
WALLET_RPC_KEY="${HOME}/.dcrwallet/rpc.key"
VSPD_FEE_XPUB="tpubVppjaMjp8GEWzpMGHdXNhkjqof8baKGkUzneNEiocnnjnjY9hQPe6mxzZQyzyKYS3u5yxLp8KrJvibqDzc75RGqzkv2JMPYDXmCRR1a39jg"
HARNESS_ROOT=/tmp/vspd-harness
while getopts r: flag
do
case "${flag}" in
r) HARNESS_ROOT=${OPTARG};
esac
done
if [ -d "${HARNESS_ROOT}" ]; then
while true; do
read -p "Wipe existing harness dir? " yn
case $yn in
[Yy]* ) rm -R "${HARNESS_ROOT}"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
tmux new-session -d -s $TMUX_SESSION
#################################################
# Setup dcrd.
#################################################
tmux rename-window -t $TMUX_SESSION 'dcrd'
echo "Writing config for dcrd"
mkdir -p "${HARNESS_ROOT}/dcrd"
cat > "${HARNESS_ROOT}/dcrd/dcrd.conf" <<EOF
rpcuser=${RPC_USER}
rpcpass=${RPC_PASS}
rpccert=${DCRD_RPC_CERT}
rpckey=${DCRD_RPC_KEY}
logdir=${HARNESS_ROOT}/dcrd/log
testnet=true
debuglevel=info
txindex=true
EOF
echo "Starting dcrd"
tmux send-keys "dcrd -C ${HARNESS_ROOT}/dcrd/dcrd.conf" C-m
sleep 1 # Give dcrd time to start
#################################################
# Setup multiple dcrwallets.
#################################################
for ((i = 1; i <= $NUMBER_OF_WALLETS; i++)); do
WALLET_RPC_LISTEN="127.0.0.1:2011${i}"
# Concatenate all wallet details for vspd config file.
if [ $i == 1 ]; then
ALL_WALLET_HOST="${WALLET_RPC_LISTEN}"
ALL_WALLET_USER="${RPC_USER}"
ALL_WALLET_PASS="${RPC_PASS}"
ALL_WALLET_CERT="${WALLET_RPC_CERT}"
else
ALL_WALLET_HOST="${ALL_WALLET_HOST},${WALLET_RPC_LISTEN}"
ALL_WALLET_USER="${ALL_WALLET_USER},${RPC_USER}"
ALL_WALLET_PASS="${ALL_WALLET_PASS},${RPC_PASS}"
ALL_WALLET_CERT="${ALL_WALLET_CERT},${WALLET_RPC_CERT}"
fi
echo ""
echo "Writing config for dcrwallet-${i}"
mkdir -p "${HARNESS_ROOT}/dcrwallet-${i}"
cat > "${HARNESS_ROOT}/dcrwallet-${i}/dcrwallet.conf" <<EOF
username=${RPC_USER}
password=${RPC_PASS}
rpccert=${WALLET_RPC_CERT}
rpckey=${WALLET_RPC_KEY}
logdir=${HARNESS_ROOT}/dcrwallet-${i}/log
appdata=${HARNESS_ROOT}/dcrwallet-${i}
pass=${WALLET_PASS}
grpclisten=127.0.0.1:2010${i}
rpclisten=${WALLET_RPC_LISTEN}
enablevoting=true
manualtickets=true
testnet=true
debuglevel=info
EOF
echo "Starting dcrwallet-${i}"
tmux new-window -t $TMUX_SESSION -n "dcrwallet-${i}"
# Create wallet.
tmux send-keys "dcrwallet -C ${HARNESS_ROOT}/dcrwallet-${i}/dcrwallet.conf --create <<EOF
y
n
n
ok
EOF" C-m
sleep 1
# Start wallet.
tmux send-keys "dcrwallet -C ${HARNESS_ROOT}/dcrwallet-${i}/dcrwallet.conf " C-m
done
#################################################
# Setup vspd.
#################################################
echo ""
echo "Writing config for vspd"
mkdir -p "${HARNESS_ROOT}/vspd"
cat > "${HARNESS_ROOT}/vspd/vspd.conf" <<EOF
dcrduser = ${RPC_USER}
dcrdpass = ${RPC_PASS}
dcrdcert = ${DCRD_RPC_CERT}
wallethost = ${ALL_WALLET_HOST}
walletuser = ${ALL_WALLET_USER}
walletpass = ${ALL_WALLET_PASS}
walletcert = ${ALL_WALLET_CERT}
loglevel = debug
network = testnet
webserverdebug = false
supportemail = [email protected]
backupinterval = 3m0s
vspclosed = false
vspclosedmsg = Your tickets are no longer welcome here. Please go away.
adminpass=12345
designation = harness
EOF
tmux new-window -t $TMUX_SESSION -n "vspd"
echo "Creating vspd database"
tmux send-keys "go run ./cmd/vspadmin --homedir=${HARNESS_ROOT}/vspd --network=testnet createdatabase ${VSPD_FEE_XPUB}" C-m
sleep 3 # wait for database creation and ensure dcrwallet rpc listeners are started
echo "Starting vspd"
tmux send-keys "vspd --homedir=${HARNESS_ROOT}/vspd" C-m
#################################################
# All done - attach to tmux session.
#################################################
tmux attach-session -t $TMUX_SESSION