-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): Run nargo test in ci on all packages (#2197)
fixes: #1982 Runs nargo test on all contracts and libraries in ci
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# Utility to get the names of all noir libaries located in ../noir-libs | ||
echo $(ls -d ../noir-libs/*/Nargo.toml | sed -r "s/..\\/noir-libs\\/(.+)\\/Nargo.toml/\\1/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
|
||
# Tests noir contracts, if multiple are provided, then they are testing in parallel, bubbling any testing errors | ||
# | ||
# Usage: | ||
# If testing a single contract: | ||
# ./scripts/test.sh CONTRACT <CONTRACT_NAME> | ||
# If testing multiple contracts: | ||
# ./scripts/test.sh CONTRACT <CONTRACT_NAME> <CONTRACT_NAME> <CONTRACT_NAME> <CONTRACT_NAME> ... | ||
# If testing a library: | ||
# ./scripts/test.sh LIB <LIBRARY_NAME> | ||
# If testing multiple libraries: | ||
# ./scripts/test.sh LIB <LIBRARY_NAME> <LIBRARY_NAME> <LIBRARY_NAME> <LIBRARY_NAME> ... | ||
|
||
ROOT=$(pwd) | ||
|
||
# Get the project type from the first argument | ||
PROJECT_TYPE=$1 | ||
shift | ||
|
||
# Error flag file | ||
error_file="/tmp/error.$$" | ||
# Array of child PIDs | ||
pids=() | ||
|
||
# Handler for SIGCHLD, cleanup if child exit with error | ||
handle_sigchld() { | ||
for pid in "${pids[@]}"; do | ||
# If process is no longer running | ||
if ! kill -0 "$pid" 2>/dev/null; then | ||
# Wait for the process and get exit status | ||
wait "$pid" | ||
status=$? | ||
|
||
# If exit status is error | ||
if [ $status -ne 0 ]; then | ||
# Create error file | ||
touch "$error_file" | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# Set SIGCHLD handler | ||
trap handle_sigchld SIGCHLD # Trap any ERR signal and call the custom error handler | ||
|
||
test() { | ||
PROJECT_NAME=$1 | ||
|
||
if [ "$PROJECT_TYPE" == "CONTRACT" ]; then | ||
CONTRACT_FOLDER="${PROJECT_NAME}_contract" | ||
echo "Testing contract $PROJECT_NAME..." | ||
cd src/contracts/$CONTRACT_FOLDER | ||
nargo test | ||
else | ||
echo "Testing library $PROJECT_NAME..." | ||
cd ../noir-libs/$PROJECT_NAME | ||
nargo test | ||
fi | ||
} | ||
|
||
echo "Using $(nargo --version)" | ||
|
||
# Build contracts | ||
for PROJECT_NAME in "$@"; do | ||
test $PROJECT_NAME & | ||
pids+=($!) | ||
done | ||
|
||
# Wait for all background processes to finish | ||
wait | ||
|
||
# If error file exists, exit with error | ||
if [ -f "$error_file" ]; then | ||
rm "$error_file" | ||
echo "Error occurred in one or more child processes. Exiting..." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Runs tests scripts for all contracts, then for all libraries. | ||
|
||
./scripts/nargo_test.sh CONTRACT $(./scripts/get_all_contracts.sh) | ||
./scripts/nargo_test.sh LIB $(./scripts/get_all_libraries.sh) |