Skip to content

Commit

Permalink
Move helper function below usage
Browse files Browse the repository at this point in the history
This is not C89. We can declare the more important things first.
  • Loading branch information
thomaseizinger committed Sep 9, 2021
1 parent 524cba1 commit 0c4854a
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,6 @@ mod tests {
}};
}

fn test_schnorrsig_sign_helper(
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
) {
let secp = Secp256k1::new();

let mut rng = thread_rng();
let (seckey, pubkey) = secp.generate_schnorrsig_keypair(&mut rng);
let mut msg = [0; 32];

for _ in 0..100 {
rng.fill_bytes(&mut msg);
let msg = Message::from_slice(&msg).unwrap();

let sig = sign(&secp, &msg, &seckey, &mut rng);

assert!(secp.verify_schnorr(&sig, &msg, &pubkey).is_ok());
}
}

#[test]
fn test_schnorrsig_sign_with_aux_rand_verify() {
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
Expand Down Expand Up @@ -327,6 +308,25 @@ mod tests {
})
}

fn test_schnorrsig_sign_helper(
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
) {
let secp = Secp256k1::new();

let mut rng = thread_rng();
let (seckey, pubkey) = secp.generate_schnorrsig_keypair(&mut rng);
let mut msg = [0; 32];

for _ in 0..100 {
rng.fill_bytes(&mut msg);
let msg = Message::from_slice(&msg).unwrap();

let sig = sign(&secp, &msg, &seckey, &mut rng);

assert!(secp.verify_schnorr(&sig, &msg, &pubkey).is_ok());
}
}

#[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
fn test_schnorrsig_sign() {
Expand Down

0 comments on commit 0c4854a

Please sign in to comment.