diff --git a/src/bls12381/fq.rs b/src/bls12381/fq.rs index f425c52b..11320f22 100644 --- a/src/bls12381/fq.rs +++ b/src/bls12381/fq.rs @@ -37,7 +37,9 @@ impl ExtField for Fq { #[cfg(test)] mod test { use super::*; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fq); @@ -46,7 +48,7 @@ mod test { test!(arith, Fq, sqrt_test, 1000); serde_test!(Fq PrimeFieldBits); - test_uniform_bytes!(Fq, 1000, L 64, L 96); + from_uniform_bytes_test!(Fq, 1000, L 64, L 96); #[test] fn test_fq_mul_nonresidue() { diff --git a/src/bls12381/fq12.rs b/src/bls12381/fq12.rs index 8f11de93..e81006d0 100644 --- a/src/bls12381/fq12.rs +++ b/src/bls12381/fq12.rs @@ -282,7 +282,7 @@ mod test { }; } use super::*; - use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test}; use ff::Field; use rand::RngCore; @@ -294,5 +294,5 @@ mod test { setup_f12_test_funcs!(Fq12, Fq6, Fq2); test_fq12!(f12_mul_by_014_, 500); test_fq12!(f12_mul_by_034_, 500); - test_frobenius!(Fq12, Fq, 8); + frobenius_test!(Fq12, Fq, 8); } diff --git a/src/bls12381/fq2.rs b/src/bls12381/fq2.rs index 21757810..d88f286e 100644 --- a/src/bls12381/fq2.rs +++ b/src/bls12381/fq2.rs @@ -66,7 +66,7 @@ mod test { use super::*; use crate::{ - arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius, + arith_test, constants_test, f2_test, frobenius_test, legendre_test, serde_test, test, }; use rand_core::RngCore; @@ -78,8 +78,8 @@ mod test { serde_test!(Fq2); - f2_tests!(Fq2, Fq); - test_frobenius!(Fq2, Fq, 20); + f2_test!(Fq2, Fq); + frobenius_test!(Fq2, Fq, 20); #[test] fn test_fq2_mul_nonresidue() { diff --git a/src/bls12381/fq6.rs b/src/bls12381/fq6.rs index deee0e5a..19fe7b0a 100644 --- a/src/bls12381/fq6.rs +++ b/src/bls12381/fq6.rs @@ -277,7 +277,7 @@ pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [ #[cfg(test)] mod test { use super::*; - use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test}; use rand_core::RngCore; macro_rules! test_fq6 { @@ -299,7 +299,7 @@ mod test { test_fq6!(f6_mul_nonresidue_, 1000); test_fq6!(f6_mul_by_1_, 1000); test_fq6!(f6_mul_by_01_, 1000); - test_frobenius!(Fq6, Fq, 10); + frobenius_test!(Fq6, Fq, 10); #[test] fn test_fq6_mul_nonresidue() { diff --git a/src/bls12381/fr.rs b/src/bls12381/fr.rs index 7c771cf0..67a06b29 100644 --- a/src/bls12381/fr.rs +++ b/src/bls12381/fr.rs @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fr); #[cfg(test)] mod test { use super::Fr; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fr); @@ -34,5 +36,5 @@ mod test { test!(arith, Fr, sqrt_test, 1000); serde_test!(Fr PrimeFieldBits); - test_uniform_bytes!(Fr, 1000, L 64); + from_uniform_bytes_test!(Fr, 1000, L 64); } diff --git a/src/bn256/fq.rs b/src/bn256/fq.rs index e45d52d6..d3fa7fbc 100644 --- a/src/bn256/fq.rs +++ b/src/bn256/fq.rs @@ -36,7 +36,9 @@ impl ExtField for Fq { #[cfg(test)] mod test { use super::Fq; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fq); @@ -45,5 +47,5 @@ mod test { test!(arith, Fq, sqrt_test, 1000); serde_test!(Fq PrimeFieldBits); - test_uniform_bytes!(Fq, 1000, L 64, L 48); + from_uniform_bytes_test!(Fq, 1000, L 64, L 48); } diff --git a/src/bn256/fq12.rs b/src/bn256/fq12.rs index d390d398..c6186ac7 100644 --- a/src/bn256/fq12.rs +++ b/src/bn256/fq12.rs @@ -210,17 +210,15 @@ mod test { }; } use super::*; - use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test}; use ff::Field; use rand::RngCore; arith_test!(Fq12); - // TODO Compile problems with derive_serde feature - // serde_test!(Fq12); // F12 specific setup_f12_test_funcs!(Fq12, Fq6, Fq2); test_fq12!(f12_mul_by_014_, 500); test_fq12!(f12_mul_by_034_, 500); - test_frobenius!(Fq12, Fq, 8); + frobenius_test!(Fq12, Fq, 8); } diff --git a/src/bn256/fq2.rs b/src/bn256/fq2.rs index d1618871..2aa478ac 100644 --- a/src/bn256/fq2.rs +++ b/src/bn256/fq2.rs @@ -69,7 +69,7 @@ mod test { use super::*; use crate::{ - arith_test, constants_test, f2_tests, legendre_test, serde_test, test, test_frobenius, + arith_test, constants_test, f2_test, frobenius_test, legendre_test, serde_test, test, }; use rand_core::RngCore; @@ -80,8 +80,8 @@ mod test { serde_test!(Fq2); - f2_tests!(Fq2, Fq); - test_frobenius!(Fq2, Fq, 20); + f2_test!(Fq2, Fq); + frobenius_test!(Fq2, Fq, 20); #[test] fn test_fq2_mul_nonresidue() { diff --git a/src/bn256/fq6.rs b/src/bn256/fq6.rs index 480db5a7..fcdef910 100644 --- a/src/bn256/fq6.rs +++ b/src/bn256/fq6.rs @@ -204,7 +204,7 @@ pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [ #[cfg(test)] mod test { use super::*; - use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test}; use rand_core::RngCore; macro_rules! test_fq6 { @@ -226,6 +226,5 @@ mod test { test_fq6!(f6_mul_nonresidue_, 1000); test_fq6!(f6_mul_by_1_, 1000); test_fq6!(f6_mul_by_01_, 1000); - test_frobenius!(Fq6, Fq, 10); - // test_uniform_bytes!(Fq6, 1000, L 96); + frobenius_test!(Fq6, Fq, 10); } diff --git a/src/bn256/fr.rs b/src/bn256/fr.rs index 00980dae..edc1e02c 100644 --- a/src/bn256/fr.rs +++ b/src/bn256/fr.rs @@ -46,7 +46,9 @@ mod table_tests; #[cfg(test)] mod test { use super::Fr; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fr); @@ -55,5 +57,5 @@ mod test { test!(arith, Fr, sqrt_test, 1000); serde_test!(Fr PrimeFieldBits); - test_uniform_bytes!(Fr, 1000, L 64, L 48); + from_uniform_bytes_test!(Fr, 1000, L 64, L 48); } diff --git a/src/pluto_eris/fp.rs b/src/pluto_eris/fp.rs index 5c95b062..7f85ef46 100644 --- a/src/pluto_eris/fp.rs +++ b/src/pluto_eris/fp.rs @@ -42,7 +42,9 @@ impl ExtField for Fp { #[cfg(test)] mod test { use super::Fp; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fp); @@ -51,5 +53,5 @@ mod test { test!(arith, Fp, sqrt_test, 1000); serde_test!(Fp PrimeFieldBits); - test_uniform_bytes!(Fp, 1000, L 64, L 72, L 112); + from_uniform_bytes_test!(Fp, 1000, L 64, L 72, L 112); } diff --git a/src/pluto_eris/fp12.rs b/src/pluto_eris/fp12.rs index 9b48f7db..31a7776f 100644 --- a/src/pluto_eris/fp12.rs +++ b/src/pluto_eris/fp12.rs @@ -268,17 +268,15 @@ mod test { }; } use super::*; - use crate::{arith_test, setup_f12_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test}; use ff::Field; use rand::RngCore; arith_test!(Fp12); - // TODO Compile problems with derive_serde feature - // serde_test!(fp12); // F12 specific setup_f12_test_funcs!(Fp12, Fp6, Fp2); test_fp12!(f12_mul_by_014_, 500); test_fp12!(f12_mul_by_034_, 500); - test_frobenius!(Fp12, Fp, 8); + frobenius_test!(Fp12, Fp, 8); } diff --git a/src/pluto_eris/fp2.rs b/src/pluto_eris/fp2.rs index 5dd98d12..b7e9024e 100644 --- a/src/pluto_eris/fp2.rs +++ b/src/pluto_eris/fp2.rs @@ -91,8 +91,8 @@ mod test { serde_test!(Fp2); - crate::f2_tests!(Fp2, Fp); - crate::test_frobenius!(Fp2, Fp, 20); + crate::f2_test!(Fp2, Fp); + crate::frobenius_test!(Fp2, Fp, 20); #[test] fn test_fp2_squaring() { diff --git a/src/pluto_eris/fp6.rs b/src/pluto_eris/fp6.rs index 18129f53..9b8df7db 100644 --- a/src/pluto_eris/fp6.rs +++ b/src/pluto_eris/fp6.rs @@ -251,7 +251,7 @@ pub(crate) const FROBENIUS_COEFF_FP6_C2: [Fp2; 6] = [ #[cfg(test)] mod test { use super::*; - use crate::{arith_test, setup_f6_test_funcs, test, test_frobenius}; + use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test}; use rand_core::RngCore; macro_rules! test_fp6 { @@ -273,7 +273,7 @@ mod test { test_fp6!(f6_mul_nonresidue_, 1000); test_fp6!(f6_mul_by_1_, 1000); test_fp6!(f6_mul_by_01_, 1000); - test_frobenius!(Fp6, Fp, 10); + frobenius_test!(Fp6, Fp, 10); #[test] fn test_fp6_mul_nonresidue() { diff --git a/src/pluto_eris/fq.rs b/src/pluto_eris/fq.rs index baa4b76c..f1717576 100644 --- a/src/pluto_eris/fq.rs +++ b/src/pluto_eris/fq.rs @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq); #[cfg(test)] mod test { use super::Fq; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fq); @@ -34,5 +36,5 @@ mod test { test!(arith, Fq, sqrt_test, 1000); serde_test!(Fq PrimeFieldBits); - test_uniform_bytes!(Fq, 1000, L 64, L 72, L 112); + from_uniform_bytes_test!(Fq, 1000, L 64, L 72, L 112); } diff --git a/src/secp256k1/fp.rs b/src/secp256k1/fp.rs index b2bec7d5..8f036576 100644 --- a/src/secp256k1/fp.rs +++ b/src/secp256k1/fp.rs @@ -25,12 +25,14 @@ crate::impl_from_bool!(Fp); #[cfg(test)] mod test { use super::Fp; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; 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); + from_uniform_bytes_test!(Fp, 1000, L 64, L 48); } diff --git a/src/secp256k1/fq.rs b/src/secp256k1/fq.rs index 85dcff81..037d51f0 100644 --- a/src/secp256k1/fq.rs +++ b/src/secp256k1/fq.rs @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq); #[cfg(test)] mod test { use super::Fq; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fq); @@ -34,5 +36,5 @@ mod test { test!(arith, Fq, sqrt_test, 1000); serde_test!(Fq); - test_uniform_bytes!(Fq, 1000, L 64, L 48); + from_uniform_bytes_test!(Fq, 1000, L 64, L 48); } diff --git a/src/secp256r1/fp.rs b/src/secp256r1/fp.rs index f25080f9..ce423d5d 100644 --- a/src/secp256r1/fp.rs +++ b/src/secp256r1/fp.rs @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fp); #[cfg(test)] mod test { use super::Fp; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fp); @@ -34,5 +36,5 @@ mod test { test!(arith, Fp, sqrt_test, 1000); serde_test!(Fp PrimeFieldBits); - test_uniform_bytes!(Fp, 1000, L 64, L 48); + from_uniform_bytes_test!(Fp, 1000, L 64, L 48); } diff --git a/src/secp256r1/fq.rs b/src/secp256r1/fq.rs index 3372f2c3..8e0c1071 100644 --- a/src/secp256r1/fq.rs +++ b/src/secp256r1/fq.rs @@ -25,7 +25,9 @@ crate::impl_from_bool!(Fq); #[cfg(test)] mod test { use super::Fq; - use crate::{arith_test, constants_test, legendre_test, serde_test, test, test_uniform_bytes}; + use crate::{ + arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test, + }; constants_test!(Fq); @@ -34,5 +36,5 @@ mod test { test!(arith, Fq, sqrt_test, 1000); serde_test!(Fq PrimeFieldBits); - test_uniform_bytes!(Fq, 1000, L 64, L 48); + from_uniform_bytes_test!(Fq, 1000, L 64, L 48); } diff --git a/src/tests/field/extensions.rs b/src/tests/field/extensions.rs index 4c1b2a38..a0079c85 100644 --- a/src/tests/field/extensions.rs +++ b/src/tests/field/extensions.rs @@ -1,6 +1,6 @@ // F2 tests #[macro_export] -macro_rules! f2_tests { +macro_rules! f2_test { ($ext_field:ident, $base_field:ident) => { #[test] @@ -177,7 +177,7 @@ macro_rules! setup_f12_test_funcs { } #[macro_export] -macro_rules! test_frobenius { +macro_rules! frobenius_test { ($field:ident, $base: ident, $size: expr) => { fn test_frobenius(mut rng: impl RngCore, n: usize) { for _ in 0..n { diff --git a/src/tests/field/legendre.rs b/src/tests/field/legendre.rs index 29e32d25..ad65e477 100644 --- a/src/tests/field/legendre.rs +++ b/src/tests/field/legendre.rs @@ -3,6 +3,7 @@ use ff::PrimeField; use rand::RngCore; pub(crate) fn legendre_symbol_test(mut rng: impl RngCore, n: usize) { + assert_eq!(F::ZERO.legendre(), 0); for _ in 0..n { let a = F::random(&mut rng); if a.legendre() == -1 { diff --git a/src/tests/field/serde.rs b/src/tests/field/serde.rs index f65086e3..9192b09b 100644 --- a/src/tests/field/serde.rs +++ b/src/tests/field/serde.rs @@ -68,7 +68,6 @@ macro_rules! serde_test { ($field:ident) => { test!(serde, $field, from_to_repr_test, 100_000); test!(serde, $field, from_to_raw_bytes_test, 100_000); - // test!($field, test_serialization_check, 1_000_000); #[cfg(feature = "derive_serde")] test!(serde, $field, derive_serde_test, 100_000); }; @@ -107,7 +106,7 @@ pub(crate) fn from_uniform_bytes_test( } #[macro_export] -macro_rules! test_uniform_bytes { +macro_rules! from_uniform_bytes_test { ($field:ident, $size:expr, L $L: expr ) => { paste::paste! { #[test] @@ -122,7 +121,7 @@ macro_rules! test_uniform_bytes { }; ($field:ident,$size:expr, L $L:expr, $(L $rest:expr),+ ) => { - test_uniform_bytes!( $field, $size, L $L ); - test_uniform_bytes! { $field, $size, $(L $rest),+ } + from_uniform_bytes_test!( $field, $size, L $L ); + from_uniform_bytes_test! { $field, $size, $(L $rest),+ } }; }