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