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') }} key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-mod restore-keys: ${{ runner.os }}-go-mod
- name: Install brew dependencies
run: brew install coreutils
- name: Run build - name: Run build
run: make build run: make build

View File

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

View File

@@ -2,17 +2,43 @@
### Requirements ### Requirements
- go 1.19+ (see [build instructions](./build.md) to download Go.) #### Operating System
- ganache (can be installed with `npm install --location=global ganache`) 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. #### Installed Dependencies for Building/Testing
Using nvm is [the suggested way](https://github.com/nvm-sh/nvm#installing-and-updating) - go 1.19+ (see [build instructions](./build.md) to download Go.)
to install npm. If you install npm using a package manager like snap, ensure the install - node/npm (to install ganache, see suggestions after list)
prefix (`npm config get prefix`) is a directory that you have write access to without sudo. - ganache (can be installed with `npm install --location=global ganache`)
You can change the directory with the command `npm config set prefix ~/.npm-packages`. See - jq, curl, bzip2, realpath
[this document](https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md)
[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 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 ### Set up development environment
Note: the `scripts/install-monero-linux.sh` script will download the monero binaries needed for you. 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 To avoid confusion, delete any data directories from old runs of `swapd` that used
the flags `--dev-xmrtaker` or `--dev-xmrmaker`: the flags `--dev-xmrtaker` or `--dev-xmrmaker`:
```bash ```bash
rm -rf /tmp/xmrtaker-* /tmp/xmrmaker-* rm -rf "${TMPDIR:-/tmp}"/xmr[mt]aker-*
``` ```
### Build the Executables ### 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 the file ..., or if you have `jq` installed (available via `sudo apt install jq`), you can set a
variable like this: variable like this:
```bash ```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: 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 # Generate the UTContract.sol Go bindings into a file named ut_contract_test.go of the
# parent directory for use by unit tests. # parent directory for use by unit tests.
# Use the contract's directory (where this script is) as the current working directory: # 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" 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 cd "${PROJECT_ROOT}" || exit 1
# Make sure no one is souring the script before we change GOBIN # 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 # This script can be handy to kill test processes launched manually
# for debugging or still hanging around for other reasons. # for debugging or still hanging around for other reasons.
pkill --echo --uid "${UID}" --full '/monerod .* --regtest ' pkill_cmd=(pkill --echo --uid "${UID}" --full)
pkill --echo --uid "${UID}" --full '/ganache.* --deterministic ' if [[ "$(uname)" == 'Darwin' ]]; then
pkill --echo --uid "${UID}" --full '/relayer' 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 # 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! # 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 # If swapd instances were killed, give the monero-wallet-rpc instances
# some time to shutdown. # some time to shutdown.
sleep 4 # Give time for wallet 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 # Take note of monero-wallet-rpc instances being killed here if the instances
# were started by swapd # 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 # 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. # 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: # 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 cd "${PROJECT_ROOT}" || exit 1
ABIGEN="$(go env GOPATH)/bin/abigen" 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 # 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. # or if the existing version does not match go-ethereum version in go.mod.
ABIGEN="$(go env GOPATH)/bin/abigen" 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)" VERSION="$(grep --max-count=1 "github.com/ethereum/go-ethereum" "${GO_MOD}" | cut '--delimiter= ' --fields=2)"
if [[ -z "${VERSION}" ]]; then 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 # 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. # 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 # 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 # deleting the monero-bin symlink or the version specific folder that it links to. This
# script changes directories and should be executed, not sourced. # 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}" cd "${PROJECT_ROOT}"
if [[ -d "monero-bin" ]]; then if [[ -d "monero-bin" ]]; then
@@ -16,7 +31,7 @@ fi
set -e 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 tar xjvf monero.tar.bz2
# Give the architecture and version specific release dir a fixed "monero-bin" symlink # 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 cd "${PROJECT_ROOT}" || exit 1
./scripts/build.sh || 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 cd "${PROJECT_ROOT}" || exit 1
source "scripts/testlib.sh" 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 # If you need to debug unit tests, this script will turn up the necessary
# daemons without running the tests. Warning: It will terminate any # daemons without running the tests. Warning: It will terminate any
# currently running test daemons. # 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 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) log_level=info # change to "debug" for more logs
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'
# check balance ./bin/swapd --env stagenet \
curl http://localhost:18083/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_accounts","params":{}}' -H 'Content-Type: application/json' "--log-level=${log_level}" \
"--ethereum-endpoint=${ETHEREUM_ENDPOINT}" \
&>swapd.log &
# start mining (if synced) echo "swapd start with logs in swapd.log"
# 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'

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 # 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: # on the command line if you are using bash. Here is an example:
# #
@@ -22,7 +22,7 @@
MONEROD_PORT=18081 MONEROD_PORT=18081
GANACHE_PORT=8545 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" MONERO_BIN_DIR="${PROJECT_ROOT}/monero-bin"
# return 0 (true) if the passed TCP port is open, otherwise non-zero (false) # 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() { check-set-swap-test-data-dir() {
if [[ -z "${SWAP_TEST_DATA_DIR}" ]]; then 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}" echo "Swap test data dir is ${SWAP_TEST_DATA_DIR}"
else else
mkdir -p "${SWAP_TEST_DATA_DIR}" # make sure it exists if the variable was already set 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 if [[ -x "${ganache_exec}" ]]; then
return 0 # ganache already installed return 0 # ganache already installed
fi fi
echo "installing ganache" echo "installing ganache in ${npm_install_dir}/bin"
if [[ -d "${npm_install_dir}/bin" ]] && [[ ! -w "${npm_install_dir}/bin" ]]; then if [[ -d "${npm_install_dir}/bin" ]] && [[ ! -w "${npm_install_dir}/bin" ]]; then
echo "${npm_install_dir}[/bin] is not writable" echo "${npm_install_dir}[/bin] is not writable"
echo "You can use 'npm config set prefix DIRNAME' to pick a different install directory" echo "You can use 'npm config set prefix DIRNAME' to pick a different install directory"
return 1 return 1
fi fi
npm install --location=global ganache npm install --global ganache
} }
start-ganache() { start-ganache() {
@@ -165,7 +165,11 @@ start-ganache() {
# shellcheck disable=SC2155 # shellcheck disable=SC2155
local ganache_exec="$(npm config get prefix)/bin/ganache" local ganache_exec="$(npm config get prefix)/bin/ganache"
check-set-swap-test-data-dir 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 \ "${ganache_exec}" --deterministic \
--accounts=50 \ --accounts=50 \
--miner.blockTime=1 \ --miner.blockTime=1 \