From d3440f9733be9a2d980522db9452f3e19385e680 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 21 Sep 2021 10:39:58 +1000 Subject: [PATCH] Use Oracle::MAX_DIGITS where possible in tests --- cfd_protocol/tests/cfds.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cfd_protocol/tests/cfds.rs b/cfd_protocol/tests/cfds.rs index 650e153..976b694 100644 --- a/cfd_protocol/tests/cfds.rs +++ b/cfd_protocol/tests/cfds.rs @@ -834,7 +834,7 @@ impl Oracle { nonces: &[SecretKey; Self::MAX_DIGITS], ) -> Vec { let mut bits = BitVec::from_bytes(&price.to_be_bytes()); - let bits = bits.split_off(bits.len() - 20); + let bits = bits.split_off(bits.len() - Self::MAX_DIGITS); bits.iter() .zip(nonces) @@ -862,8 +862,12 @@ struct Event { impl Event { fn new(rng: &mut (impl RngCore + CryptoRng)) -> Self { - let (nonces, nonce_pks) = (0..20).map(|_| nonce(rng)).unzip::<_, _, Vec<_>, _>(); - let nonces = nonces.try_into().expect("20 nonces"); + let (nonces, nonce_pks) = (0..Oracle::MAX_DIGITS) + .map(|_| nonce(rng)) + .unzip::<_, _, Vec<_>, _>(); + let nonces = nonces + .try_into() + .unwrap_or_else(|_| panic!("{} nonces", Oracle::MAX_DIGITS)); Self { nonces, nonce_pks } }