Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn committed Oct 21, 2024
1 parent aea2d00 commit e2ee08e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ criterion = { version = "0.3", features = ["html_reports"] }
curve25519-dalek = { version = "4", features = ["rand_core"] }
rand = "0.8"
rand_core = "0.6"
tempfile = "3.13.0"

[[bench]]
harness = false
Expand Down
28 changes: 28 additions & 0 deletions src/compute/fixed_msm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ark_bls12_381::G1Affine;
use ark_std::UniformRand;
use curve25519_dalek::ristretto::RistrettoPoint;
use rand_core::OsRng;
use tempfile::TempDir;

#[test]
fn we_can_compute_msms_using_a_single_generator() {
Expand Down Expand Up @@ -48,6 +49,33 @@ fn we_can_compute_msms_using_multiple_generator() {
assert_eq!(res[0], generators[0] + generators[1] + generators[1]);
}

#[test]
fn we_can_serialize_a_handle_to_a_file() {
let mut rng = OsRng;

let mut res = vec![RistrettoPoint::default(); 1];

// randomly obtain the generator points
let generators: Vec<RistrettoPoint> =
(0..2).map(|_| RistrettoPoint::random(&mut rng)).collect();

// create handle
let handle = MsmHandle::new(&generators);

// write the handle to a file
let tmp_dir = TempDir::new().unwrap();
let filename = tmp_dir.path().join("t").to_str().unwrap().to_string();
handle.write(&filename);

// read the handle back from file
let handle = MsmHandle::<RistrettoPoint>::new_from_file(&filename);

// we can compute a multiexponentiation
let scalars: Vec<u8> = vec![1, 2];
handle.msm(&mut res, 1, &scalars);
assert_eq!(res[0], generators[0] + generators[1] + generators[1]);
}

#[test]
fn we_can_compute_msms_using_multiple_outputs() {
let mut rng = OsRng;
Expand Down

0 comments on commit e2ee08e

Please sign in to comment.