key: Add PubKey hashing test.

This commit is contained in:
Dawid Ciężarkiewicz 2016-01-08 19:45:20 -08:00
parent 6686c213dd
commit 16b36f18e1
1 changed files with 23 additions and 0 deletions

View File

@ -609,6 +609,29 @@ mod test {
assert!(pk2.add_exp_assign(&s, &sk1).is_ok());
assert_eq!(PublicKey::from_secret_key(&s, &sk2).unwrap(), pk2);
}
#[test]
fn pubkey_hash() {
use std::hash::{Hash, SipHasher, Hasher};
use std::collections::HashSet;
fn hash<T: Hash>(t: &T) -> u64 {
let mut s = SipHasher::new();
t.hash(&mut s);
s.finish()
}
let s = Secp256k1::new();
let mut set = HashSet::new();
const COUNT : usize = 1024;
let count = (0..COUNT).map(|_| {
let (_, pk) = s.generate_keypair(&mut thread_rng()).unwrap();
let hash = hash(&pk);
assert!(!set.contains(&hash));
set.insert(hash);
}).count();
assert_eq!(count, COUNT);
}
}