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

Fuzz testing #1255

Merged
merged 17 commits into from
Jan 9, 2025
Merged

Fuzz testing #1255

merged 17 commits into from
Jan 9, 2025

Conversation

immrsd
Copy link
Collaborator

@immrsd immrsd commented Dec 10, 2024

PR Checklist

  • Tests

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Good start on the fuzz testing! I left a few comments

packages/testing/src/math.cairo Outdated Show resolved Hide resolved
packages/token/src/tests/erc20/test_fuzz_erc20.cairo Outdated Show resolved Hide resolved
@@ -48,7 +48,7 @@ jobs:
run: scarb fmt --check --workspace

- name: Run tests and generate coverage report
run: snforge test --workspace --coverage
run: snforge test --workspace --coverage --features fuzzing --fuzzer-runs 10000
Copy link
Member

Choose a reason for hiding this comment

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

I have the feeling that this will soon make tests run timeout in the action.

Copy link
Member

Choose a reason for hiding this comment

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

Tests are not running on the PR btw, when that's fixed I'm curious to see how much time will this take with this few examples.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reduced the number of fuzzer runs to 500 which seems a reasonable value to me, at least for now

With 10k runs the tests took 1h 55m to complete which is way too much, here are the run results: https://github.com/OpenZeppelin/cairo-contracts/actions/runs/12374506824/job/34537193923

With 1k runs it took 17m 27s to run all the tests. 10 minutes more than our usual test runs.
Results: https://github.com/OpenZeppelin/cairo-contracts/actions/runs/12379685661/job/34554383936

Although it's an acceptable duration, it can increase much when we add more fuzz test cases. So now with 500 runs the tests job takes 12 minutes (5 minutes more than it was without fuzz tests)

packages/testing/src/math.cairo Outdated Show resolved Hide resolved
packages/token/Scarb.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Improvements look good! Just left a final question

packages/token/src/tests/erc20/test_fuzz_erc20.cairo Outdated Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

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

Great job @immrsd, the approach looks good to me. With this said, note that snfoundry is working on improving its fuzz testing API, so we will probably need to adapt in the future, but this looks like a good foundation. cc @ggonzalez94 regarding snfoundry probably updating the API at some point this year.

@immrsd
Copy link
Collaborator Author

immrsd commented Jan 8, 2025

Great job @immrsd, the approach looks good to me. With this said, note that snfoundry is working on improving its fuzz testing API, so we will probably need to adapt in the future, but this looks like a good foundation. cc @ggonzalez94 regarding snfoundry probably updating the API at some point this year.

Noted!

@immrsd immrsd requested a review from andrew-fleming January 8, 2025 14:50
@immrsd immrsd merged commit ca212ce into OpenZeppelin:main Jan 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants