diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index 48c5edacd84b63f449b6000a7b1bd6818043747a..e8ddf8102dbae4d471b35a370260bdba7c76b6f8 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -125,37 +125,30 @@ where #[cfg(feature = "runtime-benchmarks")] pub struct BenchmarkSetupHandler<T>(PhantomData<T>); +// Macro implementing the BenchmarkSetupHandler trait for pallets requiring identity preparation for benchmarks. #[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)), - ); - } +macro_rules! impl_benchmark_setup_handler { + ($t:ty) => { + impl<T> $t 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)), + ); + } + // TODO: All the required preparation for the benchmarks, depending on the coupling + // between pallets, would be implemented here when moving away from prepared identities from the gdev-benchmark. + } + }; } #[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)), - ); - } -} +impl_benchmark_setup_handler!(pallet_membership::SetDistance<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>); +#[cfg(feature = "runtime-benchmarks")] +impl_benchmark_setup_handler!(pallet_identity::traits::SetDistance<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>);