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

Enable test with --no-default-features #386

Merged
merged 7 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ mod test {
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
];

#[cfg(not(fuzzing))]
let s = Secp256k1::signing_only();
let sk = SecretKey::from_slice(&SK_BYTES).expect("sk");

Expand Down Expand Up @@ -1739,7 +1740,8 @@ mod test {
assert_eq!(set.len(), COUNT);
}

#[cfg_attr(not(fuzzing), test)]
#[test]
#[cfg(not(fuzzing))]
fn pubkey_combine() {
let compressed1 = PublicKey::from_slice(
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
Expand All @@ -1759,7 +1761,8 @@ mod test {
assert_eq!(sum1.unwrap(), exp_sum);
}

#[cfg_attr(not(fuzzing), test)]
#[test]
#[cfg(not(fuzzing))]
fn pubkey_combine_keys() {
let compressed1 = PublicKey::from_slice(
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
Expand All @@ -1782,7 +1785,8 @@ mod test {
assert_eq!(sum1.unwrap(), exp_sum);
}

#[cfg_attr(not(fuzzing), test)]
#[test]
#[cfg(not(fuzzing))]
fn pubkey_combine_keys_empty_slice() {
assert!(PublicKey::combine_keys(&[]).is_err());
}
Expand Down Expand Up @@ -1852,6 +1856,7 @@ mod test {
0218845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166\
";

#[cfg(not(fuzzing))]
let s = Secp256k1::new();
let sk = SecretKey::from_slice(&SK_BYTES).unwrap();

Expand Down
28 changes: 15 additions & 13 deletions src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod tests {

use super::*;

#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(all(not(fuzzing), any(feature = "alloc", feature = "std")))]
macro_rules! hex_32 {
($hex:expr) => {{
let mut result = [0u8; 32];
Expand Down Expand Up @@ -458,19 +458,21 @@ mod tests {
#[test]
#[cfg(feature = "std")]
fn test_pubkey_display_output() {
let secp = Secp256k1::new();
static SK_BYTES: [u8; 32] = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x63,
];

let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");

// In fuzzing mode secret->public key derivation is different, so
// hard-code the epected result.
#[cfg(not(fuzzing))]
let pk = kp.public_key();
let pk = {
let secp = Secp256k1::new();
static SK_BYTES: [u8; 32] = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x63,
];

let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");

// In fuzzing mode secret->public key derivation is different, so
// hard-code the epected result.
Copy link
Member

Choose a reason for hiding this comment

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

In ae3e06f:

Typo expected. (I know this is just moved code but we might as well fix it here)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha, there were three instances of this typo. I fixed them all as an additional patch. Cheers.

kp.public_key()
};
#[cfg(fuzzing)]
let pk = XOnlyPublicKey::from_slice(&[0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x06, 0x83, 0x7f, 0x30, 0xaa, 0x0c, 0xd0, 0x54, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66]).expect("pk");

Expand Down