diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a844e8bfd..01a96ad90 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -67,7 +67,7 @@ jobs: run: yarn test test-contracts: - name: Test storage layout and signatures + name: Test storage layout, signatures and look for unused errors runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -98,8 +98,11 @@ jobs: - name: Test function signatures run: yarn run test:signatures - - name: Test unused errors - run: yarn run test:unused:errors + - name: Run unused Solidity errors checker + uses: OffchainLabs/actions/check-unused-errors@unused-errors + with: + directory: './contracts' + exceptions_file: './test/unused-errors/exceptions.txt' test-e2e: name: Test e2e diff --git a/test/unused-errors/find_unused_errors.sh b/test/unused-errors/find_unused_errors.sh deleted file mode 100755 index 98b764975..000000000 --- a/test/unused-errors/find_unused_errors.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -# Directory containing the Solidity files -DIR="./contracts" -EXCEPTIONS_FILE="./test/unused-errors/exceptions.txt" - -# Temporary file to store errors and their corresponding files -ERRORS_FILE=$(mktemp) -UNUSED_ERRORS_FILE=$(mktemp) -exit_status=0 - -# Load exceptions into an array -exceptions=() -if [ -f "$EXCEPTIONS_FILE" ]; then - while IFS= read -r line || [ -n "$line" ]; do - exceptions+=("$line") - done < "$EXCEPTIONS_FILE" -fi - -# Function to check if an error is in the exceptions list -is_exception() { - local error="$1" - for exception in "${exceptions[@]}"; do - if [ "$exception" == "$error" ]; then - return 0 - fi - done - return 1 -} - -# Find all error definitions and store them in a temporary file along with filenames -grep -rHo "error\s\+\w\+\s*(" $DIR | awk -F':' '{print $1 ": " $2}' | awk '{gsub(/error /, ""); gsub(/\(/, ""); print}' | sort -u > $ERRORS_FILE - -# Loop through each error to check if it is used -while IFS=: read -r file error; do - # Normalize file and error output - error=$(echo $error | xargs) - - # Skip errors in the exception list - if is_exception "$error"; then - echo "Skipping: $error" - continue - fi - - # Count occurrences of each error in 'revert' statements - count=$(grep -roh "revert\s\+$error" $DIR | wc -l) - - # If count is 0, the error is defined but never used - if [ "$count" -eq 0 ]; then - echo "$error" >> $UNUSED_ERRORS_FILE - exit_status=1 - fi -done < $ERRORS_FILE - -# Print the list of unused errors -if [ -s $UNUSED_ERRORS_FILE ]; then - echo "These errors are defined, but never used:" - cat $UNUSED_ERRORS_FILE -else - echo "All defined errors are used." -fi - -# Remove the temporary files -rm $ERRORS_FILE -rm $UNUSED_ERRORS_FILE - -# Exit with the appropriate status -exit $exit_status