decred.org/dcrdex@v1.0.5/dex/testing/dash/harness.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Tmux script that sets up a simnet harness for Dash. 4 # 5 # Wallets can be re-created using seed phrase. 'sethdseed' does not exist 6 # Rather you can make a Blank non HD wallet and use 'upgradetohd' using 7 # a "mnemonic" parameter that is a set of seed words from the hdseed of 8 # a previous wallet. This is really for restoring wallets but we can use 9 # it to make a repeatable wallet. 10 11 SYMBOL="dash" 12 # Dash binaries should be in PATH 13 DAEMON="dashd" 14 CLI="dash-cli" 15 RPC_USER="user" 16 RPC_PASS="pass" 17 ALPHA_LISTEN_PORT="20775" 18 BETA_LISTEN_PORT="20776" 19 ALPHA_RPC_PORT="20777" 20 BETA_RPC_PORT="20778" 21 WALLET_PASSWORD="abc" 22 23 # These should be BIP39 mnemomic seed words representing the wallet's hdseed. 24 # Using the hex hdseed directly does not seem to be possible. 25 # 26 # With no mnemonic supplied dash core will generate a random hdseed when the 27 # `upgradetohd' RPC is called.` 28 ALPHA_SEED_MNEMONIC="lecture crew glove notable rail wink artefact canvas wreck achieve render sail select rigid guide celery pluck nature brass galaxy faith hire confirm bullet" 29 BETA_SEED_MNEMONIC="spider truth grid loan blame wall proof again link book teach quiz sniff parrot spare reward manual flower smoke fury nest kingdom possible roof" 30 GAMMA_SEED_MNEMONIC="tent spend begin analyst salute flavor mind gift speak oval lunar wife during issue pull muscle hamster mosquito note benefit radar observe reveal tiny" 31 DELTA_SEED_MNEMONIC="great harsh elite anger thunder mandate ladder rough butter image defense elevator boss border submit matter tobacco banner rather talent prevent mother defense jump" 32 33 # "" 34 # ├── gamma 35 # │ └── wallet.dat 36 # └── wallet.dat 37 # "" 38 # ├── delta 39 # │ └── wallet.dat 40 # └── wallet.dat 41 42 # alpha node has an unnamed HD wallet "" 43 ALPHA_MINING_ADDR="yNuBWDrd4z5X98jUbFv9QGA5kEovzr8tbF" 44 45 # beta node has an unnamed HD wallet "" 46 BETA_MINING_ADDR="yXsphR4cWKFy2wyApUC5fbWPX3u8Pg6wqi" 47 48 # gamma is a named HD wallet in the alpha node's wallet directory. 49 GAMMA_ADDRESS="yQmfjX89287y3cYFXdDAo882VCG7cSspRm" 50 51 # delta is a named HD wallet in the beta node's wallet directory. 52 DELTA_ADDRESS="ySM59Zz7BsVsd8TJnNbLTXoZmkqN4Ph2Yw" 53 54 # Background watch mining in window 3 by default: 55 # 'export NOMINER="1"' or uncomment this line to disable 56 #NOMINER="1" 57 58 set -ex 59 60 SHELL=$(which bash) 61 62 NODES_ROOT=~/dextest/${SYMBOL} 63 rm -rf "${NODES_ROOT}" 64 ## Tree clean ## 65 66 ALPHA_CLI_CFG="-rpcwallet= -rpcport=${ALPHA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 67 BETA_CLI_CFG="-rpcwallet= -rpcport=${BETA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 68 69 GAMMA_CLI_CFG="-rpcwallet=gamma -rpcport=${ALPHA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 70 DELTA_CLI_CFG="-rpcwallet=delta -rpcport=${BETA_RPC_PORT} -regtest=1 -rpcuser=user -rpcpassword=pass" 71 72 # DONE can be used in a send-keys call along with a `wait-for dash` command to 73 # wait for process termination. 74 DONE="; tmux wait-for -S ${SYMBOL}" 75 WAIT="wait-for ${SYMBOL}" 76 77 ################################################################################ 78 # Make directories and start tmux 79 ################################################################################ 80 ALPHA_DIR="${NODES_ROOT}/alpha" 81 BETA_DIR="${NODES_ROOT}/beta" 82 HARNESS_DIR="${NODES_ROOT}/harness-ctl" 83 84 mkdir -p "${ALPHA_DIR}" 85 mkdir -p "${BETA_DIR}" 86 mkdir -p "${HARNESS_DIR}" 87 88 SESSION="${SYMBOL}-harness" 89 90 cd ${NODES_ROOT} && tmux new-session -d -s $SESSION $SHELL 91 92 ################################################################################ 93 # Write config files. 94 ################################################################################ 95 96 echo "Writing node config files" 97 98 # These config files aren't actually used here, but can be used by other 99 # programs. 100 101 cat > "${ALPHA_DIR}/alpha.conf" <<EOF 102 rpcwallet= 103 rpcuser=user 104 rpcpassword=pass 105 datadir=${ALPHA_DIR} 106 txindex=1 107 port=${ALPHA_LISTEN_PORT} 108 regtest=1 109 rpcport=${ALPHA_RPC_PORT} 110 EOF 111 112 cat > "${BETA_DIR}/beta.conf" <<EOF 113 rpcwallet= 114 rpcuser=user 115 rpcpassword=pass 116 datadir=${BETA_DIR} 117 txindex=1 118 regtest=1 119 rpcport=${BETA_RPC_PORT} 120 EOF 121 122 ################################################################################ 123 # Start the alpha node. 124 ################################################################################ 125 126 tmux rename-window -t $SESSION:0 'alpha' 127 tmux send-keys -t $SESSION:0 "set +o history" C-m 128 tmux send-keys -t $SESSION:0 "cd ${ALPHA_DIR}" C-m 129 130 echo "Starting simnet alpha node" 131 tmux send-keys -t $SESSION:0 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 132 -rpcport=${ALPHA_RPC_PORT} -datadir=${ALPHA_DIR} \ 133 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 134 -whitelist=127.0.0.0/8 -whitelist=::1 \ 135 -txindex=1 -regtest=1 -port=${ALPHA_LISTEN_PORT} -fallbackfee=0.00001 \ 136 ${EXTRA_ARGS}; tmux wait-for -S alpha${SYMBOL}" C-m 137 sleep 3 138 139 ################################################################################ 140 # Start the beta node. 141 ################################################################################ 142 143 tmux new-window -t $SESSION:1 -n 'beta' $SHELL 144 tmux send-keys -t $SESSION:1 "set +o history" C-m 145 tmux send-keys -t $SESSION:1 "cd ${BETA_DIR}" C-m 146 147 echo "Starting simnet beta node" 148 tmux send-keys -t $SESSION:1 "${DAEMON} -rpcuser=user -rpcpassword=pass \ 149 -rpcport=${BETA_RPC_PORT} -datadir=${BETA_DIR} \ 150 -debug=rpc -debug=net -debug=mempool -debug=walletdb -debug=addrman -debug=mempoolrej \ 151 -whitelist=127.0.0.0/8 -whitelist=::1 \ 152 -txindex=1 -regtest=1 -port=${BETA_LISTEN_PORT} -fallbackfee=0.00001 \ 153 ${EXTRA_ARGS}; tmux wait-for -S beta${SYMBOL}" C-m 154 sleep 3 155 156 ################################################################################ 157 # Setup the harness-ctl directory with scripts 158 ################################################################################ 159 160 tmux new-window -t $SESSION:2 -n 'harness-ctl' $SHELL 161 tmux send-keys -t $SESSION:2 "set +o history" C-m 162 tmux send-keys -t $SESSION:2 "cd ${HARNESS_DIR}" C-m 163 sleep 1 164 165 cd ${HARNESS_DIR} 166 167 cat > "./alpha" <<EOF 168 #!/usr/bin/env bash 169 ${CLI} ${ALPHA_CLI_CFG} "\$@" 170 EOF 171 chmod +x "./alpha" 172 173 cat > "./mine-alpha" <<EOF 174 #!/usr/bin/env bash 175 ${CLI} ${ALPHA_CLI_CFG} generatetoaddress \$1 ${ALPHA_MINING_ADDR} 176 EOF 177 chmod +x "./mine-alpha" 178 179 cat > "./beta" <<EOF 180 #!/usr/bin/env bash 181 ${CLI} ${BETA_CLI_CFG} "\$@" 182 EOF 183 chmod +x "./beta" 184 185 cat > "./mine-beta" <<EOF 186 #!/usr/bin/env bash 187 ${CLI} ${BETA_CLI_CFG} generatetoaddress \$1 ${BETA_MINING_ADDR} 188 EOF 189 chmod +x "./mine-beta" 190 191 cat > "./gamma" <<EOF 192 #!/usr/bin/env bash 193 ${CLI} ${GAMMA_CLI_CFG} "\$@" 194 EOF 195 chmod +x "./gamma" 196 197 cat > "./delta" <<EOF 198 #!/usr/bin/env bash 199 ${CLI} ${DELTA_CLI_CFG} "\$@" 200 EOF 201 chmod +x "./delta" 202 203 cat > "./reorg" <<EOF 204 #!/usr/bin/env bash 205 set -x 206 echo "Disconnecting beta from alpha" 207 sleep 1 208 ./beta disconnectnode 127.0.0.1:${ALPHA_LISTEN_PORT} 209 echo "Mining a block on alpha" 210 sleep 1 211 ./mine-alpha 1 212 echo "Mining 3 blocks on beta" 213 ./mine-beta 3 214 sleep 2 215 echo "Reconnecting beta to alpha" 216 ./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} onetry 217 sleep 2 218 EOF 219 chmod +x "./reorg" 220 221 cat > "./new-wallet" <<EOF 222 #!/usr/bin/env bash 223 echo "making a new named non-hd wallet on "\$1" node: name="\$2" password=none" 224 "./\$1" createwallet "\$2" false false 225 EOF 226 chmod +x "./new-wallet" 227 228 cat > "${HARNESS_DIR}/quit" <<EOF 229 #!/usr/bin/env bash 230 tmux send-keys -t $SESSION:0 C-c 231 tmux send-keys -t $SESSION:1 C-c 232 if [ -z "$NOMINER" ] ; then 233 tmux send-keys -t $SESSION:3 C-c 234 fi 235 tmux wait-for alpha${SYMBOL} 236 tmux wait-for beta${SYMBOL} 237 # seppuku 238 tmux kill-session 239 EOF 240 chmod +x "${HARNESS_DIR}/quit" 241 242 ################################################################################ 243 # Connect alpha node to beta 244 ################################################################################ 245 echo "connect alpha node to beta" 246 247 tmux send-keys -t $SESSION:2 "./beta addnode 127.0.0.1:${ALPHA_LISTEN_PORT} add${DONE}" C-m\; ${WAIT} 248 # Give the nodes time to sync. 249 sleep 2 250 251 tmux send-keys -t $SESSION:2 "./beta getnetworkinfo${DONE}" C-m\; ${WAIT} 252 253 ################################################################################ 254 # Have to generate a block before calling upgradetohd 255 ################################################################################ 256 echo "Generating the genesis block" 257 258 tmux send-keys -t $SESSION:2 "./alpha generatetoaddress 1 ${ALPHA_MINING_ADDR}${DONE}" C-m\; ${WAIT} 259 sleep 2 260 261 ################################ 262 # Create HD wallets from seeds # 263 ################################ 264 265 # https://docs.dash.org/projects/core/en/stable/docs/api/remote-procedure-calls-wallet.html#createwallet 266 # https://docs.dash.org/projects/core/en/stable/docs/api/remote-procedure-calls-wallet.html#upgradetohd 267 268 ################################################################################ 269 # Create unnamed wallet on node alpha 270 ################################################################################ 271 echo "Creating alpha wallet - encrypted HD" 272 273 tmux send-keys -t $SESSION:2 "./alpha createwallet \"\" false true \"${WALLET_PASSWORD}\" ${DONE}" C-m\; ${WAIT} 274 sleep 2 275 276 tmux send-keys -t $SESSION:2 "./alpha upgradetohd \"${ALPHA_SEED_MNEMONIC}\" \"\" \"${WALLET_PASSWORD}\"${DONE}" C-m\; ${WAIT} 277 sleep 3 278 279 ################################################################################ 280 # Create unnamed wallet on node beta 281 ################################################################################ 282 echo "Creating beta wallet - encrypted HD" 283 284 tmux send-keys -t $SESSION:2 "./beta createwallet \"\" false true \"${WALLET_PASSWORD}\" ${DONE}" C-m\; ${WAIT} 285 sleep 2 286 287 tmux send-keys -t $SESSION:2 "./beta upgradetohd \"${BETA_SEED_MNEMONIC}\" \"\" ${WALLET_PASSWORD}${DONE}" C-m\; ${WAIT} 288 sleep 3 289 290 ################################################################################ 291 # Create the gamma wallet 292 ################################################################################ 293 echo "Creating gamma wallet - encrypted HD" 294 295 tmux send-keys -t $SESSION:2 "./alpha createwallet \"gamma\" false true \"${WALLET_PASSWORD}\" ${DONE}" C-m\; ${WAIT} 296 sleep 2 297 298 tmux send-keys -t $SESSION:2 "./alpha -rpcwallet=\"gamma\" upgradetohd \"${GAMMA_SEED_MNEMONIC}\" \"\" \"${WALLET_PASSWORD}\"${DONE}" C-m\; ${WAIT} 299 sleep 3 300 301 ################################################################################ 302 # Create the delta wallet 303 ################################################################################ 304 echo "Creating delta wallet - encrypted HD" 305 306 tmux send-keys -t $SESSION:2 "./beta createwallet \"delta\" false true \"${WALLET_PASSWORD}\" ${DONE}" C-m\; ${WAIT} 307 sleep 3 308 309 tmux send-keys -t $SESSION:2 "./beta -rpcwallet=\"delta\" upgradetohd \"${DELTA_SEED_MNEMONIC}\" \"\" \"${WALLET_PASSWORD}\"${DONE}" C-m\; ${WAIT} 310 sleep 3 311 312 ################################################################################ 313 # Mine alpha 314 ################################################################################ 315 echo "Generating 200 blocks for alpha" 316 317 tmux send-keys -t $SESSION:2 "./alpha generatetoaddress 100 ${ALPHA_MINING_ADDR}${DONE}" C-m\; ${WAIT} 318 sleep 1 319 tmux send-keys -t $SESSION:2 "./alpha generatetoaddress 100 ${ALPHA_MINING_ADDR}${DONE}" C-m\; ${WAIT} 320 sleep 1 321 322 ################################################################################ 323 # Send beta, gamma and delta some coin 324 ################################################################################ 325 echo "Funding beta, gamma & delta wallets from alpha's block subsidy. 500 tDASH/block." 326 327 tmux send-keys -t $SESSION:2 "./alpha walletpassphrase \"${WALLET_PASSWORD}\" 100000000${i}${DONE}" C-m\; ${WAIT} 328 329 # Send some dash to beta, gamma and delta wallets, mining a few more blocks. 330 echo "Sending 8777 DASH each to beta, gamma and delta in 8 blocks" 331 for i in 1000 1800 500 700 100 1500 300 2500 200 100 7 7 7 7 7 7 7 3 3 3 3 3 3 2 2 2 2 2 1 332 do 333 tmux send-keys -t $SESSION:2 "./alpha sendtoaddress ${BETA_MINING_ADDR} ${i}${DONE}" C-m\; ${WAIT} 334 tmux send-keys -t $SESSION:2 "./alpha sendtoaddress ${GAMMA_ADDRESS} ${i}${DONE}" C-m\; ${WAIT} 335 tmux send-keys -t $SESSION:2 "./alpha sendtoaddress ${DELTA_ADDRESS} ${i}${DONE}" C-m\; ${WAIT} 336 # 337 tmux send-keys -t $SESSION:2 "./mine-beta 1${DONE}" C-m\; ${WAIT} 338 done 339 340 ################################################################################ 341 # Setup watch background miner -- if required 342 ################################################################################ 343 if [ -z "$NOMINER" ] ; then 344 tmux new-window -t $SESSION:3 -n "miner" $SHELL 345 tmux send-keys -t $SESSION:3 "cd ${HARNESS_DIR}" C-m 346 tmux send-keys -t $SESSION:3 "watch -n 15 ./mine-alpha 1" C-m 347 fi 348 349 set +x 350 351 echo "----------" 352 echo "SETUP DONE" 353 echo "----------" 354 355 # Re-enable history 356 tmux send-keys -t $SESSION:2 "set -o history" C-m 357 358 tmux select-window -t $SESSION:2 359 tmux attach-session -t $SESSION