decred.org/dcrdex@v1.0.5/dex/testing/firo/harness.sh (about)

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