Skip to content
Snippets Groups Projects
Unverified Commit 0dd8479b authored by bgallois's avatar bgallois
Browse files

fix(pallet_membership): fix benchmarks

parent 500497cf
No related branches found
No related tags found
No related merge requests found
Pipeline #33670 failed
...@@ -61,6 +61,7 @@ benchmarks_instance_pallet! { ...@@ -61,6 +61,7 @@ benchmarks_instance_pallet! {
PendingMembership::<T, I>::insert(idty.clone(), T::MetaData::default()); PendingMembership::<T, I>::insert(idty.clone(), T::MetaData::default());
let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap();
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
T::BenchmarkSetupHandler::force_status_ok(&3, &caller);
}: _<T::RuntimeOrigin>(caller_origin) }: _<T::RuntimeOrigin>(caller_origin)
verify { verify {
assert_has_event::<T, I>(Event::<T, I>::MembershipAcquired(idty).into()); assert_has_event::<T, I>(Event::<T, I>::MembershipAcquired(idty).into());
...@@ -69,6 +70,7 @@ benchmarks_instance_pallet! { ...@@ -69,6 +70,7 @@ benchmarks_instance_pallet! {
let idty: T::IdtyId = 3.into(); let idty: T::IdtyId = 3.into();
let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap();
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
T::BenchmarkSetupHandler::force_status_ok(&3, &caller);
}: _<T::RuntimeOrigin>(caller_origin) }: _<T::RuntimeOrigin>(caller_origin)
verify { verify {
assert_has_event::<T, I>(Event::<T, I>::MembershipRenewed(idty).into()); assert_has_event::<T, I>(Event::<T, I>::MembershipRenewed(idty).into());
......
...@@ -42,6 +42,16 @@ use sp_std::prelude::*; ...@@ -42,6 +42,16 @@ use sp_std::prelude::*;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::BTreeMap; use std::collections::BTreeMap;
#[cfg(feature = "runtime-benchmarks")]
pub trait SetDistance<U32, AccountId> {
fn force_status_ok(idty_index: &U32, account: &AccountId) -> ();
}
#[cfg(feature = "runtime-benchmarks")]
impl<U32, AccountId> SetDistance<U32, AccountId> for () {
fn force_status_ok(_idty_id: &U32, _account: &AccountId) -> () {}
}
#[frame_support::pallet] #[frame_support::pallet]
pub mod pallet { pub mod pallet {
use super::*; use super::*;
...@@ -83,6 +93,8 @@ pub mod pallet { ...@@ -83,6 +93,8 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self, I>> type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>; + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type WeightInfo: WeightInfo; type WeightInfo: WeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetupHandler: SetDistance<u32, Self::AccountId>;
} }
// GENESIS STUFF // // GENESIS STUFF //
......
...@@ -93,6 +93,8 @@ impl pallet_membership::Config for Test { ...@@ -93,6 +93,8 @@ impl pallet_membership::Config for Test {
type PendingMembershipPeriod = PendingMembershipPeriod; type PendingMembershipPeriod = PendingMembershipPeriod;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = (); type WeightInfo = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetupHandler = ();
} }
// Build genesis storage according to the mock runtime. // Build genesis storage according to the mock runtime.
......
...@@ -469,6 +469,8 @@ parameter_types! { ...@@ -469,6 +469,8 @@ parameter_types! {
type PendingMembershipPeriod = PendingMembershipPeriod; type PendingMembershipPeriod = PendingMembershipPeriod;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_membership_membership::WeightInfo<Runtime>; 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 { impl pallet_certification::Config<Instance1> for Runtime {
...@@ -516,6 +518,8 @@ parameter_types! { ...@@ -516,6 +518,8 @@ parameter_types! {
type PendingMembershipPeriod = SmithPendingMembershipPeriod; type PendingMembershipPeriod = SmithPendingMembershipPeriod;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_membership_smith_membership::WeightInfo<Runtime>; 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 { impl pallet_certification::Config<Instance2> for Runtime {
......
...@@ -142,3 +142,16 @@ where ...@@ -142,3 +142,16 @@ where
); );
} }
} }
#[cfg(feature = "runtime-benchmarks")]
impl<T> pallet_membership::SetDistance<u32, T::AccountId> for BenchmarkSetupHandler<T>
where
T: pallet_distance::Config,
{
fn force_status_ok(idty_id: &u32, account: &<T as frame_system::Config>::AccountId) -> () {
let _ = pallet_distance::Pallet::<T>::set_distance_status(
*idty_id,
Some((account.clone(), pallet_distance::DistanceStatus::Valid)),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment