tests.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use lox::dup_filter;
  2. use lox::dup_filter::SeenType::{Fresh, Seen};
  3. use lox::BridgeDb;
  4. use curve25519_dalek::scalar::Scalar;
  5. #[test]
  6. fn test_bridgedb() {
  7. let mut bdb = BridgeDb::new();
  8. for i in &[1u32, 5, 7, 12, 19, 20, 22] {
  9. bdb.insert_openinv(*i);
  10. }
  11. let inv = bdb.invite();
  12. println!("{:?}", inv);
  13. let res = BridgeDb::verify(inv, bdb.pubkey);
  14. println!("{:?}", res);
  15. }
  16. #[test]
  17. fn test_dup_filter() {
  18. let mut df1: dup_filter::DupFilter<Scalar> = Default::default();
  19. let mut df2: dup_filter::DupFilter<Scalar> = Default::default();
  20. let mut rng = rand::thread_rng();
  21. let s1 = Scalar::random(&mut rng);
  22. let s2 = Scalar::random(&mut rng);
  23. let s3 = Scalar::random(&mut rng);
  24. let s4 = Scalar::random(&mut rng);
  25. let s5 = Scalar::random(&mut rng);
  26. // Check basic behaviour
  27. assert_eq!(df1.check(&s1), Fresh);
  28. assert_eq!(df1.filter(&s1), Fresh);
  29. assert_eq!(df1.check(&s1), Seen);
  30. assert_eq!(df1.filter(&s1), Seen);
  31. // Ensure different instances of DupFilter have different tables
  32. assert_eq!(df2.check(&s1), Fresh);
  33. assert_eq!(df2.filter(&s1), Fresh);
  34. assert_eq!(df2.filter(&s1), Seen);
  35. assert_eq!(df2.check(&s1), Seen);
  36. // Check multiple ids
  37. assert_eq!(df1.check(&s2), Fresh);
  38. assert_eq!(df1.filter(&s3), Fresh);
  39. assert_eq!(df1.filter(&s4), Fresh);
  40. assert_eq!(df1.filter(&s3), Seen);
  41. assert_eq!(df1.check(&s1), Seen);
  42. assert_eq!(df1.filter(&s1), Seen);
  43. assert_eq!(df1.filter(&s5), Fresh);
  44. println!("df1 = {:?}", df1);
  45. println!("df2 = {:?}", df2);
  46. }