From 36458aefe7d8b2400ebcd9e2e1e5e10cc8881a5e Mon Sep 17 00:00:00 2001 From: galactus <96341601+godmodegalactus@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:56:37 +0100 Subject: [PATCH] Fixing by cu computation adding more tests to check by CU (#311) * Fixing by cu computation adding more tests to check by CU * Adding more tests --- block_priofees/src/stats_calculation.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block_priofees/src/stats_calculation.rs b/block_priofees/src/stats_calculation.rs index 4e3578fe..f409019e 100644 --- a/block_priofees/src/stats_calculation.rs +++ b/block_priofees/src/stats_calculation.rs @@ -45,7 +45,7 @@ pub fn calculate_supp_percentiles( let dist_fee_by_cu = (0..=100) .step_by(p_step) .map(|p| { - if agg < (cu_sum * p) / 100 { + while agg < (cu_sum * p) / 100 { index += 1; agg += prio_fees_in_block[index].1; } @@ -157,6 +157,8 @@ mod tests { let supp_info = calculate_supp_percentiles(&prio_fees_in_block); assert_eq!(supp_info.by_tx[5], 43); assert_eq!(supp_info.by_tx_percentiles[5], 0.25); + assert_eq!(supp_info.by_cu_percentiles[20], 1.0); + assert_eq!(supp_info.by_cu[20], 72); } #[test] @@ -179,6 +181,10 @@ mod tests { assert_eq!(supp_info.by_tx_percentiles[4], 0.20); assert_eq!(supp_info.by_tx[5], 5); + assert_eq!(supp_info.by_cu_percentiles[19], 0.95); + assert_eq!(supp_info.by_cu_percentiles[20], 1.0); + assert_eq!(supp_info.by_cu[19], 10); + assert_eq!(supp_info.by_cu[20], 10); } #[test]