decred.org/dcrdex@v1.0.5/dex/testing/doge/harness.sh (about) 1 #!/usr/bin/env bash 2 SYMBOL="doge" 3 DAEMON="dogecoind" 4 CLI="dogecoin-cli" 5 RPC_USER="user" 6 RPC_PASS="pass" 7 ALPHA_LISTEN_PORT="23764" 8 BETA_LISTEN_PORT="23765" 9 DELTA_LISTEN_PORT="23766" 10 GAMMA_LISTEN_PORT="23767" 11 ALPHA_RPC_PORT="23768" 12 BETA_RPC_PORT="23769" 13 DELTA_RPC_PORT="23770" 14 GAMMA_RPC_PORT="23771" 15 ALPHA_MINING_ADDR="mjzB71SzfAi8BwNvobPZ983d8vCdxuQD2i" 16 BETA_MINING_ADDR="mwL7ypWCMEhBhGcsqWNwkvAasuXP3duXQk" 17 18 # Uncomment to disable background mining 19 #NOMINER="1" 20 21 set -ex 22 NODES_ROOT=~/dextest/${SYMBOL} 23 rm -rf "${NODES_ROOT}" 24 SOURCE_DIR=$(pwd) 25 26 ALPHA_DIR="${NODES_ROOT}/alpha" 27 BETA_DIR="${NODES_ROOT}/beta" 28 DELTA_DIR="${NODES_ROOT}/delta" 29 GAMMA_DIR="${NODES_ROOT}/gamma" 30 HARNESS_DIR="${NODES_ROOT}/harness-ctl" 31 32 echo "Writing node config files" 33 mkdir -p "${HARNESS_DIR}" 34 35 WALLET_PASSWORD="abc" 36 37 ALPHA_CLI_CFG="-rpcport=${ALPHA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 38 39 BETA_CLI_CFG="-rpcport=${BETA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 40 41 DELTA_CLI_CFG="-rpcport=${DELTA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 42 43 GAMMA_CLI_CFG="-rpcport=${GAMMA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 44 45 # DONE can be used in a send-keys call along with a `wait-for btc` command to 46 # wait for process termination. 47 DONE="; tmux wait-for -S ${SYMBOL}" 48 WAIT="wait-for ${SYMBOL}" 49 50 SESSION="${SYMBOL}-harness" 51 52 SHELL=$(which bash) 53 54 # Background watch mining by default: 55 # 'export NOMINER="1"' or uncomment this line to disable 56 #NOMINER="1" 57 58 ################################################################################ 59 # Load prepared wallets. 60 ################################################################################ 61 62 mkdir -p ${ALPHA_DIR}/regtest 63 cp ${SOURCE_DIR}/alpha_wallet.dat ${ALPHA_DIR}/regtest/wallet.dat 64 mkdir -p ${BETA_DIR}/regtest 65 cp ${SOURCE_DIR}/beta_wallet.dat ${BETA_DIR}/regtest/wallet.dat 66 mkdir -p ${DELTA_DIR} 67 mkdir -p ${GAMMA_DIR} 68 69 cd ${NODES_ROOT} && tmux new-session -d -s $SESSION $SHELL 70 71 ################################################################################ 72 # Write config files. 73 ################################################################################ 74 75 # These config files aren't actually used here, but can be used by other 76 # programs. I would use them here, but bitcoind seems to have some issues 77 # reading from the file when using regtest. 78 79 cat > "${ALPHA_DIR}/alpha.conf" <<EOF 80 rpcuser=user 81 rpcpassword=pass 82 datadir=${ALPHA_DIR} 83 txindex=1 84 port=${ALPHA_LISTEN_PORT} 85 regtest=1 86 rpcport=${ALPHA_RPC_PORT} 87 EOF 88 89 cat > "${BETA_DIR}/beta.conf" <<EOF 90 rpcuser=user 91 rpcpassword=pass 92 datadir=${BETA_DIR} 93 txindex=1 94 regtest=1 95 rpcport=${BETA_RPC_PORT} 96 EOF 97 98 cat > "${DELTA_DIR}/delta.conf" <<EOF 99 rpcuser=user 100 rpcpassword=pass 101 datadir=${DELTA_DIR} 102 txindex=1 103 regtest=1 104 rpcport=${DELTA_RPC_PORT} 105 EOF 106 107 cat > "${GAMMA_DIR}/gamma.conf" <<EOF 108 rpcuser=user 109 rpcpassword=pass 110 datadir=${GAMMA_DIR} 111 txindex=1 112 regtest=1 113 rpcport=${GAMMA_RPC_PORT} 114 EOF 115 116 ################################################################################ 117 # Start the alpha node. 118 ################################################################################ 119 120 tmux rename-window -t $SESSION:0 'alpha' 121 tmux send-keys -t $SESSION:0 "set +o history" C-m 122 tmux send-keys -t $SESSION:0 "cd ${ALPHA_DIR}" C-m 123 echo "Starting simnet alpha node" 124 tmux send-keys -t $SESSION:0 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 125 -rpcport=${ALPHA_RPC_PORT} -datadir=${ALPHA_DIR} \ 126 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 127 -whitelist=127.0.0.0/8 -whitelist=::1 \ 128 -txindex=1 -regtest=1 -port=${ALPHA_LISTEN_PORT} -fallbackfee=0.00001 \ 129 -printtoconsole; tmux wait-for -S alpha${SYMBOL}" C-m 130 sleep 3 131 132 ################################################################################ 133 # Setup the beta node. 134 ################################################################################ 135 136 tmux new-window -t $SESSION:1 -n 'beta' $SHELL 137 tmux send-keys -t $SESSION:1 "set +o history" C-m 138 tmux send-keys -t $SESSION:1 "cd ${BETA_DIR}" C-m 139 140 echo "Starting simnet beta node" 141 tmux send-keys -t $SESSION:1 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 142 -rpcport=${BETA_RPC_PORT} -datadir=${BETA_DIR} -txindex=1 -regtest=1 \ 143 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 144 -whitelist=127.0.0.0/8 -whitelist=::1 \ 145 -port=${BETA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 146 tmux wait-for -S beta${SYMBOL}" C-m 147 sleep 3 148 149 ################################################################################ 150 # Setup the delta node. 151 ################################################################################ 152 153 tmux new-window -t $SESSION:2 -n 'delta' $SHELL 154 tmux send-keys -t $SESSION:2 "set +o history" C-m 155 tmux send-keys -t $SESSION:2 "cd ${DELTA_DIR}" C-m 156 157 echo "Starting simnet delta node" 158 tmux send-keys -t $SESSION:2 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 159 -rpcport=${DELTA_RPC_PORT} -datadir=${DELTA_DIR} -txindex=1 -regtest=1 \ 160 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 161 -whitelist=127.0.0.0/8 -whitelist=::1 \ 162 -port=${DELTA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 163 tmux wait-for -S delta${SYMBOL}" C-m 164 sleep 3 165 166 ################################################################################ 167 # Setup the gamma node. 168 ################################################################################ 169 170 tmux new-window -t $SESSION:3 -n 'gamma' $SHELL 171 tmux send-keys -t $SESSION:3 "set +o history" C-m 172 tmux send-keys -t $SESSION:3 "cd ${GAMMA_DIR}" C-m 173 174 echo "Starting simnet gamma node" 175 tmux send-keys -t $SESSION:3 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 176 -rpcport=${GAMMA_RPC_PORT} -datadir=${GAMMA_DIR} -txindex=1 -regtest=1 \ 177 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 178 -whitelist=127.0.0.0/8 -whitelist=::1 \ 179 -port=${GAMMA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 180 tmux wait-for -S gamma${SYMBOL}" C-m 181 sleep 3 182 183 ################################################################################ 184 # Setup the harness-ctl directory 185 ################################################################################ 186 187 tmux new-window -t $SESSION:4 -n 'harness-ctl' $SHELL 188 tmux send-keys -t $SESSION:4 "set +o history" C-m 189 tmux send-keys -t $SESSION:4 "cd ${HARNESS_DIR}" C-m 190 sleep 1 191 192 cd ${HARNESS_DIR} 193 194 # start-wallet, connect-alpha, and stop-wallet are used by loadbot to set up and 195 # run new wallets. 196 cat > "./start-wallet" <<EOF 197 #!/usr/bin/env bash 198 199 mkdir ${NODES_ROOT}/\$1 200 201 printf "rpcuser=user\nrpcpassword=pass\ndatadir=${NODES_ROOT}/\$1\ntxindex=1\nregtest=1\nrpcport=\$2\n" > ${NODES_ROOT}/\$1/\$1.conf 202 203 ${DAEMON} -rpcuser=user -rpcpassword=pass \ 204 -rpcport=\$2 -datadir=${NODES_ROOT}/\$1 -txindex=1 -regtest=1 \ 205 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 206 -whitelist=127.0.0.0/8 -whitelist=::1 \ 207 -port=\$3 -fallbackfee=0.00001 208 EOF 209 chmod +x "./start-wallet" 210 211 cat > "./connect-alpha" <<EOF 212 #!/usr/bin/env bash 213 ${CLI} -rpcport=\$1 -regtest=1 -rpcuser=user -rpcpassword=pass addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add 214 EOF 215 chmod +x "./connect-alpha" 216 217 cat > "./stop-wallet" <<EOF 218 #!/usr/bin/env bash 219 ${CLI} -rpcport=\$1 -regtest=1 -rpcuser=user -rpcpassword=pass stop 220 EOF 221 chmod +x "./stop-wallet" 222 223 cat > "./alpha" <<EOF 224 #!/usr/bin/env bash 225 ${CLI} ${ALPHA_CLI_CFG} "\$@" 226 EOF 227 chmod +x "./alpha" 228 229 cat > "./mine-alpha" <<EOF 230 #!/usr/bin/env bash 231 ${CLI} ${ALPHA_CLI_CFG} generatetoaddress \$1 ${ALPHA_MINING_ADDR} 232 EOF 233 chmod +x "./mine-alpha" 234 235 cat > "./beta" <<EOF 236 #!/usr/bin/env bash 237 ${CLI} ${BETA_CLI_CFG} "\$@" 238 EOF 239 chmod +x "./beta" 240 241 cat > "./mine-beta" <<EOF 242 #!/usr/bin/env bash 243 ${CLI} ${BETA_CLI_CFG} generatetoaddress \$1 ${BETA_MINING_ADDR} 244 EOF 245 chmod +x "./mine-beta" 246 247 cat > "./delta" <<EOF 248 #!/usr/bin/env bash 249 ${CLI} ${DELTA_CLI_CFG} "\$@" 250 EOF 251 chmod +x "./delta" 252 253 cat > "./gamma" <<EOF 254 #!/usr/bin/env bash 255 ${CLI} ${GAMMA_CLI_CFG} "\$@" 256 EOF 257 chmod +x "./gamma" 258 259 cat > "./reorg" <<EOF 260 #!/usr/bin/env bash 261 set -x 262 echo "Disconnecting beta from alpha" 263 sleep 1 264 ./beta disconnectnode 127.0.0.1:${ALPHA_LISTEN_PORT} 265 echo "Mining a block on alpha" 266 sleep 1 267 ./mine-alpha 1 268 echo "Mining 3 blocks on beta" 269 ./mine-beta 3 270 sleep 2 271 echo "Reconnecting beta to alpha" 272 ./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} onetry 273 sleep 2 274 EOF 275 chmod +x "./reorg" 276 277 cat > "${HARNESS_DIR}/quit" <<EOF 278 #!/usr/bin/env bash 279 tmux send-keys -t $SESSION:0 C-c 280 tmux send-keys -t $SESSION:1 C-c 281 tmux send-keys -t $SESSION:2 C-c 282 tmux send-keys -t $SESSION:3 C-c 283 tmux send-keys -t $SESSION:5 C-c 284 tmux wait-for alpha${SYMBOL} 285 tmux wait-for beta${SYMBOL} 286 # seppuku 287 tmux kill-session 288 EOF 289 chmod +x "${HARNESS_DIR}/quit" 290 291 ################################################################################ 292 # Generate the first block 293 ################################################################################ 294 tmux send-keys -t $SESSION:4 "./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 295 tmux send-keys -t $SESSION:4 "./delta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 296 tmux send-keys -t $SESSION:4 "./gamma addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 297 # This timeout is apparently critical. Give the nodes time to sync. 298 sleep 1 299 300 tmux send-keys -t $SESSION:4 "./alpha walletpassphrase ${WALLET_PASSWORD} 100000000${DONE}" C-m\; ${WAIT} 301 tmux send-keys -t $SESSION:4 "./beta walletpassphrase ${WALLET_PASSWORD} 100000000${DONE}" C-m\; ${WAIT} 302 303 echo "Generating 400 blocks for alpha" 304 tmux send-keys -t $SESSION:4 "./alpha generatetoaddress 400 ${ALPHA_MINING_ADDR}${DONE}" C-m\; ${WAIT} 305 306 ################################################################################# 307 # Send beta some coin 308 ################################################################################ 309 310 DELTA_ADDR=`./delta getnewaddress` 311 echo "delta address = '${DELTA_ADDR}'" 312 GAMMA_ADDR=`./gamma getnewaddress` 313 echo "gamma address = '${GAMMA_ADDR}'" 314 315 # Send the beta wallet some dough. 316 echo "Sending 8,400,000 DOGE to lazy wallets in 8 blocks" 317 for i in 1000000 1800000 500000 700000 100000 1500000 300000 2500000 318 do 319 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${BETA_MINING_ADDR} ${i}${DONE}" C-m\; ${WAIT} 320 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${DELTA_ADDR} ${i}${DONE}" C-m\; ${WAIT} 321 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${GAMMA_ADDR} ${i}${DONE}" C-m\; ${WAIT} 322 done 323 324 tmux send-keys -t $SESSION:4 "./mine-alpha 2${DONE}" C-m\; ${WAIT} 325 326 ################################################################################ 327 # Setup watch background miner -- if required 328 ################################################################################ 329 if [ -z "$NOMINER" ] ; then 330 tmux new-window -t $SESSION:5 -n "miner" $SHELL 331 tmux send-keys -t $SESSION:5 "cd ${HARNESS_DIR}" C-m 332 tmux send-keys -t $SESSION:5 "watch -n 15 ./mine-alpha 1" C-m 333 fi 334 335 ###################################################################################### 336 # Reenable history select the harness control window & attach to the control session # 337 ###################################################################################### 338 tmux send-keys -t $SESSION:4 "set -o history" C-m 339 tmux select-window -t $SESSION:4 340 tmux attach-session -t $SESSION