From f732d22dc30a5c6c5d368ebee269dec7fbea1b95 Mon Sep 17 00:00:00 2001 From: bohendo Date: Mon, 4 Aug 2025 16:27:02 +0530 Subject: [PATCH 1/2] rm bugged force flag from initial mutation test run --- docs/src/tools/Mutator.md | 4 +++- slither/tools/mutator/utils/testing_generated_mutant.py | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/src/tools/Mutator.md b/docs/src/tools/Mutator.md index b33c5f4fbe..4cf5a93fd5 100644 --- a/docs/src/tools/Mutator.md +++ b/docs/src/tools/Mutator.md @@ -12,6 +12,8 @@ You can provide flags to `forge` as part of the `--test-cmd` parameter or target `slither-mutate src/core/MyContract.sol --test-cmd='forge test --match-contract="MyContract"'` +If a `timout` flag is not provided, slither-mutate will default to using a value that's double the runtime of it's initial test cmd execution. Make sure you run `forge clean` or similar beforehand to ensure cache usage doesn't cause a timeout that's too short to be used; this could lead to false-negatives. + ### CLI Interface ```shell @@ -30,7 +32,7 @@ options: --test-dir TEST_DIR Tests directory --ignore-dirs IGNORE_DIRS Directories to ignore - --timeout TIMEOUT Set timeout for test command (by default 30 seconds) + --timeout TIMEOUT Set timeout for test command (by default 2x the initial test runtime) --output-dir OUTPUT_DIR Name of output directory (by default 'mutation_campaign') -v, --verbose log mutants that are caught, uncaught, and fail to compile diff --git a/slither/tools/mutator/utils/testing_generated_mutant.py b/slither/tools/mutator/utils/testing_generated_mutant.py index 2ea3314e6d..1b055b5f12 100644 --- a/slither/tools/mutator/utils/testing_generated_mutant.py +++ b/slither/tools/mutator/utils/testing_generated_mutant.py @@ -40,10 +40,6 @@ def run_test_cmd( elif "hardhat test" in cmd or "truffle test" in cmd and "--bail" not in cmd: cmd += " --bail" - if timeout is None and "hardhat" not in cmd: # hardhat doesn't support --force flag on tests - # if no timeout, ensure all contracts are recompiled w/out using any cache - cmd += " --force" - try: result = subprocess.run( cmd, From a2f863b61f3c465c5a7ae324b41091ffef018c3e Mon Sep 17 00:00:00 2001 From: bohendo Date: Mon, 4 Aug 2025 16:27:09 +0530 Subject: [PATCH 2/2] clean up mutation output logs --- slither/tools/mutator/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slither/tools/mutator/__main__.py b/slither/tools/mutator/__main__.py index 1eb5f3faed..bc8531eaca 100644 --- a/slither/tools/mutator/__main__.py +++ b/slither/tools/mutator/__main__.py @@ -344,7 +344,7 @@ def main() -> None: # pylint: disable=too-many-statements,too-many-branches,too if total_mutant_counts[0] > 0: logger.info( magenta( - f"Revert mutants: {uncaught_mutant_counts[0]} uncaught of {total_mutant_counts[0]} ({100 * uncaught_mutant_counts[0]/total_mutant_counts[0]}%)" + f"Revert mutants: {uncaught_mutant_counts[0]} uncaught of {total_mutant_counts[0]} ({round(100 * (total_mutant_counts[0] - uncaught_mutant_counts[0])/total_mutant_counts[0], 1)}% caught)" ) ) else: @@ -353,7 +353,7 @@ def main() -> None: # pylint: disable=too-many-statements,too-many-branches,too if total_mutant_counts[1] > 0: logger.info( magenta( - f"Comment mutants: {uncaught_mutant_counts[1]} uncaught of {total_mutant_counts[1]} ({100 * uncaught_mutant_counts[1]/total_mutant_counts[1]}%)" + f"Comment mutants: {uncaught_mutant_counts[1]} uncaught of {total_mutant_counts[1]} ({round(100 * (total_mutant_counts[1] - uncaught_mutant_counts[1])/total_mutant_counts[1], 1)}% caught)" ) ) else: @@ -362,7 +362,7 @@ def main() -> None: # pylint: disable=too-many-statements,too-many-branches,too if total_mutant_counts[2] > 0: logger.info( magenta( - f"Tweak mutants: {uncaught_mutant_counts[2]} uncaught of {total_mutant_counts[2]} ({100 * uncaught_mutant_counts[2]/total_mutant_counts[2]}%)\n" + f"Tweak mutants: {uncaught_mutant_counts[2]} uncaught of {total_mutant_counts[2]} ({round(100 * (total_mutant_counts[2] - uncaught_mutant_counts[2])/total_mutant_counts[2], 1)}% caught)\n" ) ) else: