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

fix(pallet_membership): fix benchmarks

parent 500497cf
No related branches found
No related tags found
1 merge request!185Fix benchmarks
......@@ -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());
......
......@@ -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 //
......
......@@ -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.
......
......@@ -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 {
......
......@@ -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)),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment