Skip to content

Commit ae3e06f

Browse files
committed
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.
1 parent c01cd8f commit ae3e06f

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/key.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ mod test {
15721572
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
15731573
];
15741574

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

@@ -1739,7 +1740,8 @@ mod test {
17391740
assert_eq!(set.len(), COUNT);
17401741
}
17411742

1742-
#[cfg_attr(not(fuzzing), test)]
1743+
#[test]
1744+
#[cfg(not(fuzzing))]
17431745
fn pubkey_combine() {
17441746
let compressed1 = PublicKey::from_slice(
17451747
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
@@ -1759,7 +1761,8 @@ mod test {
17591761
assert_eq!(sum1.unwrap(), exp_sum);
17601762
}
17611763

1762-
#[cfg_attr(not(fuzzing), test)]
1764+
#[test]
1765+
#[cfg(not(fuzzing))]
17631766
fn pubkey_combine_keys() {
17641767
let compressed1 = PublicKey::from_slice(
17651768
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),
@@ -1782,7 +1785,8 @@ mod test {
17821785
assert_eq!(sum1.unwrap(), exp_sum);
17831786
}
17841787

1785-
#[cfg_attr(not(fuzzing), test)]
1788+
#[test]
1789+
#[cfg(not(fuzzing))]
17861790
fn pubkey_combine_keys_empty_slice() {
17871791
assert!(PublicKey::combine_keys(&[]).is_err());
17881792
}
@@ -1852,6 +1856,7 @@ mod test {
18521856
0218845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166\
18531857
";
18541858

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

src/schnorr.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ mod tests {
286286

287287
use super::*;
288288

289-
#[cfg(any(feature = "alloc", feature = "std"))]
289+
#[cfg(all(not(fuzzing), any(feature = "alloc", feature = "std")))]
290290
macro_rules! hex_32 {
291291
($hex:expr) => {{
292292
let mut result = [0u8; 32];
@@ -458,19 +458,21 @@ mod tests {
458458
#[test]
459459
#[cfg(feature = "std")]
460460
fn test_pubkey_display_output() {
461-
let secp = Secp256k1::new();
462-
static SK_BYTES: [u8; 32] = [
463-
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
464-
0x06, 0x07, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63,
465-
0x63, 0x63, 0x63, 0x63,
466-
];
467-
468-
let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");
469-
470-
// In fuzzing mode secret->public key derivation is different, so
471-
// hard-code the epected result.
472461
#[cfg(not(fuzzing))]
473-
let pk = kp.public_key();
462+
let pk = {
463+
let secp = Secp256k1::new();
464+
static SK_BYTES: [u8; 32] = [
465+
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
466+
0x06, 0x07, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63,
467+
0x63, 0x63, 0x63, 0x63,
468+
];
469+
470+
let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");
471+
472+
// In fuzzing mode secret->public key derivation is different, so
473+
// hard-code the epected result.
474+
kp.public_key()
475+
};
474476
#[cfg(fuzzing)]
475477
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");
476478

0 commit comments

Comments
 (0)