Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Sep 22, 2024
1 parent c02eb61 commit ccff4dc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 65 deletions.
7 changes: 4 additions & 3 deletions src/bls12381/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ impl ExtField for Fq2 {
mod test {

use super::*;
use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius};
use crate::{
arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius,
};
use rand_core::RngCore;

// constants_test!(Fq2);
constants_test!(Fq2);

arith_test!(Fq2);
legendre_test!(Fq2);
test!(arith, Fq2, sqrt_test, 1000);

serde_test!(Fq2);
// test_uniform_bytes!(Fq2, 1000, L 96);

f2_tests!(Fq2, Fq);
test_frobenius!(Fq2, Fq, 20);
Expand Down
38 changes: 4 additions & 34 deletions src/bn256/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,52 +68,22 @@ impl ExtField for Fq2 {
mod test {

use super::*;
use crate::{arith_test, f2_tests, legendre_test, serde_test, test, test_frobenius};
use crate::{
arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius,
};
use rand_core::RngCore;

// constants_test!(Fq2);

constants_test!(Fq2);
arith_test!(Fq2);
legendre_test!(Fq2);
test!(arith, Fq2, sqrt_test, 1000);

serde_test!(Fq2);
// test_uniform_bytes!(Fq2, 1000, L 96);

f2_tests!(Fq2, Fq);
test_frobenius!(Fq2, Fq, 20);

#[test]
fn test_fq2_squaring() {
let mut a = Fq2 {
c0: Fq::one(),
c1: Fq::one(),
}; // u + 1
a.square_assign();
assert_eq!(
a,
Fq2 {
c0: Fq::zero(),
c1: Fq::one() + Fq::one(),
}
); // 2u

let mut a = Fq2 {
c0: Fq::zero(),
c1: Fq::one(),
}; // u
a.square_assign();
assert_eq!(a, {
let neg1 = -Fq::one();
Fq2 {
c0: neg1,
c1: Fq::zero(),
}
}); // -1
}

#[test]

fn test_fq2_mul_nonresidue() {
let e = Fq2::random(rand_core::OsRng);
let a0 = e.mul_by_nonresidue();
Expand Down
3 changes: 1 addition & 2 deletions src/pluto_eris/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ExtField for Fp2 {
mod test {

use super::*;
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};
use crate::{arith_test, constants_test, legendre_test, serde_test, test};
use rand_core::RngCore;

constants_test!(Fp2);
Expand All @@ -90,7 +90,6 @@ mod test {
test!(arith, Fp2, sqrt_test, 1000);

serde_test!(Fp2);
test_uniform_bytes!(Fp2, 1000, L 128);

crate::f2_tests!(Fp2, Fp);
crate::test_frobenius!(Fp2, Fp, 20);
Expand Down
2 changes: 0 additions & 2 deletions src/secp256k1/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ mod test {
use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes};

constants_test!(Fp);

arith_test!(Fp);
legendre_test!(Fp);
test!(arith, Fp, sqrt_test, 1000);

serde_test!(Fp PrimeFieldBits);
test_uniform_bytes!(Fp, 1000, L 64, L 48);
}
25 changes: 1 addition & 24 deletions src/tests/field/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ where
}
}

// Test from_raw_bytes / to_raw_bytes
// TODO: Is this test redundant? It uses methods that are not exposed.
// IMO this can be removed.
// fn test_serialization_check<F: Field>(mut rng: impl RngCore, n: usize) {
// use crate::serde::SerdeObject;
// const LIMBS: usize = F::SIZE / 8;
// // failure check
// for _ in 0..n {
// let rand_word = [(); LIMBS].map(|_| rng.next_u64());
// let a = F(rand_word);
// let rand_bytes = a.to_raw_bytes();

// match F::is_less_than_modulus(&rand_word) {
// false => {
// assert!(F::from_raw_bytes(&rand_bytes).is_none());
// }
// _ => {
// assert_eq!(F::from_raw_bytes(&rand_bytes), Some(a));
// }
// }
// }
// }

#[cfg(feature = "bits")]
pub(crate) fn test_bits<F: ff::PrimeFieldBits>(mut rng: impl RngCore, n: usize) {
for _ in 0..n {
Expand Down Expand Up @@ -104,7 +81,7 @@ macro_rules! serde_test {
}

// Out of serde_tests macro, since it needs to be tested for several generic L.
// Tests from_uniform_bytes.
// Tests from_uniform_bytes **for prime fields only**.
pub(crate) fn from_uniform_bytes_test<F: PrimeField, const L: usize>(
mut rng: impl RngCore,
n: usize,
Expand Down

0 comments on commit ccff4dc

Please sign in to comment.