Skip to content

Commit

Permalink
Fix lint warnings in test code
Browse files Browse the repository at this point in the history
Various combinations of features trigger lint warnings for unused code,
all warnings are caused by incorrect feature gating.

Correct feature gating to remove Clippy warnings during testing.
  • Loading branch information
tcharding committed Feb 1, 2022
1 parent 25fde65 commit 38b5128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
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.
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

0 comments on commit 38b5128

Please sign in to comment.