Fix unit tests and benchmarks

The new API allows us to remove a bunch of tests which are now checked
by the compiler.
This commit is contained in:
Thomas Eizinger 2018-06-03 18:47:14 +10:00
parent f1a88259fb
commit bb77741e47
3 changed files with 6 additions and 46 deletions

View File

@ -98,7 +98,7 @@ mod tests {
#[test]
fn ecdh() {
let s = Secp256k1::with_caps(::ContextFlag::SignOnly);
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut thread_rng()).unwrap();
let (sk2, pk2) = s.generate_keypair(&mut thread_rng()).unwrap();
@ -120,7 +120,7 @@ mod benches {
#[bench]
pub fn bench_ecdh(bh: &mut Bencher) {
let s = Secp256k1::with_caps(::ContextFlag::SignOnly);
let s = Secp256k1::signing_only();
let (sk, pk) = s.generate_keypair(&mut thread_rng()).unwrap();
let s = Secp256k1::new();

View File

@ -354,39 +354,6 @@ mod test {
0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41]).is_err());
}
#[test]
fn test_pubkey_from_slice_bad_context() {
let s = Secp256k1::without_caps();
let sk = SecretKey::new(&s, &mut thread_rng());
assert_eq!(PublicKey::from_secret_key(&s, &sk), Err(IncapableContext));
let s = Secp256k1::with_caps(ContextFlag::VerifyOnly);
assert_eq!(PublicKey::from_secret_key(&s, &sk), Err(IncapableContext));
let s = Secp256k1::with_caps(ContextFlag::SignOnly);
assert!(PublicKey::from_secret_key(&s, &sk).is_ok());
let s = Secp256k1::with_caps(ContextFlag::Full);
assert!(PublicKey::from_secret_key(&s, &sk).is_ok());
}
#[test]
fn test_add_exp_bad_context() {
let s = Secp256k1::with_caps(ContextFlag::Full);
let (sk, mut pk) = s.generate_keypair(&mut thread_rng()).unwrap();
assert!(pk.add_exp_assign(&s, &sk).is_ok());
let s = Secp256k1::with_caps(ContextFlag::VerifyOnly);
assert!(pk.add_exp_assign(&s, &sk).is_ok());
let s = Secp256k1::with_caps(ContextFlag::SignOnly);
assert_eq!(pk.add_exp_assign(&s, &sk), Err(IncapableContext));
let s = Secp256k1::with_caps(ContextFlag::None);
assert_eq!(pk.add_exp_assign(&s, &sk), Err(IncapableContext));
}
#[test]
fn test_out_of_range() {
@ -530,7 +497,7 @@ mod test {
#[test]
fn pubkey_combine() {
let s = Secp256k1::with_caps(ContextFlag::None);
let s = Secp256k1::without_caps();
let compressed1 = PublicKey::from_slice(
&s,
&hex!("0241cc121c419921942add6db6482fb36243faf83317c866d2a28d8c6d7089f7ba"),

View File

@ -114,10 +114,9 @@ mod tests {
#[test]
fn capabilities() {
let none = Secp256k1::with_caps(ContextFlag::None);
let sign = Secp256k1::with_caps(ContextFlag::SignOnly);
let vrfy = Secp256k1::with_caps(ContextFlag::VerifyOnly);
let full = Secp256k1::with_caps(ContextFlag::Full);
let sign = Secp256k1::signing_only();
let vrfy = Secp256k1::verification_only();
let full = Secp256k1::new();
let mut msg = [0u8; 32];
thread_rng().fill_bytes(&mut msg);
@ -126,22 +125,16 @@ mod tests {
let (sk, pk) = full.generate_keypair(&mut thread_rng()).unwrap();
// Try signing
assert_eq!(none.sign_schnorr(&msg, &sk), Err(IncapableContext));
assert_eq!(vrfy.sign_schnorr(&msg, &sk), Err(IncapableContext));
assert!(sign.sign_schnorr(&msg, &sk).is_ok());
assert!(full.sign_schnorr(&msg, &sk).is_ok());
assert_eq!(sign.sign_schnorr(&msg, &sk), full.sign_schnorr(&msg, &sk));
let sig = full.sign_schnorr(&msg, &sk).unwrap();
// Try verifying
assert_eq!(none.verify_schnorr(&msg, &sig, &pk), Err(IncapableContext));
assert_eq!(sign.verify_schnorr(&msg, &sig, &pk), Err(IncapableContext));
assert!(vrfy.verify_schnorr(&msg, &sig, &pk).is_ok());
assert!(full.verify_schnorr(&msg, &sig, &pk).is_ok());
// Try pk recovery
assert_eq!(none.recover_schnorr(&msg, &sig), Err(IncapableContext));
assert_eq!(sign.recover_schnorr(&msg, &sig), Err(IncapableContext));
assert!(vrfy.recover_schnorr(&msg, &sig).is_ok());
assert!(full.recover_schnorr(&msg, &sig).is_ok());