Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutation testing #66

Merged
merged 15 commits into from
Feb 5, 2024
Merged

Add mutation testing #66

merged 15 commits into from
Feb 5, 2024

Conversation

gvladika
Copy link
Contributor

PR adds integration with Certora's Gambit mutation testing framework. Gambit receives Solidity file or list of files as input, and it will generate "mutants" as output. Those are copies of original file, but each with an atomic modification of original file, ie. flipped operator, mutated 'if' condition etc. Idea is to then run the test suite against the mutant. If all tests still pass, mutant survived, that's bad - either there's faulty test or there is missing coverage. If some test(s) fail, mutant's been killed, that's good.

gambitTester script works like this:

  • generates mutants for files specified in test-mutation/config.json
  • for each mutant do in parallel (in batches):
    • replace original file with mutant
    • re-compile and run foundry suite
    • track results
  • report results

How to use it:

  • update test-mutation/config.json with the list of solidity files to be tested
  • run yarn run test:mutation

Copy link
Contributor

@yahgwai yahgwai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'm looking forward to trying this out on our other projects. Is there a way to ignore a certain mutation if we know it's not useful information?

It might be nice to add a section the readme about how to do the mutation testing, including where to install gambit

@gvladika
Copy link
Contributor Author

Nice! I'm looking forward to trying this out on our other projects. Is there a way to ignore a certain mutation if we know it's not useful information?

It might be nice to add a section the readme about how to do the mutation testing, including where to install gambit

I've added new doc with all the steps: d3e5df6

In the JSON config file (which is the input to Gambit for generating mutants), you can specify which kind of "mutation operators" you want to applied. Here is the list of all supported operators. You can also ie. limit mutation operators to the specific functions that you're interested in testing. Once mutated files are generated, currently there is no way to tell the testing script to skip some of them. But we can add that feature if it would be useful.

Copy link
Member

@gzeoneth gzeoneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gzeoneth gzeoneth merged commit cb9bca7 into main Feb 5, 2024
7 checks passed
@gzeoneth gzeoneth deleted the gambit-tool branch February 5, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants