Skip to content

Commit

Permalink
harness: Add a new wallet-less monero-wallet-rpc server instance
Browse files Browse the repository at this point in the history
	New monero-wallet-rpc server with no attached wallet. This is
 	for programmatically creating/generating and using a new wallet.

	The wallet will be generated in "own" dir but can be named what-
	ever you need: "alice", "Bob", etc.
  • Loading branch information
xorzero777 authored and JoeGruffins committed Aug 28, 2024
1 parent 60550d9 commit 6ccec62
Showing 1 changed file with 52 additions and 26 deletions.
78 changes: 52 additions & 26 deletions dex/testing/xmr/harness.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
# Tmux script that sets up an XMR regtest harness with one node 'alpha' and 3
# wallets 'fred', 'bill' & 'charlie'. Charlie also has a View-Only sibling.
#
# There is now a new monero-wallet-rpc server with no attached wallet. This is
# for programmatically creating and using a new wallet. The wallet will be gen-
# erated in "own" directory but can be named whatever you need - maybe "alice",
# "Bob" or "carol"

################################################################################
# Development
Expand Down Expand Up @@ -38,6 +43,7 @@ export FRED_WALLET_RPC_PORT="28084"
export BILL_WALLET_RPC_PORT="28184"
export CHARLIE_WALLET_RPC_PORT="28284"
export CHARLIE_VIEW_WALLET_RPC_PORT="28384"
export OWN_WALLET_RPC_PORT="28484"

# wallet seeds, passwords & primary addresses
FRED_WALLET_SEED="vibrate fever timber cuffs hunter terminal dilute losing light because nabbing slower royal brunt gnaw vats fishing tipsy toxic vague oscar fudge mice nasty light"
Expand All @@ -63,6 +69,7 @@ FRED_WALLET_DIR="${NODES_ROOT}/wallets/fred"
BILL_WALLET_DIR="${NODES_ROOT}/wallets/bill"
CHARLIE_WALLET_DIR="${NODES_ROOT}/wallets/charlie"
CHARLIE_VIEW_WALLET_DIR="${NODES_ROOT}/wallets/charlie_view"
OWN_WALLET_DIR="${NODES_ROOT}/wallets/own"
HARNESS_CTL_DIR="${NODES_ROOT}/harness-ctl"
ALPHA_DATA_DIR="${NODES_ROOT}/alpha"
ALPHA_REGTEST_CFG="${ALPHA_DATA_DIR}/alpha.conf"
Expand All @@ -74,14 +81,15 @@ mkdir -p "${FRED_WALLET_DIR}"
mkdir -p "${BILL_WALLET_DIR}"
mkdir -p "${CHARLIE_WALLET_DIR}"
mkdir -p "${CHARLIE_VIEW_WALLET_DIR}"
mkdir -p "${OWN_WALLET_DIR}"
mkdir -p "${HARNESS_CTL_DIR}"
mkdir -p "${ALPHA_DATA_DIR}"
touch "${ALPHA_REGTEST_CFG}" # currently empty
touch "${ALPHA_REGTEST_CFG}"

# make available from the harness-ctl dir
cp monero_functions ${HARNESS_CTL_DIR}
# make available from the harness-ctl dir
cp monero_functions ${HARNESS_CTL_DIR}

# Background watch mining in window ??? by default:
# Background watch mining in window 7 by default:
# 'export NOMINER="1"' or uncomment this line to disable
#NOMINER="1"

Expand Down Expand Up @@ -111,7 +119,7 @@ EOF
chmod +x "${HARNESS_CTL_DIR}/alpha_sendrawtransaction"
# -----------------------------------------------------------------------------

# Get one or more transactions from monerod
# Get one or more transaction details from monerod
# inputs:
# - txids as hex string - "hash1,hash2,hash3,..."
# - decode_as_json - defaults to false
Expand Down Expand Up @@ -372,6 +380,7 @@ cat > "${HARNESS_CTL_DIR}/wallets" <<EOF
env | grep FRED
env | grep BILL
env | grep CHARLIE
env | grep OWN
EOF
chmod +x "${HARNESS_CTL_DIR}/wallets"
# -----------------------------------------------------------------------------
Expand All @@ -381,9 +390,11 @@ cat > "${NODES_ROOT}/harness-ctl/quit" <<EOF
#!/usr/bin/env bash
if [ -z "$NOMINER" ]
then
tmux send-keys -t $SESSION:6 C-c
tmux send-keys -t $SESSION:7 C-c
fi
sleep 0.05
tmux send-keys -t $SESSION:6 C-c
sleep 0.05
tmux send-keys -t $SESSION:5 C-c
sleep 0.05
tmux send-keys -t $SESSION:4 C-c
Expand Down Expand Up @@ -412,10 +423,17 @@ chmod +x "${HARNESS_CTL_DIR}/help"
################################################################################
# Configuration Files
################################################################################
echo "Writing node config files"

echo "empty config file in ${ALPHA_DATA_DIR}"
echo "TODO: populate; for now we have no passwords and the ports are not random"
echo "Writing alpha node config file ${ALPHA_REGTEST_CFG}"

cat > "${ALPHA_REGTEST_CFG}" <<EOF
regtest=1
offline=1
data-dir=${ALPHA_DATA_DIR}
rpc-bind-ip=127.0.0.1
rpc-bind-port=${ALPHA_NODE_RPC_PORT}
fixed-difficulty=1
log-level=1
EOF

################################################################################
# Start tmux harness
Expand All @@ -434,21 +452,13 @@ tmux send-keys -t $SESSION:0 "cd ${HARNESS_CTL_DIR}" C-m
################################################################################

# start alpha node - window 1
echo "starting singlenode alpha"
echo "starting singlenode alpha with config-file: ${ALPHA_REGTEST_CFG}"

tmux new-window -t $SESSION:1 -n 'alpha' $SHELL
tmux send-keys -t $SESSION:1 "set +o history" C-m
tmux send-keys -t $SESSION:1 "cd ${ALPHA_DATA_DIR}" C-m

tmux send-keys -t $SESSION:1 "monerod \
--regtest \
--offline \
--data-dir ${ALPHA_DATA_DIR} \
--config-file ${ALPHA_REGTEST_CFG} \
--rpc-bind-ip 127.0.0.1 \
--rpc-bind-port ${ALPHA_NODE_RPC_PORT} \
--fixed-difficulty 1 \
--log-level 2; tmux wait-for -S alphaxmr" C-m
tmux send-keys -t $SESSION:1 "monerod --config-file=${ALPHA_REGTEST_CFG}; tmux wait-for -S alphaxmr" C-m

sleep 5

Expand All @@ -474,7 +484,7 @@ tmux send-keys -t $SESSION:2 "monero-wallet-rpc \

sleep 2

# Start the second wallet client - window 3
# Start the second wallet server - window 3
echo "starting bill wallet server"

tmux new-window -t $SESSION:3 -n 'bill' $SHELL
Expand All @@ -491,7 +501,7 @@ tmux send-keys -t $SESSION:3 "monero-wallet-rpc \
sleep 2

# Start the third wallet server - window 4
echo "starting bill wallet client"
echo "starting bill wallet server"

tmux new-window -t $SESSION:4 -n 'charlie' $SHELL
tmux send-keys -t $SESSION:4 "set +o history" C-m
Expand All @@ -507,7 +517,7 @@ tmux send-keys -t $SESSION:4 "monero-wallet-rpc \
sleep 2

# Start the fourth wallet server - window 5
echo "starting charlie_view wallet client"
echo "starting charlie_view wallet server"

tmux new-window -t $SESSION:5 -n 'charlie_view' $SHELL
tmux send-keys -t $SESSION:5 "set +o history" C-m
Expand All @@ -522,6 +532,22 @@ tmux send-keys -t $SESSION:5 "monero-wallet-rpc \

sleep 2

# Start the fifth wallet server - window 5
echo "starting Own wallet server"

tmux new-window -t $SESSION:6 -n 'own' $SHELL
tmux send-keys -t $SESSION:6 "set +o history" C-m
tmux send-keys -t $SESSION:6 "cd ${OWN_WALLET_DIR}" C-m

tmux send-keys -t $SESSION:6 "monero-wallet-rpc \
--rpc-bind-ip 127.0.0.1 \
--rpc-bind-port ${OWN_WALLET_RPC_PORT} \
--wallet-dir ${OWN_WALLET_DIR} \
--disable-rpc-login \
--allow-mismatched-daemon-version; tmux wait-for -S ownxmr" C-m

sleep 2

################################################################################
# Create the wallets
################################################################################
Expand Down Expand Up @@ -601,9 +627,9 @@ sleep 3
# Watch miner
if [ -z "$NOMINER" ]
then
tmux new-window -t $SESSION:6 -n "miner" $SHELL
tmux send-keys -t $SESSION:6 "cd ${NODES_ROOT}/harness-ctl" C-m
tmux send-keys -t $SESSION:6 "watch -n 15 ./mine-to-bill 1" C-m
tmux new-window -t $SESSION:7 -n "miner" $SHELL
tmux send-keys -t $SESSION:7 "cd ${NODES_ROOT}/harness-ctl" C-m
tmux send-keys -t $SESSION:7 "watch -n 15 ./mine-to-bill 1" C-m
fi

# Re-enable history and attach to the control session.
Expand Down

0 comments on commit 6ccec62

Please sign in to comment.