key: Add PubKey hashing test.
This commit is contained in:
parent
6686c213dd
commit
16b36f18e1
23
src/key.rs
23
src/key.rs
|
@ -609,6 +609,29 @@ mod test {
|
||||||
assert!(pk2.add_exp_assign(&s, &sk1).is_ok());
|
assert!(pk2.add_exp_assign(&s, &sk1).is_ok());
|
||||||
assert_eq!(PublicKey::from_secret_key(&s, &sk2).unwrap(), pk2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue