Fix lint warnings in test code

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.
This commit is contained in:
Tobin Harding 2022-02-01 12:49:07 +11:00
parent c01cd8f1f3
commit ae3e06f95b
2 changed files with 23 additions and 16 deletions

View File

@ -1572,6 +1572,7 @@ mod test {
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
]; ];
#[cfg(not(fuzzing))]
let s = Secp256k1::signing_only(); let s = Secp256k1::signing_only();
let sk = SecretKey::from_slice(&SK_BYTES).expect("sk"); let sk = SecretKey::from_slice(&SK_BYTES).expect("sk");
@ -1739,7 +1740,8 @@ mod test {
assert_eq!(set.len(), COUNT); assert_eq!(set.len(), COUNT);
} }
#[cfg_attr(not(fuzzing), test)] #[test]
#[cfg(not(fuzzing))]
fn pubkey_combine() { fn pubkey_combine() {
let compressed1 = PublicKey::from_slice( let compressed1 = PublicKey::from_slice(
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"), &hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
@ -1759,7 +1761,8 @@ mod test {
assert_eq!(sum1.unwrap(), exp_sum); assert_eq!(sum1.unwrap(), exp_sum);
} }
#[cfg_attr(not(fuzzing), test)] #[test]
#[cfg(not(fuzzing))]
fn pubkey_combine_keys() { fn pubkey_combine_keys() {
let compressed1 = PublicKey::from_slice( let compressed1 = PublicKey::from_slice(
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"), &hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
@ -1782,7 +1785,8 @@ mod test {
assert_eq!(sum1.unwrap(), exp_sum); assert_eq!(sum1.unwrap(), exp_sum);
} }
#[cfg_attr(not(fuzzing), test)] #[test]
#[cfg(not(fuzzing))]
fn pubkey_combine_keys_empty_slice() { fn pubkey_combine_keys_empty_slice() {
assert!(PublicKey::combine_keys(&[]).is_err()); assert!(PublicKey::combine_keys(&[]).is_err());
} }
@ -1852,6 +1856,7 @@ mod test {
0218845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166\ 0218845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166\
"; ";
#[cfg(not(fuzzing))]
let s = Secp256k1::new(); let s = Secp256k1::new();
let sk = SecretKey::from_slice(&SK_BYTES).unwrap(); let sk = SecretKey::from_slice(&SK_BYTES).unwrap();

View File

@ -286,7 +286,7 @@ mod tests {
use super::*; use super::*;
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(all(not(fuzzing), any(feature = "alloc", feature = "std")))]
macro_rules! hex_32 { macro_rules! hex_32 {
($hex:expr) => {{ ($hex:expr) => {{
let mut result = [0u8; 32]; let mut result = [0u8; 32];
@ -458,19 +458,21 @@ mod tests {
#[test] #[test]
#[cfg(feature = "std")] #[cfg(feature = "std")]
fn test_pubkey_display_output() { 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))] #[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)] #[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"); 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");