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

fix(pallet_identity): fix benchmarks

parent 5db045f3
No related branches found
No related tags found
1 merge request!185Fix benchmarks
Pipeline #33666 failed
...@@ -276,6 +276,27 @@ pub mod pallet { ...@@ -276,6 +276,27 @@ pub mod pallet {
} }
} }
// BENCHMARK FUNCTIONS //
impl<T: Config> Pallet<T> {
/// Force the distance status using IdtyIndex and AccountId
/// only to prepare identity for benchmarking.
pub fn set_distance_status(
identity: <T as pallet_identity::Config>::IdtyIndex,
status: Option<(<T as frame_system::Config>::AccountId, DistanceStatus)>,
) -> DispatchResult {
IdentityDistanceStatus::<T>::set(identity, status);
DistanceStatusExpireOn::<T>::mutate(
pallet_session::CurrentIndex::<T>::get() + T::ResultExpiration::get(),
move |identities| {
identities
.try_push(identity)
.map_err(|_| Error::<T>::ManyEvaluationsInBlock.into())
},
)
}
}
// INTERNAL FUNCTIONS // // INTERNAL FUNCTIONS //
impl<T: Config> Pallet<T> { impl<T: Config> Pallet<T> {
......
...@@ -147,6 +147,7 @@ benchmarks! { ...@@ -147,6 +147,7 @@ benchmarks! {
let owner_key: T::AccountId = Identities::<T>::get(index).unwrap().owner_key; let owner_key: T::AccountId = Identities::<T>::get(index).unwrap().owner_key;
let owner_key_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner_key.clone()).into(); let owner_key_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner_key.clone()).into();
Pallet::<T>::confirm_identity(owner_key_origin.clone(), name.clone())?; Pallet::<T>::confirm_identity(owner_key_origin.clone(), name.clone())?;
T::BenchmarkSetupHandler::force_status_ok(&index, &owner_key);
}: _<T::RuntimeOrigin>(caller_origin, index) }: _<T::RuntimeOrigin>(caller_origin, index)
verify { verify {
assert_has_event::<T>(Event::<T>::IdtyValidated { idty_index: index }.into()); assert_has_event::<T>(Event::<T>::IdtyValidated { idty_index: index }.into());
......
...@@ -114,6 +114,9 @@ pub mod pallet { ...@@ -114,6 +114,9 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet /// Type representing the weight of this pallet
type WeightInfo: WeightInfo; type WeightInfo: WeightInfo;
/// Type representing the a distance handler to prepare identity for benchmarking
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetupHandler: SetDistance<Self::IdtyIndex, Self::AccountId>;
} }
// GENESIS STUFF // // GENESIS STUFF //
......
...@@ -117,6 +117,8 @@ impl pallet_identity::Config for Test { ...@@ -117,6 +117,8 @@ impl pallet_identity::Config for Test {
type RevocationSignature = Signature; type RevocationSignature = Signature;
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.
......
...@@ -76,3 +76,13 @@ impl<IndtyIndex> RemoveIdentityConsumers<IndtyIndex> for () { ...@@ -76,3 +76,13 @@ impl<IndtyIndex> RemoveIdentityConsumers<IndtyIndex> for () {
Weight::zero() Weight::zero()
} }
} }
#[cfg(feature = "runtime-benchmarks")]
pub trait SetDistance<IndtyIndex, AccountId> {
fn force_status_ok(idty_index: &IndtyIndex, account: &AccountId) -> ();
}
#[cfg(feature = "runtime-benchmarks")]
impl<IdtyIndex, AccountId> SetDistance<IdtyIndex, AccountId> for () {
fn force_status_ok(_idty_id: &IdtyIndex, _account: &AccountId) -> () {}
}
...@@ -454,6 +454,8 @@ parameter_types! { ...@@ -454,6 +454,8 @@ parameter_types! {
type RevocationSignature = Signature; type RevocationSignature = Signature;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>; type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetupHandler = common_runtime::providers::BenchmarkSetupHandler<Runtime>;
} }
impl pallet_membership::Config<frame_support::instances::Instance1> for Runtime { impl pallet_membership::Config<frame_support::instances::Instance1> for Runtime {
......
...@@ -121,3 +121,24 @@ where ...@@ -121,3 +121,24 @@ where
) )
} }
} }
#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkSetupHandler<T>(PhantomData<T>);
#[cfg(feature = "runtime-benchmarks")]
impl<T>
pallet_identity::traits::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