Modify scripts to run on MacOS (#233)

Updates scripts/docs to support macOS as well as Linux/aarch64 (arm64)
This commit is contained in:
Janaka-Steph
2023-01-16 21:05:35 +01:00
committed by GitHub
parent b78cf06870
commit d13521daef
15 changed files with 121 additions and 54 deletions

View File

@@ -40,5 +40,8 @@ jobs:
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-mod
- name: Install brew dependencies
run: brew install coreutils
- name: Run build
run: make build

View File

@@ -90,9 +90,9 @@ func TestDaemon_DevXMRTaker(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
err := d.make(c) // blocks on RPC server start
require.ErrorIs(t, err, context.Canceled)
wg.Done()
}()
time.Sleep(500 * time.Millisecond) // let the server start
cancel()

View File

@@ -2,17 +2,43 @@
### Requirements
- go 1.19+ (see [build instructions](./build.md) to download Go.)
- ganache (can be installed with `npm install --location=global ganache`)
#### Operating System
The code base is only tested regularly with Ubuntu 22.04 on X86-64, but we would like to
support most 64-bit Linux distributions, macOS, and WSL on Windows both with X86-64
and ARM processors.
These programs and scripts have only been tested on X86-64 Ubuntu 20.04 and 22.04.
Using nvm is [the suggested way](https://github.com/nvm-sh/nvm#installing-and-updating)
to install npm. If you install npm using a package manager like snap, ensure the install
prefix (`npm config get prefix`) is a directory that you have write access to without sudo.
You can change the directory with the command `npm config set prefix ~/.npm-packages`. See
[this document](https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md)
#### Installed Dependencies for Building/Testing
- go 1.19+ (see [build instructions](./build.md) to download Go.)
- node/npm (to install ganache, see suggestions after list)
- ganache (can be installed with `npm install --location=global ganache`)
- jq, curl, bzip2, realpath
[The suggested way](https://github.com/nvm-sh/nvm#installing-and-updating) to install
node/npm is using nvm. If you install npm using a package manager like snap, ensure
the install prefix (`npm config get prefix`) is a directory that you have write
access to without sudo. You can change the directory with this command:
```
npm config set prefix ~/.npm-packages
```
See [this document](https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md)
if you want a more sophisticated setup.
If you are testing, you'll want `jq` installed. `curl` and `bzip2` are normally
preinstalled, but if you are running in a docker container, you might have to
install them.
```bash
sudo apt install curl bzip2 jq
```
#### Macos Notes
On macOS, you'll need to install `realpath` (from the `coreutils` package). If you
are using Homebrew, you can use these commands to install all the needed tools:
```bash
brew install coreutils go jq nvm
nvm install node
npm install --location=global ganache
```
### Set up development environment
Note: the `scripts/install-monero-linux.sh` script will download the monero binaries needed for you.
@@ -30,7 +56,7 @@ Warning: the command below will kill running instances of `ganache`, `monerod`,
To avoid confusion, delete any data directories from old runs of `swapd` that used
the flags `--dev-xmrtaker` or `--dev-xmrmaker`:
```bash
rm -rf /tmp/xmrtaker-* /tmp/xmrmaker-*
rm -rf "${TMPDIR:-/tmp}"/xmr[mt]aker-*
```
### Build the Executables
@@ -65,7 +91,7 @@ Now get the ethereum contract address that Alice deployed to. This can be pulled
the file ..., or if you have `jq` installed (available via `sudo apt install jq`), you can set a
variable like this:
```bash
CONTRACT_ADDR=$(jq -r .ContractAddress /tmp/xmrtaker-*/contract-address.json)
CONTRACT_ADDR=$(jq -r .ContractAddress "${TMPDIR-/tmp}"/xmrtaker-*/contract-address.json)
```
Now start Bob's swapd instance:

View File

@@ -1,9 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash
# Generate the UTContract.sol Go bindings into a file named ut_contract_test.go of the
# parent directory for use by unit tests.
# Use the contract's directory (where this script is) as the current working directory:
cd "$(dirname "$(readlink -f "$0")")"
cd "$(dirname "$(realpath "$0")")"
ABIGEN="$(go env GOPATH)/bin/abigen"

View File

@@ -1,6 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${PROJECT_ROOT}" || exit 1
# Make sure no one is souring the script before we change GOBIN

View File

@@ -1,14 +1,25 @@
#!/bin/bash
#!/usr/bin/env bash
# This script can be handy to kill test processes launched manually
# for debugging or still hanging around for other reasons.
pkill --echo --uid "${UID}" --full '/monerod .* --regtest '
pkill --echo --uid "${UID}" --full '/ganache.* --deterministic '
pkill --echo --uid "${UID}" --full '/relayer'
pkill_cmd=(pkill --echo --uid "${UID}" --full)
if [[ "$(uname)" == 'Darwin' ]]; then
pkill_cmd=(pkill -l -U "${UID}" -f)
fi
echo "Stopping any monerod regest instances"
"${pkill_cmd[@]}" '/monerod .* --regtest '
echo "Stopping any ganache instances"
"${pkill_cmd[@]}" '/ganache '
echo "Stopping any relayer instances"
"${pkill_cmd[@]}" '/relayer '
# If you have monero-wallet-rpc or swapd processes owned by the current user
# that you don't want to kill, don't use this script!
if pkill --echo --uid "${UID}" --full '/swapd '; then
echo "Stopping any swapd instances"
if "${pkill_cmd[@]}" '/swapd '; then
# If swapd instances were killed, give the monero-wallet-rpc instances
# some time to shutdown.
sleep 4 # Give time for wallet to shutdown
@@ -16,7 +27,8 @@ fi
# Take note of monero-wallet-rpc instances being killed here if the instances
# were started by swapd
pkill --echo --uid "${UID}" --full '/monero-wallet-rpc '
echo "Stopping any monero-wallet-rpc instances"
"${pkill_cmd[@]}" '/monero-wallet-rpc '
# Don't use the exit value of the last pkill, since it will exit with
# non-zero value if there were no processes to kill.

View File

@@ -1,7 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash
# Use the project root (one directory above this script) as the current working directory:
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${PROJECT_ROOT}" || exit 1
ABIGEN="$(go env GOPATH)/bin/abigen"

View File

@@ -1,9 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash
# Installs abigen into the user's GOPATH bin directory if it is not there already
# or if the existing version does not match go-ethereum version in go.mod.
ABIGEN="$(go env GOPATH)/bin/abigen"
GO_MOD="$(dirname "$(readlink -f "$0")")/../go.mod"
GO_MOD="$(dirname "$(realpath "$0")")/../go.mod"
VERSION="$(grep --max-count=1 "github.com/ethereum/go-ethereum" "${GO_MOD}" | cut '--delimiter= ' --fields=2)"
if [[ -z "${VERSION}" ]]; then

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Installs golangci-lint (https://golangci-lint.run) into the user's personal GOPATH bin directory if it is
# not there already or if the version does not match the value defined below.

View File

@@ -1,12 +1,27 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Installs the latest version of monero CLI tools. You can force a reinstall or upgrade by
# deleting the monero-bin symlink or the version specific folder that it links to. This
# script changes directories and should be executed, not sourced.
#
arch=linux64
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
os_name="$(uname)"
arch_name="$(uname -m)"
if [[ "${os_name}" == Linux ]] && [[ "${arch_name}" == x86_64 ]]; then
xmr_arch=linux64
elif [[ "${os_name}" == Linux ]] && [[ "${arch_name}" == aarch64 ]]; then
xmr_arch=linuxarm8
elif [[ "${os_name}" == Darwin ]] && [[ "${arch_name}" == x86_64 ]]; then
xmr_arch=mac64
elif [[ "${os_name}" == Darwin ]] && [[ "${arch_name}" == arm64 ]]; then
xmr_arch=macarm8
else
echo "OS=${os_name} on ARCH=${arch_name} is not supported"
exit 1
fi
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${PROJECT_ROOT}"
if [[ -d "monero-bin" ]]; then
@@ -16,7 +31,7 @@ fi
set -e
curl -L "https://downloads.getmonero.org/cli/${arch}" -o monero.tar.bz2
curl -L "https://downloads.getmonero.org/cli/${xmr_arch}" -o monero.tar.bz2
tar xjvf monero.tar.bz2
# Give the architecture and version specific release dir a fixed "monero-bin" symlink

View File

@@ -1,6 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${PROJECT_ROOT}" || exit 1
./scripts/build.sh || exit 1

View File

@@ -1,6 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${PROJECT_ROOT}" || exit 1
source "scripts/testlib.sh"

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# If you need to debug unit tests, this script will turn up the necessary
# daemons without running the tests. Warning: It will terminate any
# currently running test daemons.

33
scripts/setup-stagenet.sh Normal file → Executable file
View File

@@ -1,20 +1,27 @@
#!/bin/bash
#!/usr/bin/env bash
# swapd will call monero-wallet-rpc, so make sure it is installed
bash ./scripts/install-monero-linux.sh
echo "starting monerod..."
./monero-bin/monerod --detach --stagenet --rpc-bind-port 18081 &
sleep 5
#
# Put your own ethereum endpoint below (or define ETHEREUM_ENDPOINT before
# invoking this script. There is no guarantee that the node below will be
# running or should be trusted when you test.
#
ETHEREUM_ENDPOINT="${ETHEREUM_ENDPOINT:-"https://ethereum-goerli-rpc.allthatnode.com"}"
echo "starting monero-wallet-rpc on port 18083..."
nohup ./monero-bin/monero-wallet-rpc --rpc-bind-port 18083 --disable-rpc-login --wallet-dir ./node-keys --stagenet --trusted-daemon &>monero-wallet-cli.log &
#
# swapd has some preconfigured stagenet monerod nodes, but the best option
# is to run and sync your own local node. If you do this, add the flags
# --monerod-host=127.0.0.1 and --monero-port=38081 to swapd.
#
# ./monero-bin/monerod --detach --stagenet &
# open wallet (must have funds)
sleep 5
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"open_wallet","params":{"filename":"stagenet-wallet","password":""}}' -H 'Content-Type: application/json'
log_level=info # change to "debug" for more logs
# check balance
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_accounts","params":{}}' -H 'Content-Type: application/json'
./bin/swapd --env stagenet \
"--log-level=${log_level}" \
"--ethereum-endpoint=${ETHEREUM_ENDPOINT}" \
&>swapd.log &
# start mining (if synced)
# curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":start_mining","params":{"threads_count":1,"do_background_mining":true,"ignore_battery":false}}' -H 'Content-Type: application/json'
echo "swapd start with logs in swapd.log"

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# This script is designed to be sourced by other test scripts, or by the shell
# on the command line if you are using bash. Here is an example:
#
@@ -22,7 +22,7 @@
MONEROD_PORT=18081
GANACHE_PORT=8545
PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
PROJECT_ROOT="$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")"
MONERO_BIN_DIR="${PROJECT_ROOT}/monero-bin"
# return 0 (true) if the passed TCP port is open, otherwise non-zero (false)
@@ -62,7 +62,7 @@ mine-monero-for-swapd() {
check-set-swap-test-data-dir() {
if [[ -z "${SWAP_TEST_DATA_DIR}" ]]; then
SWAP_TEST_DATA_DIR="$(mktemp --tmpdir -d atomic-swap-test-data-XXXXXXXXXX)"
SWAP_TEST_DATA_DIR="$(mktemp -d "${TMPDIR:-/tmp}/atomic-swap-test-data-XXXXXXXXXX")"
echo "Swap test data dir is ${SWAP_TEST_DATA_DIR}"
else
mkdir -p "${SWAP_TEST_DATA_DIR}" # make sure it exists if the variable was already set
@@ -143,13 +143,13 @@ install-ganache() {
if [[ -x "${ganache_exec}" ]]; then
return 0 # ganache already installed
fi
echo "installing ganache"
echo "installing ganache in ${npm_install_dir}/bin"
if [[ -d "${npm_install_dir}/bin" ]] && [[ ! -w "${npm_install_dir}/bin" ]]; then
echo "${npm_install_dir}[/bin] is not writable"
echo "You can use 'npm config set prefix DIRNAME' to pick a different install directory"
return 1
fi
npm install --location=global ganache
npm install --global ganache
}
start-ganache() {
@@ -165,7 +165,11 @@ start-ganache() {
# shellcheck disable=SC2155
local ganache_exec="$(npm config get prefix)/bin/ganache"
check-set-swap-test-data-dir
NODE_OPTIONS="--max_old_space_size=8192" nohup \
local nohup_cmd=nohup
if [[ "$(uname)" == 'Darwin' ]]; then
nohup_cmd=
fi
NODE_OPTIONS="--max_old_space_size=8192" ${nohup_cmd} \
"${ganache_exec}" --deterministic \
--accounts=50 \
--miner.blockTime=1 \