From 410b529414b9350294882ec024c7707d88a1352c Mon Sep 17 00:00:00 2001 From: Lopes-Marcio <45036084+Lopes-Marcio@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:00:05 +0300 Subject: [PATCH] Update run-tests.sh --- forge/run-tests.sh | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/forge/run-tests.sh b/forge/run-tests.sh index 607f5fc36..8a160cd02 100644 --- a/forge/run-tests.sh +++ b/forge/run-tests.sh @@ -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 \ No newline at end of file +echo "[4/4] Execution finished successfully." +# Cleanup is handled automatically by the 'trap' on EXIT