From e2ee08e2f90df995b09bbc5c8e20f610053b310b Mon Sep 17 00:00:00 2001 From: rnburn Date: Mon, 21 Oct 2024 10:49:52 -0700 Subject: [PATCH] add test --- Cargo.toml | 1 + src/compute/fixed_msm_tests.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 565cf41..2af426f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/compute/fixed_msm_tests.rs b/src/compute/fixed_msm_tests.rs index 17d4778..8629ad9 100644 --- a/src/compute/fixed_msm_tests.rs +++ b/src/compute/fixed_msm_tests.rs @@ -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() { @@ -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 = + (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::::new_from_file(&filename); + + // we can compute a multiexponentiation + let scalars: Vec = 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;