test for dup_filter module
This commit is contained in:
parent
23d66aaae3
commit
befacce4ef
|
@ -3,9 +3,9 @@
|
||||||
* the table of seen ids in memory, but a production one would of course
|
* the table of seen ids in memory, but a production one would of course
|
||||||
* use a disk-backed database. */
|
* use a disk-backed database. */
|
||||||
|
|
||||||
|
use std::cmp::Eq;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::cmp::Eq;
|
|
||||||
|
|
||||||
/// Each instance of DupFilter maintains its own independent table of
|
/// Each instance of DupFilter maintains its own independent table of
|
||||||
/// seen ids. IdType will typically be Scalar.
|
/// seen ids. IdType will typically be Scalar.
|
||||||
|
|
|
@ -17,6 +17,8 @@ The notation follows that of the paper "Hyphae: Social Secret Sharing"
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate zkp;
|
extern crate zkp;
|
||||||
|
|
||||||
|
pub mod dup_filter;
|
||||||
|
|
||||||
use sha2::Sha512;
|
use sha2::Sha512;
|
||||||
|
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
use lox::dup_filter;
|
||||||
use lox::BridgeDb;
|
use lox::BridgeDb;
|
||||||
|
|
||||||
|
use curve25519_dalek::scalar::Scalar;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_openinvite() {
|
fn test_openinvite() {
|
||||||
let bdb = BridgeDb::new(20);
|
let bdb = BridgeDb::new(20);
|
||||||
|
@ -8,3 +11,35 @@ fn test_openinvite() {
|
||||||
let res = BridgeDb::verify(inv, bdb.pubkey);
|
let res = BridgeDb::verify(inv, bdb.pubkey);
|
||||||
println!("{:?}", res);
|
println!("{:?}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dup_filter() {
|
||||||
|
let mut df1: dup_filter::DupFilter<Scalar> = Default::default();
|
||||||
|
let mut df2: dup_filter::DupFilter<Scalar> = Default::default();
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let s1 = Scalar::random(&mut rng);
|
||||||
|
let s2 = Scalar::random(&mut rng);
|
||||||
|
let s3 = Scalar::random(&mut rng);
|
||||||
|
let s4 = Scalar::random(&mut rng);
|
||||||
|
let s5 = Scalar::random(&mut rng);
|
||||||
|
// Check basic behaviour
|
||||||
|
assert_eq!(df1.check(&s1), false);
|
||||||
|
assert_eq!(df1.filter(&s1), Ok(()));
|
||||||
|
assert_eq!(df1.check(&s1), true);
|
||||||
|
assert_eq!(df1.filter(&s1), Err(()));
|
||||||
|
// Ensure different instances of DupFilter have different tables
|
||||||
|
assert_eq!(df2.check(&s1), false);
|
||||||
|
assert_eq!(df2.filter(&s1), Ok(()));
|
||||||
|
assert_eq!(df2.filter(&s1), Err(()));
|
||||||
|
assert_eq!(df2.check(&s1), true);
|
||||||
|
// Check multiple ids
|
||||||
|
assert_eq!(df1.check(&s2), false);
|
||||||
|
assert_eq!(df1.filter(&s3), Ok(()));
|
||||||
|
assert_eq!(df1.filter(&s4), Ok(()));
|
||||||
|
assert_eq!(df1.filter(&s3), Err(()));
|
||||||
|
assert_eq!(df1.check(&s1), true);
|
||||||
|
assert_eq!(df1.filter(&s1), Err(()));
|
||||||
|
assert_eq!(df1.filter(&s5), Ok(()));
|
||||||
|
println!("df1 = {:?}", df1);
|
||||||
|
println!("df2 = {:?}", df2);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue