Skip to content

Commit

Permalink
ensures mmb bench checks are deteministic
Browse files Browse the repository at this point in the history
  • Loading branch information
gpestana committed May 10, 2024
1 parent d726d0f commit 3d4452f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::iter()
.map(|(n, noms)| (n, noms.targets.into_inner()))
Expand All @@ -1193,21 +1195,21 @@ 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]
{
v13::MigrationV13::<T, crate::weights::SubstrateWeight<T>>::step(None, &mut meter)
.unwrap();
}

assert_eq!(T::TargetList::count(), n_validators + 1);
assert_eq!(T::TargetList::count(), targets_count_before);
}

impl_benchmark_test_suite!(
Expand Down

0 comments on commit 3d4452f

Please sign in to comment.