-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: run extra fuzz rounds for new fuzz tests
Adds a new script that can run extra fuzz test iterations when new fuzz tests are added. Can be used in CI or locally to make sure that new fuzz tests aren't flaky.
- Loading branch information
1 parent
31f408b
commit b6d3b01
Showing
3 changed files
with
52 additions
and
1 deletion.
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
36 changes: 36 additions & 0 deletions
36
packages/contracts-bedrock/scripts/testing/test-extra-fuzz-runs.sh
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,36 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# This script is used to run extra fuzz test iterations on any fuzz tests that | ||
# have been newly added in a PR. We typically want to run extra fuzz iterations | ||
# when new tests are added to make sure that they are not flaky with some small | ||
# percentage of fuzz runs. | ||
|
||
# Set the number of fuzz runs to run | ||
# 350000 fuzz runs will guarantee that any test that fails 1% of the time with | ||
# the default 512 fuzz runs will fail 99.9% of the time (on average) inside of | ||
# this script. | ||
FUZZ_RUNS=${1:-350000} | ||
|
||
# show where the script failed in this next line! | ||
trap 'echo "Script failed at line $LINENO" && echo "Error: $BASH_COMMAND"' ERR | ||
|
||
# Get the contracts base directory | ||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
CONTRACTS_BASE=$(dirname "$(dirname "$SCRIPT_DIR")") | ||
|
||
# Determine if there are any new fuzz tests | ||
NEW_TEST_NAMES=$(git diff origin/develop...HEAD -- '*.sol' | grep -E '^\+.*function testFuzz_' | awk '{print $3}' | sed 's/.*function //; s/(.*//' || true) | ||
NEW_TEST_NAMES=$(echo "$NEW_TEST_NAMES" | tr '\n' ' ' | xargs) | ||
|
||
# Exit if no new fuzz tests are found | ||
if [ -z "$NEW_TEST_NAMES" ]; then | ||
echo "No new fuzz tests found" | ||
exit 0 | ||
fi | ||
|
||
# Navigate to the contracts base directory | ||
cd "$CONTRACTS_BASE" | ||
|
||
# Run matching tests with extra fuzz runs | ||
forge test --match-test "${NEW_TEST_NAMES// /|}" --fuzz-runs $FUZZ_RUNS |