Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dex/testing: add script for two-wallet testing #2535

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dex/testing/walletpair/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# walletpair.sh

This is a tmux script for a 2-wallet pair that developers can use to perform manual testing on mainnet and testnet. The script aims to solve a number of problems.

- Testing by self-trading with a single wallet has historically failed to detect some bugs.
- Keeping your personal mainnet wallet on a release branch is advisable, so we don't want to use our primary wallet for testing.
- For testing on mainnet, we want to use a testing server that has ultra-low lot limits and bond size, and we only want to run the nodes/markets that we're interested in testing. It's not usually a server suitable for public use.

**walletpair.sh** will create two dexc instances, and open browser windows to
them. Wallet data is persisted through restarts, so you can send mainnet funds
without risk of loss. That said, this is for testing, so only send what you can
lose in case of massive catastrophe.

Use `--testnet` flag to run on testnet.
69 changes: 69 additions & 0 deletions dex/testing/walletpair/walletpair.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

export SHELL=$(which bash)
SESSION="walletpair"
PAIR_ROOT=~/dextest/walletpair
CLIENT_1_DIR="${PAIR_ROOT}/dexc1"
CLIENT_1_ADDR="127.0.0.4:5760"
CLIENT_2_DIR="${PAIR_ROOT}/dexc2"
CLIENT_2_ADDR="127.0.0.5:5761"
HARNESS_DIR="${PAIR_ROOT}/harness-ctl"
DEXC_DIR=$(realpath ../../../client/cmd/dexc)
DEXC="${DEXC_DIR}/dexc"

cd "${DEXC_DIR}"
go build
cd -

mkdir -p "${HARNESS_DIR}"
mkdir -p "${CLIENT_1_DIR}"
mkdir -p "${CLIENT_2_DIR}"

CLIENT_1_CONF="${CLIENT_1_DIR}/dexc.conf"
rm -f "${CLIENT_1_CONF}"
cat > "${CLIENT_1_CONF}" <<EOF
webaddr=${CLIENT_1_ADDR}
experimental=true
EOF

CLIENT_2_CONF="${CLIENT_2_DIR}/dexc.conf"
rm -f "$CLIENT_2_CONF"
cat > "$CLIENT_2_CONF" <<EOF
webaddr=${CLIENT_2_ADDR}
experimental=true
EOF

QUIT_FILE="${HARNESS_DIR}/quit"
rm -f "${QUIT_FILE}"
cat > "${QUIT_FILE}" <<EOF
#!/usr/bin/env bash
tmux send-keys -t $SESSION:1 C-c
tmux send-keys -t $SESSION:2 C-c
sleep 1
tmux kill-session
EOF
chmod +x "${QUIT_FILE}"

echo "xdg-open http://${CLIENT_1_ADDR} > /dev/null 2>&1" > "${HARNESS_DIR}/dexc1"
chmod +x "${HARNESS_DIR}/dexc1"

echo "xdg-open http://${CLIENT_2_ADDR} > /dev/null 2>&1" > "${HARNESS_DIR}/dexc2"
chmod +x "${HARNESS_DIR}/dexc2"

tmux new-session -d -s $SESSION $SHELL
tmux rename-window -t $SESSION:0 'harness-ctl'

tmux new-window -t $SESSION:1 -n 'dexc1' $SHELL
tmux send-keys -t $SESSION:1 "cd ${PAIR_ROOT}/dexc1" C-m
tmux send-keys -t $SESSION:1 "${DEXC} --appdata=${CLIENT_1_DIR} ${@}" C-m

tmux new-window -t $SESSION:2 -n 'dexc1' $SHELL
tmux send-keys -t $SESSION:2 "cd ${PAIR_ROOT}/dexc1" C-m
tmux send-keys -t $SESSION:2 "${DEXC} --appdata=${CLIENT_2_DIR} ${@}" C-m

tmux select-window -t $SESSION:0
sleep 1
tmux send-keys -t $SESSION:0 "cd ${HARNESS_DIR}; tmux wait-for -S walletpair" C-m\; wait-for walletpair
tmux send-keys -t $SESSION:0 "./dexc1; tmux wait-for -S walletpair" C-m\; wait-for walletpair
tmux send-keys -t $SESSION:0 "./dexc2" C-m
tmux attach-session -t $SESSION
Loading