Skip to content

Commit

Permalink
feat: added benchmark helper for pallet_data_preservers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Brayanov committed Dec 20, 2024
1 parent 979fc76 commit a010dc8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions pallets/data-preservers/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ use {
tp_traits::{ParaId, StorageDeposit},
};

/// Trait describing factory function for para_id.
pub trait ArgumentFactory<ParaId> {
/// Factory function reserving parachain
fn reserve_para_id(para_id: ParaId) -> ();
}

/// Dummy implementation for when the factory is not needed.
impl<ParaId> ArgumentFactory<ParaId> for () {
fn reserve_para_id(_para_id: ParaId) -> () {}
}

macro_rules! bset {
( $($value:expr),* $(,)? ) => {
{
Expand Down Expand Up @@ -333,6 +344,8 @@ mod benchmarks {
Pallet::<T>::create_profile(RawOrigin::Signed(caller.clone()).into(), profile)
.expect("to create profile");

T::BenchmarkHelper::reserve_para_id(para_id);

let origin = T::AssignmentOrigin::try_successful_origin(&para_id).unwrap();

#[extrinsic_call]
Expand Down Expand Up @@ -366,6 +379,8 @@ mod benchmarks {
Pallet::<T>::create_profile(RawOrigin::Signed(caller.clone()).into(), profile)
.expect("to create profile");

T::BenchmarkHelper::reserve_para_id(para_id);

let origin = T::AssignmentOrigin::try_successful_origin(&para_id).unwrap();

Pallet::<T>::start_assignment(
Expand Down
7 changes: 7 additions & 0 deletions pallets/data-preservers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ mod tests;
#[cfg(any(test, feature = "runtime-benchmarks"))]
mod benchmarks;

#[cfg(feature = "runtime-benchmarks")]
pub use benchmarks::ArgumentFactory;

pub mod weights;
pub use weights::WeightInfo;

Expand Down Expand Up @@ -172,6 +175,10 @@ pub mod pallet {
type AssignmentPayment: AssignmentPayment<Self::AccountId>;

type WeightInfo: WeightInfo;

/// Helper type for benchmarks.
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper: ArgumentFactory<ParaId>;
}

#[pallet::event]
Expand Down
2 changes: 2 additions & 0 deletions runtime/dancebox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_author_noting::Config for Runtime {
Expand Down
3 changes: 3 additions & 0 deletions runtime/flashbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;

#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_author_noting::Config for Runtime {
Expand Down
6 changes: 3 additions & 3 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,8 @@ impl pallet_data_preservers::Config for Runtime {
type MaxAssignmentsPerParaId = MaxAssignmentsPerParaId;
type MaxNodeUrlLen = MaxNodeUrlLen;
type MaxParaIdsVecLen = MaxLengthParaIds;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
Expand Down Expand Up @@ -2045,9 +2047,7 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = DancelightRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
#[cfg(feature = "runtime-benchmarks")]
type InnerRegistrar = ();
#[cfg(not(feature = "runtime-benchmarks"))]

type InnerRegistrar = InnerDancelightRegistrar<
Runtime,
AccountId,
Expand Down

0 comments on commit a010dc8

Please sign in to comment.