From 3d4452f1cb4aed62bd8a74ad06109f41a49df583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Pestana?= Date: Fri, 10 May 2024 13:45:48 +0200 Subject: [PATCH] ensures mmb bench checks are deteministic --- substrate/frame/staking/src/benchmarking.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/substrate/frame/staking/src/benchmarking.rs b/substrate/frame/staking/src/benchmarking.rs index b63f00129d38..0aca10f20a25 100644 --- a/substrate/frame/staking/src/benchmarking.rs +++ b/substrate/frame/staking/src/benchmarking.rs @@ -1183,6 +1183,8 @@ mod benchmarks { ) .unwrap(); + let targets_count_before = T::TargetList::count(); + // drop targets from target list nominated by the one nominator to be migrated. let (_to_migrate, mut nominations) = Nominators::::iter() .map(|(n, noms)| (n, noms.targets.into_inner())) @@ -1193,13 +1195,13 @@ mod benchmarks { nominations.sort(); nominations.dedup(); + // drop targets nominated by the first nominator. for t in nominations.iter() { assert_ok!(T::TargetList::on_remove(&t)); } - // targets nominated by first nominator will be dropped from the target list. - // note: +1 because there is one extra validator added by the test setup. - assert_eq!(T::TargetList::count(), n_validators + 1 - nominations.len() as u32); + // confirm targets dropped. + assert!(T::TargetList::count() < targets_count_before); #[block] { @@ -1207,7 +1209,7 @@ mod benchmarks { .unwrap(); } - assert_eq!(T::TargetList::count(), n_validators + 1); + assert_eq!(T::TargetList::count(), targets_count_before); } impl_benchmark_test_suite!(