Add Prop test infra to binary_sv2#2083
Add Prop test infra to binary_sv2#2083Shourya742 wants to merge 3 commits intostratum-mining:mainfrom
Conversation
…sv2 and update corresponding crates
85078b8 to
44d2cee
Compare
There was a problem hiding this comment.
what if this becomes a more generic script, instead of dealing with just binary_s2, and change its path to scripts folder?
There was a problem hiding this comment.
Yup, agree. I had to follow the same setups while writing test for other crates as well.
There was a problem hiding this comment.
Is not working on my mac, as soon as understand what is failing I'll post here
There was a problem hiding this comment.
you need to have cargo-llvm-cov installed, along with some other llvm profilers. I will add them in the script.
There was a problem hiding this comment.
I have them, I probably messed up with the other one i use for the fuzzing coverage:
https://github.com/stratum-mining/stratum-fuzzing-corpus/blob/main/scripts/fuzz_coverage.sh
This is one is working for me
| fn prop_b0255_rejects_oversized(data: Vec<u8>) -> TestResult { | ||
| if data.len() > 255 { | ||
| TestResult::from_bool(B0255::try_from(data).is_err()) | ||
| } else { | ||
| TestResult::discard() | ||
| } | ||
| } |
There was a problem hiding this comment.
for me this test is always discarding the data. Because, this value is too big for the testing session. Maybe we should have some Arbitrary impl for some BytesOver255 (?)
How i tested it? the panic! that I added is never reached
| fn prop_b0255_rejects_oversized(data: Vec<u8>) -> TestResult { | |
| if data.len() > 255 { | |
| TestResult::from_bool(B0255::try_from(data).is_err()) | |
| } else { | |
| TestResult::discard() | |
| } | |
| } | |
| fn prop_b0255_rejects_oversized(data: Vec<u8>) -> TestResult { | |
| if data.len() > 255 { | |
| panic!( | |
| "Data length {} exceeds 255, which should be rejected by B0255", | |
| data.len() | |
| ); | |
| TestResult::from_bool(B0255::try_from(data).is_err()) | |
| } else { | |
| TestResult::discard() | |
| } | |
| } |
| let mut buf = vec![0u8; pubkey.get_size()]; | ||
| pubkey.to_slice_unchecked(&mut buf); | ||
| let decoded = PubKey::from_bytes_unchecked(&mut buf); | ||
| assert_eq!(decoded.inner_as_ref(), &original[..]); |
There was a problem hiding this comment.
why not compare directly to data?
I'm ok with both, just wanted to know is there is a reason.
| assert_eq!(decoded.inner_as_ref(), &original[..]); | |
| assert_eq!(decoded.inner_as_ref(), &data.0[..]); |
| fn prop_str0255_rejects_oversized(data: Vec<u8>) -> TestResult { | ||
| if data.len() <= 255 { | ||
| return TestResult::discard(); | ||
| } | ||
| TestResult::from_bool(Str0255::try_from(data).is_err()) | ||
| } |
There was a problem hiding this comment.
all the data is being discarded, same comment as in prop_b0255_rejects_oversized. the test bellow never panics
| fn prop_str0255_rejects_oversized(data: Vec<u8>) -> TestResult { | |
| if data.len() <= 255 { | |
| return TestResult::discard(); | |
| } | |
| TestResult::from_bool(Str0255::try_from(data).is_err()) | |
| } | |
| #[quickcheck] | |
| fn prop_str0255_rejects_oversized(data: Vec<u8>) -> TestResult { | |
| if data.len() <= 255 { | |
| return TestResult::discard(); | |
| } | |
| panic!("Data length {} exceeds 255", data.len()); | |
| TestResult::from_bool(Str0255::try_from(data).is_err()) | |
| } |
|
|
||
| #[quickcheck] | ||
| fn prop_str0255_from_utf8_string(text: alloc::string::String) -> TestResult { | ||
| if text.len() > 255 { |
There was a problem hiding this comment.
this is if is never reached, but i think in that case is OK
| } | ||
|
|
||
| #[quickcheck] | ||
| fn prop_b032_rejects_oversized_(size: u8) -> TestResult { |
There was a problem hiding this comment.
| fn prop_b032_rejects_oversized_(size: u8) -> TestResult { | |
| fn prop_b032_rejects_oversized(size: u8) -> TestResult { |
|
Closing this considering we anyway gonna change a lot of stuff in binary_sv2 in future. |
This test just fix the prop test dependency, adds a coverage shell file and implement prop test of datatypes/non-copy-datatypes/inner.rs.
Part of #2071