Skip to content

Add Prop test infra to binary_sv2#2083

Closed
Shourya742 wants to merge 3 commits intostratum-mining:mainfrom
Shourya742:2026-02-13-add-binary-sv2-prop-test
Closed

Add Prop test infra to binary_sv2#2083
Shourya742 wants to merge 3 commits intostratum-mining:mainfrom
Shourya742:2026-02-13-add-binary-sv2-prop-test

Conversation

@Shourya742
Copy link
Copy Markdown
Collaborator

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

@Shourya742 Shourya742 force-pushed the 2026-02-13-add-binary-sv2-prop-test branch from 85078b8 to 44d2cee Compare February 13, 2026 16:38
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what if this becomes a more generic script, instead of dealing with just binary_s2, and change its path to scripts folder?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yup, agree. I had to follow the same setups while writing test for other crates as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is not working on my mac, as soon as understand what is failing I'll post here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

you need to have cargo-llvm-cov installed, along with some other llvm profilers. I will add them in the script.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment on lines +571 to +577
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()
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Suggested change
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[..]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not compare directly to data?
I'm ok with both, just wanted to know is there is a reason.

Suggested change
assert_eq!(decoded.inner_as_ref(), &original[..]);
assert_eq!(decoded.inner_as_ref(), &data.0[..]);

Comment on lines +813 to +818
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())
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

all the data is being discarded, same comment as in prop_b0255_rejects_oversized. the test bellow never panics

Suggested change
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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is if is never reached, but i think in that case is OK

}

#[quickcheck]
fn prop_b032_rejects_oversized_(size: u8) -> TestResult {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fn prop_b032_rejects_oversized_(size: u8) -> TestResult {
fn prop_b032_rejects_oversized(size: u8) -> TestResult {

@Shourya742
Copy link
Copy Markdown
Collaborator Author

Closing this considering we anyway gonna change a lot of stuff in binary_sv2 in future.

@Shourya742 Shourya742 closed this Apr 8, 2026
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.

2 participants