-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_tests.sh
executable file
·100 lines (80 loc) · 2.82 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
export NVM_DIR="${XDG_CONFIG_HOME:-${HOME}/.nvm}"
if [ ! -f "$NVM_DIR/nvm.sh" ]; then
echo "Please install nvm before running this script as Shardeum requires a specific version of node and npm."
exit 1
fi
# Load nvm
source "$NVM_DIR/nvm.sh"
# Define your local repository path
REPO_PATH="${1:-/path/to/your/local/shardeum/repo}"
REPO_NAME="shardeum"
# Check if the directory exists
if [ -d "$REPO_PATH" ]; then
echo "Repository path exists: $REPO_PATH"
pushd "$REPO_PATH"
else
echo "No existing Shardeum installation found, cloning the repository..."
if [ ! -d .test ]; then
mkdir .test
fi
pushd .test
if [ -d $REPO_NAME ]; then
rm -rf $REPO_NAME
fi
git clone https://github.com/shardeum/shardeum.git || { echo "Failed to clone shardeum repository"; exit 1; }
pushd "$REPO_NAME"
fi
# Check Node.js version
if ! node --version | grep -q "v18"; then
echo "Node.js v18 not found, installing and selecting via nvm..."
nvm install 18.16.1 && nvm use 18.16.1 || { echo "Failed to install/select Node.js v18.16.1"; exit 1; }
fi
# Ensure Rust is installed
if ! command -v rustc &> /dev/null; then
echo "Rust missing, installing..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup toolchain install 1.74.1
rustup default 1.74.1
else
echo -n "Rust detected, version: "
rustc --version
fi
# Install build essentials based on OS
install_linux() {
sudo apt-get update && sudo apt-get install -y build-essential
}
install_macos() {
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed, please install it before running this script."
exit 1
fi
brew update
brew install gcc
}
case "$OSTYPE" in
linux-gnu*) install_linux ;;
darwin*) install_macos ;;
*) echo "Unsupported OS: $OSTYPE"; exit 1 ;;
esac
# Install project dependencies and apply debug patch
echo "Installing Shardeum project dependencies..."
npm ci
git apply debug-10-nodes.patch || { echo "Failed to apply patch"; exit 1; }
# Build the project
npm run prepare
# Install shardus and archiver globally if not already installed
command -v shardus &> /dev/null || npm install -g shardus @shardus/archiver
# Start the shardus network
shardus start 10 || { echo "Failed to start shardus network"; exit 1; }
echo "Started 10 nodes with shardus"
# Wait for archivers in the network to initialize
echo "Waiting for 4 minutes to allow the network to stabilize..."
sleep 240
# Return to the original directory using popd
popd || { echo "Failed to return to parent directory"; exit 1; }
npm run test || { echo "Test suite failed"; exit 1; }
echo "Test suite completed."
# Stop the shardus network
shardus stop & shardus clean & rm -rf .test || { echo "Failed to stop shardus network"; exit 1; }