Skip to content
Open
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
45 changes: 34 additions & 11 deletions forge/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@

#!/bin/bash

set -e # Stopping on error
# Exit immediately if a command exits with a non-zero status
set -e

# Trapping: This ensures cleanup happens even if the script fails half-way
# A critical security practice for handling temporary sensitive data
cleanup() {
if [ -f .env.forge-temp ]; then
echo "[Cleanup] Removing temporary environment file..."
rm .env.forge-temp
fi
}
trap cleanup EXIT

# 1. Export network configurations to a temporary file
echo "[1/4] Exporting dynamic network configurations..."
# Ensure the node script actually creates the file before proceeding
node scripts/exportNetworkConfigs.js

# 2. Load environment variables from the temporary file
export $(cat .env.forge-temp | xargs)
if [ ! -f .env.forge-temp ]; then
echo "Error: .env.forge-temp not found. Export failed."
exit 1
fi

echo "[2/4] Loading temporary environment variables..."
# Use allexport to safely import env vars into the current shell session
set -a
source .env.forge-temp
set +a

# 3. Run the Forge tests
forge test -vvv --via-ir --optimizer-runs 1 --no-match-path "./contracts/capo/*"
echo "[3/4] Running Forge tests (Optimizer: 1, via-IR: enabled)..."
# Logic: --via-ir is required for complex nested storage or high-stack contracts
# Optimization: --no-match-path isolates testing to relevant modules
forge test \
-vvv \
--via-ir \
--optimizer-runs 1 \
--no-match-path "./contracts/capo/*"

# 4. Delete the temporary environment file
rm .env.forge-temp
# To test a specific test case in Foundry, use the --match-test flag:
# Example: forge test --match-test testFunctionName -vvvv
echo "[4/4] Execution finished successfully."
# Cleanup is handled automatically by the 'trap' on EXIT