Skip to content

Commit 96bd35c

Browse files
committed
test: add script to test in local
1 parent be30255 commit 96bd35c

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

Diff for: scripts/run-gnoa-test.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
set -x # Debug mode enable
6+
7+
if [[ -z "$1" ]]; then
8+
echo "❌ Error: Enter the path to the folder where the test will be performed!"
9+
echo "Usage: $0 <folder path>"
10+
exit 1
11+
fi
12+
13+
FOLDER="$1"
14+
15+
# Check if folder exists
16+
if [[ ! -d "$FOLDER" ]]; then
17+
echo "❌ Error: Test folder $FOLDER does not exist!"
18+
exit 1
19+
fi
20+
21+
# gnoA test run
22+
echo "🚀 Running gnoA tests in $FOLDER..."
23+
cd "$FOLDER"
24+
25+
TESTFILES=($(ls *_test.gnoA 2>/dev/null || true))
26+
27+
if [[ ${#TESTFILES[@]} -eq 0 ]]; then
28+
echo "⚠️ Warning: No _test.gnoA files found in $FOLDER. Skipping..."
29+
exit 0
30+
fi
31+
32+
FAILED_TESTS=()
33+
TMP_PATH="/tmp"
34+
35+
for testfile in "${TESTFILES[@]}"; do
36+
base="${testfile%.gnoA}"
37+
38+
mv "$testfile" "$base.gno"
39+
40+
# Unit test 수행
41+
if ! gno test "$FOLDER" -root-dir "$GNO_PATH" -v 2>&1 | tee "${TMP_PATH}/test_output.log"; then
42+
FAILED_TESTS+=("$base.gno test failed!")
43+
fi
44+
45+
mv "$base.gno" "$testfile"
46+
done
47+
48+
cd -
49+
50+
if [[ ${#FAILED_TESTS[@]} -ne 0 ]]; then
51+
echo ""
52+
echo "❌ Failed gnoA test list:"
53+
for fail in "${FAILED_TESTS[@]}"; do
54+
echo " - $fail"
55+
done
56+
exit 1
57+
else
58+
echo "✅ All gnoA tests completed successfully!"
59+
exit 0
60+
fi

Diff for: scripts/run-test.sh

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
3+
set -e # Exit immediately if a command exits with a non-zero status.
4+
set -o pipefail # Catch errors in pipelines.
5+
set -x # Print commands and their arguments as they are executed.
6+
7+
# Define paths relative to project root
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10+
TMP_PATH="$PROJECT_ROOT/tmp"
11+
GNO_PATH="$TMP_PATH/gno"
12+
GNOSWAP_PATH="$TMP_PATH/gnoswap"
13+
14+
# Matrix configurations
15+
TEST_KEYS=("p/uint256" "p/int256" "p/gnsmath" "r/common" "r/gns" "r/gnft" "r/gov/xgns"
16+
"r/emission" "r/protocol_fee" "r/pool" "r/position" "r/router" "r/staker"
17+
"r/community_pool" "r/gov/staker" "r/gov/governance" "r/launchpad")
18+
19+
TEST_VALUES=(
20+
"gno/examples/gno.land/p/gnoswap/uint256"
21+
"gno/examples/gno.land/p/gnoswap/int256"
22+
"gno/examples/gno.land/p/gnoswap/gnsmath"
23+
"gno/examples/gno.land/r/gnoswap/v1/common"
24+
"gno/examples/gno.land/r/gnoswap/v1/gns"
25+
"gno/examples/gno.land/r/gnoswap/v1/gnft"
26+
"gno/examples/gno.land/r/gnoswap/v1/gov/xgns"
27+
"gno/examples/gno.land/r/gnoswap/v1/emission"
28+
"gno/examples/gno.land/r/gnoswap/v1/protocol_fee"
29+
"gno/examples/gno.land/r/gnoswap/v1/pool"
30+
"gno/examples/gno.land/r/gnoswap/v1/position"
31+
"gno/examples/gno.land/r/gnoswap/v1/router"
32+
"gno/examples/gno.land/r/gnoswap/v1/staker"
33+
"gno/examples/gno.land/r/gnoswap/v1/community_pool"
34+
"gno/examples/gno.land/r/gnoswap/v1/gov/staker"
35+
"gno/examples/gno.land/r/gnoswap/v1/gov/governance"
36+
"gno/examples/gno.land/r/gnoswap/v1/launchpad"
37+
)
38+
39+
# Ensure tmp directory exists
40+
mkdir -p "$TMP_PATH"
41+
42+
# 1. Clone gnoswap repository into tmp/
43+
echo "✅ Cloning gnoswap repository into tmp/gnoswap..."
44+
git clone https://github.com/gnoswap-labs/gnoswap.git "$GNOSWAP_PATH"
45+
46+
# 2. Clone gno repository into tmp/
47+
echo "✅ Cloning gno repository into tmp/gno..."
48+
git clone --depth 1 --branch master https://github.com/gnolang/gno.git "$GNO_PATH"
49+
50+
# 3. Install Go if not available
51+
echo "✅ Checking Go installation..."
52+
if ! command -v go &> /dev/null; then
53+
echo "Go is not installed. Installing Go..."
54+
curl -OL https://golang.org/dl/go1.22.linux-amd64.tar.gz
55+
sudo tar -C /usr/local -xzf go1.22.linux-amd64.tar.gz
56+
fi
57+
58+
# Use the system's default GOROOT
59+
export GOPATH=$HOME/go
60+
export PATH=$GOPATH/bin:$PATH
61+
echo "✅ Go Version: $(go version)"
62+
63+
# 4. Modify `gnovm`
64+
echo "✅ Configuring gnovm..."
65+
if [[ "$OSTYPE" == "darwin"* ]]; then
66+
sed -i '' 's/ctx.Timestamp += (count \* 5)/ctx.Timestamp += (count \* 2)/g' "$GNO_PATH/gnovm/tests/stdlibs/std/std.go"
67+
else
68+
sed -i 's/ctx.Timestamp += (count \* 5)/ctx.Timestamp += (count \* 2)/g' "$GNO_PATH/gnovm/tests/stdlibs/std/std.go"
69+
fi
70+
71+
# 5. Build & install `gno` CLI
72+
echo "✅ Installing gno CLI..."
73+
cd "$GNO_PATH"
74+
make install.gno
75+
cd "$PROJECT_ROOT"
76+
77+
# 6. Install Python if not available
78+
echo "✅ Checking Python installation..."
79+
if ! command -v python3 &> /dev/null; then
80+
sudo apt update && sudo apt install -y python3 python3-pip
81+
fi
82+
python3 --version
83+
84+
# 7. Run setup.py (install to tmp/)
85+
echo "✅ Running setup.py in gnoswap..."
86+
cd "$GNOSWAP_PATH"
87+
python3 setup.py -w "$TMP_PATH"
88+
cd "$PROJECT_ROOT"
89+
90+
echo "📂 Searching for test files..."
91+
find "$TMP_PATH/gno/examples/gno.land/p/gnoswap" -name "*_test.gno" || echo "❌ No _test.gno files found!"
92+
find "$TMP_PATH/gno/examples/gno.land/r/gnoswap/v1" -name "*_test.gno" || echo "❌ No _test.gno files found!"
93+
find "$TMP_PATH/gno/examples/gno.land/p/gnoswap" -name "*_test.gnoA" || echo "❌ No _test.gnoA files found!"
94+
find "$TMP_PATH/gno/examples/gno.land/r/gnoswap/v1" -name "*_test.gnoA" || echo "❌ No _test.gnoA files found!"
95+
96+
# 8. Run tests for each contract in the matrix
97+
echo "🔍 TEST_VALUES content:"
98+
99+
set +x
100+
101+
FAILED_TESTS=()
102+
LENGTH=${#TEST_KEYS[@]}
103+
for ((i=0; i<LENGTH; i++)); do
104+
FOLDER="$TMP_PATH/${TEST_VALUES[$i]}"
105+
echo "🚀 Running tests for $FOLDER..."
106+
107+
# Check if folder exists
108+
if [[ ! -d "$FOLDER" ]]; then
109+
echo "❌ Error: Test folder $FOLDER does not exist! Skipping..."
110+
FAILED_TESTS+=("$FOLDER")
111+
continue
112+
fi
113+
114+
# 1) Run unit tests
115+
if ! gno test "$FOLDER" -root-dir "$GNO_PATH" -v 2>&1 | tee ${TMP_PATH}/test_output.log; then
116+
FAILED_TESTS+=("$FOLDER")
117+
fi
118+
119+
# 2) Remove all *_test.gno except _helper_test.gno
120+
find "$FOLDER" -type f -name "*_test.gno" ! -name "_helper_test.gno" -exec rm -f {} +
121+
122+
# 3) Run gnoA tests
123+
cd "$FOLDER"
124+
TESTFILES=($(ls *_test.gnoA 2>/dev/null || true))
125+
126+
for ((j=0; j<${#TESTFILES[@]}; j++)); do
127+
testfile="${TESTFILES[$j]}"
128+
base="${testfile%.gnoA}"
129+
130+
mv "$testfile" "$base.gno"
131+
132+
if ! gno test "$FOLDER" -root-dir "$GNO_PATH" -v 2>&1 | tee ${TMP_PATH}/test_output.log; then
133+
FAILED_TESTS+=("[$FOLDER] file: $base.gno test failed")
134+
fi
135+
136+
mv "$base.gno" "$testfile"
137+
done
138+
139+
cd "$PROJECT_ROOT"
140+
done
141+
142+
echo ""
143+
echo "✅ All tests completed!"
144+
if [[ ${#FAILED_TESTS[@]} -ne 0 ]]; then
145+
echo "❌ Fail test :"
146+
for fail in "${FAILED_TESTS[@]}"; do
147+
echo " - $fail"
148+
done
149+
exit 1
150+
else
151+
echo "✅ All tests are successfully!"
152+
fi

0 commit comments

Comments
 (0)