@@ -216,89 +216,89 @@ pub fn bigrational_as_fixed_point<const N: usize>(
216216// Threshold::new(delegated_stake, total_currency).threshold_met(vrf_out)
217217// }
218218
219- // #[cfg(test)]
220- // mod test {
221- // use std::str::FromStr;
222-
223- // use ark_ff::{One, Zero};
224- // use num::{BigInt, BigRational, ToPrimitive};
225-
226- // use super::*;
227-
228- // // TODO: move to regular fns, rework step
229- // fn first_non_zero(stake: BigInt, total_currency: BigInt, step: BigInt) -> BigInt {
230- // let ten = BigInt::from_str("10").unwrap();
231- // let mut stake = stake;
232- // if step == BigInt::zero() {
233- // stake + BigInt::one()
234- // } else {
235- // loop {
236- // let thrs = Threshold::new(stake.to_digits (), total_currency.to_digits ());
237-
238- // if thrs.threshold_rational != BigRational::zero() {
239- // println!("stake: {stake} nanoMINA");
240- // return first_non_zero(stake - step.clone(), total_currency, step / ten);
241- // }
242- // stake += step.clone();
243- // }
244- // }
245- // }
246-
247- // #[test]
248- // #[ignore]
249- // fn test_threshold_nonzero() {
250- // // let total_currency = BigInt::from_str("1157953132840039233").unwrap();
251- // // let initial_stake = BigInt::zero();
252- // // let initial_step = BigInt::from_str("10000000000000000000").unwrap();
253-
254- // let total_currency = BigInt::from_str("1025422352000001000").unwrap();
255- // let initial_stake = BigInt::zero();
256- // let initial_step = BigInt::from_str("10000000000000000000").unwrap();
257-
258- // let first_non_zero_nanomina =
259- // first_non_zero(initial_stake, total_currency.clone(), initial_step);
260-
261- // let last_zero = first_non_zero_nanomina.clone() - BigInt::one();
262-
263- // let thrs_zero = Threshold::new(last_zero, total_currency.clone());
264- // assert_eq!(thrs_zero.threshold_rational, BigRational::zero());
265-
266- // let thrs_first = Threshold::new(first_non_zero_nanomina.clone(), total_currency);
267- // assert!(thrs_first.threshold_rational > BigRational::zero());
268-
269- // let first_non_zero_mina = first_non_zero_nanomina.to_f64().unwrap() / 1_000_000_000.0;
270-
271- // println!("First non zero stake: {first_non_zero_mina} MINA");
272- // println!(
273- // "First non zero threshold: {}",
274- // thrs_first.threshold_rational.to_f64().unwrap()
275- // );
276- // }
277-
278- // #[test]
279- // #[ignore]
280- // fn test_threshold_increase() {
281- // // let total_currency = BigInt::from_str("1157953132840039233").unwrap();
282- // // let mut stake_nanomina = BigInt::from_str("1104310162392").unwrap();
283- // // let mut step = BigInt::from_str("1000000000000").unwrap();
284-
285- // let total_currency = BigInt::from_str("1025422352000001000").unwrap();
286- // let mut stake_nanomina = BigInt::from_str("2000000000000000").unwrap();
287- // let mut step = BigInt::from_str("1000000000000").unwrap();
288-
289- // loop {
290- // if stake_nanomina > total_currency {
291- // break;
292- // }
293- // let thrs = Threshold::new(stake_nanomina.clone(), total_currency.clone());
294- // let stake_mina = stake_nanomina.to_f64().unwrap() / 1_000_000_000.0;
295- // println!(
296- // "stake: {stake_mina} MINA - threshold: {}",
297- // thrs.threshold_rational.to_f64().unwrap()
298- // );
299-
300- // stake_nanomina += step.clone();
301- // step *= 2;
302- // }
303- // }
304- // }
219+ #[ cfg( test) ]
220+ mod test {
221+ use std:: str:: FromStr ;
222+
223+ use ark_ff:: { One , Zero } ;
224+ use num:: { BigInt , BigRational , ToPrimitive } ;
225+
226+ use super :: * ;
227+
228+ // TODO: move to regular fns, rework step
229+ fn first_non_zero ( stake : BigInt , total_currency : BigInt , step : BigInt ) -> BigInt {
230+ let ten = BigInt :: from_str ( "10" ) . unwrap ( ) ;
231+ let mut stake = stake;
232+ if step == BigInt :: zero ( ) {
233+ stake + BigInt :: one ( )
234+ } else {
235+ loop {
236+ let thrs = Threshold :: new ( stake. clone ( ) , total_currency. clone ( ) ) ;
237+
238+ if thrs. threshold_rational != BigRational :: zero ( ) {
239+ println ! ( "stake: {stake} nanoMINA" ) ;
240+ return first_non_zero ( stake - step. clone ( ) , total_currency, step / ten) ;
241+ }
242+ stake += step. clone ( ) ;
243+ }
244+ }
245+ }
246+
247+ #[ test]
248+ #[ ignore]
249+ fn test_threshold_nonzero ( ) {
250+ // let total_currency = BigInt::from_str("1157953132840039233").unwrap();
251+ // let initial_stake = BigInt::zero();
252+ // let initial_step = BigInt::from_str("10000000000000000000").unwrap();
253+
254+ let total_currency = BigInt :: from_str ( "1025422352000001000" ) . unwrap ( ) ;
255+ let initial_stake = BigInt :: zero ( ) ;
256+ let initial_step = BigInt :: from_str ( "10000000000000000000" ) . unwrap ( ) ;
257+
258+ let first_non_zero_nanomina =
259+ first_non_zero ( initial_stake, total_currency. clone ( ) , initial_step) ;
260+
261+ let last_zero = first_non_zero_nanomina. clone ( ) - BigInt :: one ( ) ;
262+
263+ let thrs_zero = Threshold :: new ( last_zero, total_currency. clone ( ) ) ;
264+ assert_eq ! ( thrs_zero. threshold_rational, BigRational :: zero( ) ) ;
265+
266+ let thrs_first = Threshold :: new ( first_non_zero_nanomina. clone ( ) , total_currency) ;
267+ assert ! ( thrs_first. threshold_rational > BigRational :: zero( ) ) ;
268+
269+ let first_non_zero_mina = first_non_zero_nanomina. to_f64 ( ) . unwrap ( ) / 1_000_000_000.0 ;
270+
271+ println ! ( "First non zero stake: {first_non_zero_mina} MINA" ) ;
272+ println ! (
273+ "First non zero threshold: {}" ,
274+ thrs_first. threshold_rational. to_f64( ) . unwrap( )
275+ ) ;
276+ }
277+
278+ #[ test]
279+ #[ ignore]
280+ fn test_threshold_increase ( ) {
281+ // let total_currency = BigInt::from_str("1157953132840039233").unwrap();
282+ // let mut stake_nanomina = BigInt::from_str("1104310162392").unwrap();
283+ // let mut step = BigInt::from_str("1000000000000").unwrap();
284+
285+ let total_currency = BigInt :: from_str ( "1025422352000001000" ) . unwrap ( ) ;
286+ let mut stake_nanomina = BigInt :: from_str ( "2000000000000000" ) . unwrap ( ) ;
287+ let mut step = BigInt :: from_str ( "1000000000000" ) . unwrap ( ) ;
288+
289+ loop {
290+ if stake_nanomina > total_currency {
291+ break ;
292+ }
293+ let thrs = Threshold :: new ( stake_nanomina. clone ( ) , total_currency. clone ( ) ) ;
294+ let stake_mina = stake_nanomina. to_f64 ( ) . unwrap ( ) / 1_000_000_000.0 ;
295+ println ! (
296+ "stake: {stake_mina} MINA - threshold: {}" ,
297+ thrs. threshold_rational. to_f64( ) . unwrap( )
298+ ) ;
299+
300+ stake_nanomina += step. clone ( ) ;
301+ step *= 2 ;
302+ }
303+ }
304+ }
0 commit comments