Added README

pull/2278/head
Vishnuram Rajkumar 10 months ago
parent 48b6f6fee2
commit 799117d086
  1. 31
      slither/tools/mutator/README.md
  2. 12
      slither/tools/mutator/__main__.py
  3. 2
      slither/tools/mutator/mutators/abstract_mutator.py
  4. 4
      slither/tools/mutator/utils/file_handling.py

@ -0,0 +1,31 @@
# Slither-mutate
`slither-mutate` is a mutation testing tool for solidity based smart contracts.
## Usage
`slither-mutate <codebase> <test-cmd> <options>`
### CLI Interface
```
positional arguments:
codebase Codebase to analyze (.sol file, truffle directory, ...)
test-cmd Command to run the tests for your project
options:
-h, --help show this help message and exit
--list-mutators List available detectors
--test-dir TEST_DIR Tests directory
--ignore-dirs IGNORE_DIRS
Directories to ignore
--timeout TIMEOUT Set timeout for test command (by default 30 seconds)
--output-dir OUTPUT_DIR
Name of output Directory (by default 'mutation_campaign')
--verbose output all mutants generated
--mutators-to-run MUTATORS_TO_RUN
mutant generators to run
--contract-names CONTRACT_NAMES
list of contract names you want to mutate
--quick to stop full mutation if revert mutator passes
```

@ -41,14 +41,14 @@ def parse_args() -> argparse.Namespace:
# argument to add the test command
parser.add_argument(
"--test-cmd",
help="Command line needed to run the tests for your project"
"test-cmd",
help="Command to run the tests for your project"
)
# argument to add the test directory - containing all the tests
parser.add_argument(
"--test-dir",
help="Directory of tests"
help="Tests directory"
)
# argument to ignore the interfaces, libraries
@ -66,7 +66,7 @@ def parse_args() -> argparse.Namespace:
# output directory argument
parser.add_argument(
"--output-dir",
help="Output Directory (by default 'mutation_campaign')"
help="Name of output directory (by default 'mutation_campaign')"
)
# to print just all the mutants
@ -170,6 +170,7 @@ def main() -> None:
# setting RR mutator as first mutator
mutators_list = _get_mutators(mutators_to_run)
# insert RR and CR in front of the list
CR_RR_list = []
duplicate_list = mutators_list.copy()
for M in duplicate_list:
@ -191,8 +192,9 @@ def main() -> None:
total_count = 0
# count of valid mutants
v_count = 0
# lines those need not be mutated (taken from RR and CR)
dont_mutate_lines = []
# mutation
try:
for compilation_unit_of_main_file in sl.compilation_units:

@ -3,7 +3,6 @@ import logging
from enum import Enum
from typing import Optional, Dict, Tuple, List
from slither.core.compilation_unit import SlitherCompilationUnit
# from slither.tools.doctor.utils import snip_section
from slither.formatters.utils.patches import apply_patch, create_diff
from slither.tools.mutator.utils.testing_generated_mutant import test_patch
from slither.utils.colors import yellow
@ -100,6 +99,7 @@ class AbstractMutator(metaclass=abc.ABCMeta): # pylint: disable=too-few-public-
for patch in patches:
# test the patch
flag = test_patch(file, patch, self.test_command, self.VALID_MUTANTS_COUNT, self.NAME, self.timeout, self.solc_remappings, self.verbose)
# if RR or CR and valid mutant, add line no.
if (self.NAME == 'RR' or self.NAME == 'CR') and flag:
self.dont_mutate_line.append(patch['line_number'])
# count the valid and invalid mutants

@ -104,6 +104,4 @@ def get_sol_file_list(codebase: str, ignore_paths: List[str] | None) -> List[str
for i in get_sol_file_list(filename, ignore_paths):
sol_file_list.append(i)
return sol_file_list
# TODO: create a function to delete the commands from the sol file
return sol_file_list
Loading…
Cancel
Save