From 747f71ca80db6994ed839dc79eac2b52abb3915a Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 15 Jun 2021 13:37:12 +0800 Subject: [PATCH] constants.rs: Add unit tests for T_P, T_Q constants. --- src/constants.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/constants.rs b/src/constants.rs index 4c488692..d6002c4a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -268,7 +268,7 @@ fn test_zs_and_us(base: C, z: &[u64], u: &[[[u8; 32]; H]], num_w #[cfg(test)] mod tests { use ff::PrimeField; - use pasta_curves::pallas; + use pasta_curves::{arithmetic::FieldExt, pallas}; #[test] // Nodes in the Merkle tree are Pallas base field elements. @@ -287,4 +287,18 @@ mod tests { fn l_orchard_scalar() { assert_eq!(super::L_ORCHARD_SCALAR, pallas::Scalar::NUM_BITS as usize); } + + #[test] + fn t_q() { + let t_q = pallas::Scalar::from_u128(super::T_Q); + let two_pow_254 = pallas::Scalar::from_u128(1 << 127).square(); + assert_eq!(t_q + two_pow_254, pallas::Scalar::zero()); + } + + #[test] + fn t_p() { + let t_p = pallas::Base::from_u128(super::T_P); + let two_pow_254 = pallas::Base::from_u128(1 << 127).square(); + assert_eq!(t_p + two_pow_254, pallas::Base::zero()); + } }