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

fix(pallet_identity): fix benchmarks

parent 5db045f3
No related branches found
No related tags found
No related merge requests found
Pipeline #33660 failed
......@@ -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 //
impl<T: Config> Pallet<T> {
......
......@@ -147,6 +147,7 @@ benchmarks! {
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();
Pallet::<T>::confirm_identity(owner_key_origin.clone(), name.clone())?;
T::DistanceHandler::force_status_ok(&index, &owner_key);
}: _<T::RuntimeOrigin>(caller_origin, index)
verify {
assert_has_event::<T>(Event::<T>::IdtyValidated { idty_index: index }.into());
......
......@@ -114,6 +114,9 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
/// Type representing the a distance handler to prepare identity for benchmarking
#[cfg(feature = "runtime-benchmarks")]
type DistanceHandler: SetDistance<Self::IdtyIndex, Self::AccountId>;
}
// GENESIS STUFF //
......
......@@ -76,3 +76,8 @@ impl<IndtyIndex> RemoveIdentityConsumers<IndtyIndex> for () {
Weight::zero()
}
}
#[cfg(feature = "runtime-benchmarks")]
pub trait SetDistance<IndtyIndex, AccountId> {
fn force_status_ok(idty_index: &IndtyIndex, account: &AccountId) -> ();
}
......@@ -454,6 +454,8 @@ parameter_types! {
type RevocationSignature = Signature;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type DistanceHandler = common_runtime::providers::DistanceHandler<Runtime>;
}
impl pallet_membership::Config<frame_support::instances::Instance1> for Runtime {
......
......@@ -121,3 +121,24 @@ where
)
}
}
#[cfg(feature = "runtime-benchmarks")]
pub struct DistanceHandler<T>(PhantomData<T>);
#[cfg(feature = "runtime-benchmarks")]
impl<T>
pallet_identity::traits::SetDistance<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>
for DistanceHandler<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