decred.org/dcrdex@v1.0.5/dex/testing/zec/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="zec" 7 DAEMON="zcashd" 8 CLI="zcash-cli" 9 RPC_USER="user" 10 RPC_PASS="pass" 11 ALPHA_LISTEN_PORT="33764" 12 BETA_LISTEN_PORT="33765" 13 DELTA_LISTEN_PORT="33766" 14 GAMMA_LISTEN_PORT="33767" 15 ALPHA_RPC_PORT="33768" 16 BETA_RPC_PORT="33769" 17 DELTA_RPC_PORT="33770" 18 GAMMA_RPC_PORT="33771" 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:1 85 nuparams=2bb40e60:1 86 nuparams=f5b9230b:1 87 nuparams=e9ff75a6:2 88 nuparams=c2d6d0b4:3 89 EOF 90 91 cat > "${BETA_DIR}/beta.conf" <<EOF 92 rpcuser=user 93 rpcpassword=pass 94 txindex=1 95 regtest=1 96 rpcport=${BETA_RPC_PORT} 97 exportdir=${SOURCE_DIR} 98 nuparams=5ba81b19:1 99 nuparams=76b809bb:1 100 nuparams=2bb40e60:1 101 nuparams=f5b9230b:1 102 nuparams=e9ff75a6:2 103 nuparams=c2d6d0b4:3 104 EOF 105 106 cat > "${DELTA_DIR}/delta.conf" <<EOF 107 rpcuser=user 108 rpcpassword=pass 109 regtest=1 110 rpcport=${DELTA_RPC_PORT} 111 exportdir=${SOURCE_DIR} 112 nuparams=5ba81b19:1 113 nuparams=76b809bb:1 114 nuparams=2bb40e60:1 115 nuparams=f5b9230b:1 116 nuparams=e9ff75a6:2 117 nuparams=c2d6d0b4:3 118 EOF 119 120 cat > "${GAMMA_DIR}/gamma.conf" <<EOF 121 rpcuser=user 122 rpcpassword=pass 123 regtest=1 124 rpcport=${GAMMA_RPC_PORT} 125 exportdir=${SOURCE_DIR} 126 nuparams=5ba81b19:1 127 nuparams=76b809bb:1 128 nuparams=2bb40e60:1 129 nuparams=f5b9230b:1 130 nuparams=e9ff75a6:2 131 nuparams=c2d6d0b4:3 132 EOF 133 134 ################################################################################ 135 # Start the alpha node. 136 ################################################################################ 137 138 tmux rename-window -t $SESSION:0 'alpha' 139 tmux send-keys -t $SESSION:0 "set +o history" C-m 140 tmux send-keys -t $SESSION:0 "cd ${ALPHA_DIR}" C-m 141 echo "Starting simnet alpha node" 142 tmux send-keys -t $SESSION:0 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 143 -rpcport=${ALPHA_RPC_PORT} -datadir=${ALPHA_DIR} -conf=alpha.conf \ 144 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 145 -whitelist=127.0.0.0/8 -whitelist=::1 -preferredtxversion=5 \ 146 -txindex=1 -regtest=1 -port=${ALPHA_LISTEN_PORT} -fallbackfee=0.00001 \ 147 -printtoconsole; tmux wait-for -S alpha${SYMBOL}" C-m 148 149 ################################################################################ 150 # Setup the beta node. 151 ################################################################################ 152 153 tmux new-window -t $SESSION:1 -n 'beta' $SHELL 154 tmux send-keys -t $SESSION:1 "set +o history" C-m 155 tmux send-keys -t $SESSION:1 "cd ${BETA_DIR}" C-m 156 157 echo "Starting simnet beta node" 158 tmux send-keys -t $SESSION:1 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 159 -rpcport=${BETA_RPC_PORT} -datadir=${BETA_DIR} -conf=beta.conf -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 -preferredtxversion=5 \ 162 -port=${BETA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 163 tmux wait-for -S beta${SYMBOL}" C-m 164 165 ################################################################################ 166 # Setup the delta node. 167 ################################################################################ 168 169 tmux new-window -t $SESSION:2 -n 'delta' $SHELL 170 tmux send-keys -t $SESSION:2 "set +o history" C-m 171 tmux send-keys -t $SESSION:2 "cd ${DELTA_DIR}" C-m 172 173 echo "Starting simnet delta node" 174 tmux send-keys -t $SESSION:2 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 175 -rpcport=${DELTA_RPC_PORT} -datadir=${DELTA_DIR} -conf=delta.conf -regtest=1 \ 176 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 177 -whitelist=127.0.0.0/8 -whitelist=::1 -preferredtxversion=5 \ 178 -port=${DELTA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 179 tmux wait-for -S delta${SYMBOL}" C-m 180 181 ################################################################################ 182 # Setup the gamma node. 183 ################################################################################ 184 185 tmux new-window -t $SESSION:3 -n 'gamma' $SHELL 186 tmux send-keys -t $SESSION:3 "set +o history" C-m 187 tmux send-keys -t $SESSION:3 "cd ${GAMMA_DIR}" C-m 188 189 echo "Starting simnet gamma node" 190 tmux send-keys -t $SESSION:3 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 191 -rpcport=${GAMMA_RPC_PORT} -datadir=${GAMMA_DIR} -conf=gamma.conf -regtest=1 \ 192 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 193 -whitelist=127.0.0.0/8 -whitelist=::1 -preferredtxversion=5 \ 194 -port=${GAMMA_LISTEN_PORT} -fallbackfee=0.00001 -printtoconsole; \ 195 tmux wait-for -S gamma${SYMBOL}" C-m 196 sleep 30 197 198 ################################################################################ 199 # Setup the harness-ctl directory 200 ################################################################################ 201 202 tmux new-window -t $SESSION:4 -n 'harness-ctl' $SHELL 203 tmux send-keys -t $SESSION:4 "set +o history" C-m 204 tmux send-keys -t $SESSION:4 "cd ${HARNESS_DIR}" C-m 205 sleep 1 206 207 cd ${HARNESS_DIR} 208 209 # start-wallet, connect-alpha, and stop-wallet are used by loadbot to set up and 210 # run new wallets. 211 cat > "./start-wallet" <<EOF 212 #!/usr/bin/env bash 213 214 mkdir ${NODES_ROOT}/\$1 215 216 printf "rpcuser=user\nrpcpassword=pass\nregtest=1\nrpcport=\$2\nexportdir=${SOURCE_DIR}\nnuparams=5ba81b19:1\nnuparams=76b809bb:1\nnuparams=2bb40e60:1\nnuparams=f5b9230b:1\nnuparams=e9ff75a6:2\nnuparams=c2d6d0b4:3\n" > ${NODES_ROOT}/\$1/\$1.conf 217 218 ${DAEMON} -rpcuser=user -rpcpassword=pass \ 219 -rpcport=\$2 -datadir=${NODES_ROOT}/\$1 -regtest=1 -conf=\$1.conf \ 220 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 221 -whitelist=127.0.0.0/8 -whitelist=::1 -preferredtxversion=5 \ 222 -port=\$3 -fallbackfee=0.00001 -printtoconsole 223 EOF 224 chmod +x "./start-wallet" 225 226 cat > "./connect-alpha" <<EOF 227 #!/usr/bin/env bash 228 ${CLI} -conf=${NODES_ROOT}/\$2/\$2.conf -rpcport=\$1 -regtest=1 -rpcuser=user -rpcpassword=pass addnode 127.0.0.1:${ALPHA_LISTEN_PORT} onetry 229 EOF 230 chmod +x "./connect-alpha" 231 232 cat > "./stop-wallet" <<EOF 233 #!/usr/bin/env bash 234 ${CLI} -conf=${NODES_ROOT}/\$2/\$2.conf -rpcport=\$1 -regtest=1 -rpcuser=user -rpcpassword=pass stop 235 EOF 236 chmod +x "./stop-wallet" 237 238 cat > "./alpha" <<EOF 239 #!/usr/bin/env bash 240 ${CLI} ${ALPHA_CLI_CFG} "\$@" 241 EOF 242 chmod +x "./alpha" 243 244 cat > "./beta" <<EOF 245 #!/usr/bin/env bash 246 ${CLI} ${BETA_CLI_CFG} "\$@" 247 EOF 248 chmod +x "./beta" 249 250 cat > "./delta" <<EOF 251 #!/usr/bin/env bash 252 ${CLI} ${DELTA_CLI_CFG} "\$@" 253 EOF 254 chmod +x "./delta" 255 256 cat > "./gamma" <<EOF 257 #!/usr/bin/env bash 258 ${CLI} ${GAMMA_CLI_CFG} "\$@" 259 EOF 260 chmod +x "./gamma" 261 262 cat > "./mine-alpha" <<EOF 263 #!/usr/bin/env bash 264 ${CLI} ${ALPHA_CLI_CFG} generate \$1 265 EOF 266 chmod +x "./mine-alpha" 267 268 cat > "./mine-beta" <<EOF 269 #!/usr/bin/env bash 270 ${CLI} ${BETA_CLI_CFG} generate \$1 271 EOF 272 chmod +x "./mine-beta" 273 274 cat > "./reorg" <<EOF 275 #!/usr/bin/env bash 276 set -x 277 echo "Disconnecting beta from alpha" 278 sleep 1 279 ./beta disconnectnode 127.0.0.1:${ALPHA_LISTEN_PORT} 280 echo "Mining a block on alpha" 281 sleep 1 282 ./mine-alpha 1 283 echo "Mining 3 blocks on beta" 284 ./mine-beta 3 285 sleep 2 286 echo "Reconnecting beta to alpha" 287 ./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} onetry 288 sleep 2 289 EOF 290 chmod +x "./reorg" 291 292 cat > "${HARNESS_DIR}/quit" <<EOF 293 #!/usr/bin/env bash 294 tmux send-keys -t $SESSION:0 C-c 295 tmux send-keys -t $SESSION:1 C-c 296 tmux send-keys -t $SESSION:2 C-c 297 tmux send-keys -t $SESSION:3 C-c 298 tmux wait-for alpha${SYMBOL} 299 tmux wait-for beta${SYMBOL} 300 tmux wait-for delta${SYMBOL} 301 tmux wait-for gamma${SYMBOL} 302 # seppuku 303 tmux kill-session 304 EOF 305 chmod +x "${HARNESS_DIR}/quit" 306 307 sleep 10 308 309 tmux send-keys -t $SESSION:4 "./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 310 tmux send-keys -t $SESSION:4 "./delta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 311 tmux send-keys -t $SESSION:4 "./gamma addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 312 # This timeout is apparently critical. Give the nodes time to sync. 313 sleep 3 314 315 echo "Generating the genesis block" 316 tmux send-keys -t $SESSION:4 "./alpha generate 1${DONE}" C-m\; ${WAIT} 317 sleep 1 318 319 tmux send-keys -t $SESSION:4 "./alpha z_importwallet ${SOURCE_DIR}/alphawallet ${DONE}" C-m\; ${WAIT} 320 tmux send-keys -t $SESSION:4 "./beta z_importwallet ${SOURCE_DIR}/betawallet ${DONE}" C-m\; ${WAIT} 321 tmux send-keys -t $SESSION:4 "./delta z_importwallet ${SOURCE_DIR}/deltawallet ${DONE}" C-m\; ${WAIT} 322 tmux send-keys -t $SESSION:4 "./gamma z_importwallet ${SOURCE_DIR}/gammawallet ${DONE}" C-m\; ${WAIT} 323 324 echo "Generating 600 blocks for alpha" 325 tmux send-keys -t $SESSION:4 "./alpha generate 600${DONE}" C-m\; ${WAIT} 326 327 ################################################################################ 328 # Send gamma and delta some coin 329 ################################################################################ 330 331 getaddr () { 332 cd ${HARNESS_DIR} 333 NODE=$1 334 ./${NODE} z_getnewaccount > /dev/null 335 R=$(./${NODE} z_getaddressforaccount 0) 336 UADDR=$(sed -rn 's/.*"address": "([^"]+)".*/\1/p' <<< "${R}") 337 R=$(./${NODE} z_listunifiedreceivers ${UADDR}) 338 ADDR=$(sed -rn 's/.*"p2pkh": "([^"]+)".*/\1/p' <<< "${R}") 339 echo $ADDR 340 } 341 342 ALPHA_ADDR="tmEgW8c44RQQfft9FHXnqGp8XEcQQSRcUXD" 343 BETA_ADDR=$(getaddr beta) 344 DELTA_ADDR=$(getaddr delta) 345 GAMMA_ADDR=$(getaddr gamma) 346 347 echo "beta address ${BETA_ADDR}" 348 echo "delta address ${DELTA_ADDR}" 349 echo "gamma address ${GAMMA_ADDR}" 350 351 # Send the lazy wallets some dough. 352 echo "Sending 74 ZEC to beta in 8 blocks" 353 for i in 18 5 7 1 15 3 25 354 do 355 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${BETA_ADDR} ${i}${DONE}" C-m\; ${WAIT} 356 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${DELTA_ADDR} ${i}${DONE}" C-m\; ${WAIT} 357 tmux send-keys -t $SESSION:4 "./alpha sendtoaddress ${GAMMA_ADDR} ${i}${DONE}" C-m\; ${WAIT} 358 done 359 360 tmux send-keys -t $SESSION:4 "./mine-alpha 2${DONE}" C-m\; ${WAIT} 361 362 tmux new-window -t $SESSION:5 -n 'miner' $SHELL 363 tmux send-keys -t $SESSION:5 "cd ${HARNESS_DIR}" C-m 364 tmux send-keys -t $SESSION:5 "watch -n 15 ./mine-alpha 1" C-m 365 366 # Reenable history and attach to the control session. 367 tmux select-window -t $SESSION:4 368 tmux send-keys -t $SESSION:4 "set -o history" C-m 369 tmux attach-session -t $SESSION