Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): Run nargo test in ci on all packages #2197

Merged
merged 9 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yarn-project/noir-contracts/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ ENV PATH="/usr/src/yarn-project/noir-contracts/.nargo/bin:${PATH}"
RUN ./scripts/install_noir.sh
RUN ./scripts/install_noir_backend.sh
RUN ./scripts/compile_ci.sh
RUN ./scripts/nargo_test_ci.sh
3 changes: 3 additions & 0 deletions yarn-project/noir-contracts/scripts/get_all_libraries.sh
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/")
78 changes: 78 additions & 0 deletions yarn-project/noir-contracts/scripts/nargo_test.sh
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
7 changes: 7 additions & 0 deletions yarn-project/noir-contracts/scripts/nargo_test_ci.sh
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)