Reduce the execution time of some tests (#10377)

* Reduce the execution time of some tests

* Fix

* Fix build

* fmt
This commit is contained in:
Kian Paimani
2021-11-28 13:47:33 +01:00
committed by GitHub
parent 1fed3540ba
commit 2fafb9546e
12 changed files with 68 additions and 229 deletions
+9 -8
View File
@@ -41,10 +41,11 @@ use frame_system::RawOrigin;
const SEED: u32 = 0;
const MAX_SPANS: u32 = 100;
const MAX_VALIDATORS: u32 = 1000;
const MAX_NOMINATORS: u32 = 1000;
const MAX_SLASHES: u32 = 1000;
type MaxValidators<T> = <<T as Config>::BenchmarkingConfig as BenchmarkingConfig>::MaxValidators;
type MaxNominators<T> = <<T as Config>::BenchmarkingConfig as BenchmarkingConfig>::MaxNominators;
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
// read and write operations.
fn add_slashing_spans<T: Config>(who: &T::AccountId, spans: u32) {
@@ -481,7 +482,7 @@ benchmarks! {
}
set_validator_count {
let validator_count = MAX_VALIDATORS;
let validator_count = MaxValidators::<T>::get();
}: _(RawOrigin::Root, validator_count)
verify {
assert_eq!(ValidatorCount::<T>::get(), validator_count);
@@ -498,7 +499,7 @@ benchmarks! {
// Worst case scenario, the list of invulnerables is very long.
set_invulnerables {
let v in 0 .. MAX_VALIDATORS;
let v in 0 .. MaxValidators::<T>::get();
let mut invulnerables = Vec::new();
for i in 0 .. v {
invulnerables.push(account("invulnerable", i, SEED));
@@ -804,9 +805,9 @@ benchmarks! {
get_npos_voters {
// number of validator intention.
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
let v in (MaxValidators::<T>::get() / 2) .. MaxValidators::<T>::get();
// number of nominator intention.
let n in (MAX_NOMINATORS / 2) .. MAX_NOMINATORS;
let n in (MaxNominators::<T>::get() / 2) .. MaxNominators::<T>::get();
// total number of slashing spans. Assigned to validators randomly.
let s in 1 .. 20;
@@ -829,9 +830,9 @@ benchmarks! {
get_npos_targets {
// number of validator intention.
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
let v in (MaxValidators::<T>::get() / 2) .. MaxValidators::<T>::get();
// number of nominator intention.
let n = MAX_NOMINATORS;
let n = MaxNominators::<T>::get();
let _ = create_validators_with_nominators_for_era::<T>(
v, n, T::MAX_NOMINATIONS as usize, false, None
+21 -1
View File
@@ -301,7 +301,7 @@ mod pallet;
use codec::{Decode, Encode, HasCompact};
use frame_support::{
traits::{Currency, Get},
traits::{ConstU32, Currency, Get},
weights::Weight,
};
use scale_info::TypeInfo;
@@ -807,3 +807,23 @@ where
R::is_known_offence(offenders, time_slot)
}
}
/// Configurations of the benchmarking of the pallet.
pub trait BenchmarkingConfig {
/// The maximum number of validators to use.
type MaxValidators: Get<u32>;
/// The maximum number of nominators to use.
type MaxNominators: Get<u32>;
}
/// A mock benchmarking config for pallet-staking.
///
/// Should only be used for testing.
#[cfg(feature = "std")]
pub struct TestBenchmarkingConfig;
#[cfg(feature = "std")]
impl BenchmarkingConfig for TestBenchmarkingConfig {
type MaxValidators = ConstU32<100>;
type MaxNominators = ConstU32<100>;
}
+2 -1
View File
@@ -272,9 +272,10 @@ impl crate::pallet::pallet::Config for Test {
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type ElectionProvider = onchain::OnChainSequentialPhragmen<Self>;
type GenesisElectionProvider = Self::ElectionProvider;
type WeightInfo = ();
// NOTE: consider a macro and use `UseNominatorsMap<Self>` as well.
type SortedListProvider = BagsList;
type BenchmarkingConfig = TestBenchmarkingConfig;
type WeightInfo = ();
}
impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test
@@ -50,6 +50,8 @@ const STAKING_ID: LockIdentifier = *b"staking ";
#[frame_support::pallet]
pub mod pallet {
use crate::BenchmarkingConfig;
use super::*;
#[pallet::pallet]
@@ -151,6 +153,9 @@ pub mod pallet {
/// the bags-list is not desired, [`impls::UseNominatorsMap`] is likely the desired option.
type SortedListProvider: SortedListProvider<Self::AccountId>;
/// Some parameters of the benchmarking.
type BenchmarkingConfig: BenchmarkingConfig;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}