diff --git a/pallets/membership/src/benchmarking.rs b/pallets/membership/src/benchmarking.rs index 9b0ad18d041b5dfb8dba4c0936d4e234cffc76dc..3021d59f50069fe39e22ad381a9c295a4377d06a 100644 --- a/pallets/membership/src/benchmarking.rs +++ b/pallets/membership/src/benchmarking.rs @@ -56,19 +56,23 @@ benchmarks_instance_pallet! { } } claim_membership { - let idty: T::IdtyId = 3.into(); + let idty_index: u32 = 3; + let idty: T::IdtyId = idty_index.into(); Membership::<T, I>::take(idty); PendingMembership::<T, I>::insert(idty.clone(), T::MetaData::default()); let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + T::BenchmarkSetupHandler::force_status_ok(&idty_index, &caller); }: _<T::RuntimeOrigin>(caller_origin) verify { assert_has_event::<T, I>(Event::<T, I>::MembershipAcquired(idty).into()); } renew_membership { - let idty: T::IdtyId = 3.into(); + let idty_index: u32 = 3; + let idty: T::IdtyId = idty_index.into(); let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + T::BenchmarkSetupHandler::force_status_ok(&idty_index, &caller); }: _<T::RuntimeOrigin>(caller_origin) verify { assert_has_event::<T, I>(Event::<T, I>::MembershipRenewed(idty).into()); diff --git a/pallets/membership/src/lib.rs b/pallets/membership/src/lib.rs index 8fec34f89f39d6656565a09d01d07b348ad4acf1..6a90624e7c44eff1a8dfd8a20b612e348d8135cd 100644 --- a/pallets/membership/src/lib.rs +++ b/pallets/membership/src/lib.rs @@ -42,6 +42,16 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use std::collections::BTreeMap; +#[cfg(feature = "runtime-benchmarks")] +pub trait SetDistance<IdtyId, AccountId> { + fn force_status_ok(idty_index: &IdtyId, account: &AccountId) -> (); +} + +#[cfg(feature = "runtime-benchmarks")] +impl<IdtyId, AccountId> SetDistance<IdtyId, AccountId> for () { + fn force_status_ok(_idty_id: &IdtyId, _account: &AccountId) -> () {} +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -83,6 +93,8 @@ pub mod pallet { type RuntimeEvent: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type WeightInfo: WeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetupHandler: SetDistance<u32, Self::AccountId>; } // GENESIS STUFF // diff --git a/pallets/membership/src/mock.rs b/pallets/membership/src/mock.rs index b4a65ac6a33a5779c5fe77df9f95b06a26180393..d97f1f86ab0e480c6a3fa439b11af5a7939f8f18 100644 --- a/pallets/membership/src/mock.rs +++ b/pallets/membership/src/mock.rs @@ -93,6 +93,8 @@ impl pallet_membership::Config for Test { type PendingMembershipPeriod = PendingMembershipPeriod; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetupHandler = (); } // Build genesis storage according to the mock runtime. diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index a2bb56c9c74dcb5797b3539db13b130d076ec772..e5aaa8c3ff5d82da3d25b61f03e694f0422ec58b 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -469,6 +469,8 @@ parameter_types! { type PendingMembershipPeriod = PendingMembershipPeriod; type RuntimeEvent = RuntimeEvent; type WeightInfo = common_runtime::weights::pallet_membership_membership::WeightInfo<Runtime>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetupHandler = common_runtime::providers::BenchmarkSetupHandler<Runtime>; } impl pallet_certification::Config<Instance1> for Runtime { @@ -516,6 +518,8 @@ parameter_types! { type PendingMembershipPeriod = SmithPendingMembershipPeriod; type RuntimeEvent = RuntimeEvent; type WeightInfo = common_runtime::weights::pallet_membership_smith_membership::WeightInfo<Runtime>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetupHandler = common_runtime::providers::BenchmarkSetupHandler<Runtime>; } impl pallet_certification::Config<Instance2> for Runtime { diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index 2079dfc3e41e0b80937b67ce5863fa7f7e063217..48c5edacd84b63f449b6000a7b1bd6818043747a 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -142,3 +142,20 @@ where ); } } + +#[cfg(feature = "runtime-benchmarks")] +impl<T> pallet_membership::SetDistance<<T as pallet_identity::Config>::IdtyIndex, T::AccountId> + for BenchmarkSetupHandler<T> +where + T: pallet_distance::Config, +{ + fn force_status_ok( + idty_id: &<T as pallet_identity::Config>::IdtyIndex, + account: &<T as frame_system::Config>::AccountId, + ) -> () { + let _ = pallet_distance::Pallet::<T>::set_distance_status( + *idty_id, + Some((account.clone(), pallet_distance::DistanceStatus::Valid)), + ); + } +}