-
Notifications
You must be signed in to change notification settings - Fork 38
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
test: Investigate Fuzzing #477
Conversation
✅ Deploy Preview for contracts-stylus canceled.
|
9d8cb5f
to
3075679
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
|
openzeppelin_crypto::merkle::Verify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the scenarios, great job @0xNeshi!
Left some comments.
@0xNeshi we should consider fuzzing for this folder -> https://github.com/OpenZeppelin/rust-contracts-stylus/tree/main/contracts/src/utils/math |
Definitely 💯 We will need shims for this to work though, I'd suggest we hold off on this for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on fuzzing!
I think we should remember once we write many tests, it can make design changes difficult as well as support.
|
||
use super::*; | ||
|
||
proptest! { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that we are mostly testing here how keccak is implemented in the other crate (tiny-keccak). That it can produce the same hash, meets consistency and distribution requirement. Shouldn't these tests be implemented there already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's remarkably low on tests for such a popular crate
lib/crypto/src/bits.rs
Outdated
fn trimmed_iter_starts_with_one() { | ||
proptest!(|(value in 1u64..)| { | ||
let bits: Vec<bool> = value.bit_be_trimmed_iter().collect(); | ||
prop_assert!(!bits.is_empty()); | ||
prop_assert!(bits[0]); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn trimmed_is_subset_of_full() { | ||
proptest!(|(value: u64)| { | ||
let full: Vec<bool> = value.bit_be_iter().collect(); | ||
let trimmed: Vec<bool> = value.bit_be_trimmed_iter().collect(); | ||
let start_idx = value.leading_zeros() as usize; | ||
prop_assert_eq!(&full[start_idx..], trimmed); | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qalisander is this way of writing proptests as standalone better for your IDE than when all tests are grouped in one proptest!
? You mentioned that this way you're able to run individual tests from within IDE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
As per our agreement, this PR includes a basic fuzz tests setup and some missing unit/property tests for
openzeppelin-crypto
crate.I created a couple of related issues to address missing property tests (see #501 #502 #503).
Adding property tests for contract will be easily possible after
motsu
is refactored (see https://github.com/OpenZeppelin/stylus-test-helpers/pull/14/files#r1919897820)Resolves #458
PR Checklist