Skip to content

Commit

Permalink
Add benchmarks arguments to kitchensink runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidK committed Oct 25, 2024
1 parent af300f7 commit fef1701
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

extern crate alloc;

#[cfg(feature = "runtime-benchmarks")]
use pallet_asset_rate::AssetKindFactory;
#[cfg(feature = "runtime-benchmarks")]
use pallet_treasury::ArgumentsFactory;
#[cfg(feature = "runtime-benchmarks")]
use polkadot_sdk::sp_core::crypto::FromEntropy;

use polkadot_sdk::*;

use alloc::{vec, vec::Vec};
Expand Down Expand Up @@ -267,6 +274,36 @@ impl Contains<RuntimeCallNameOf<Runtime>> for TxPauseWhitelistedCalls {
}
}

#[cfg(feature = "runtime-benchmarks")]
pub struct AssetRateArguments;
#[cfg(feature = "runtime-benchmarks")]
impl AssetKindFactory<NativeOrWithId<u32>> for AssetRateArguments {
fn create_asset_kind(seed: u32) -> NativeOrWithId<u32> {
if seed % 2 > 0 {
NativeOrWithId::Native
} else {
NativeOrWithId::WithId(seed / 2)
}
}
}

#[cfg(feature = "runtime-benchmarks")]
pub struct PalletTreasuryArguments;
#[cfg(feature = "runtime-benchmarks")]
impl ArgumentsFactory<NativeOrWithId<u32>, AccountId> for PalletTreasuryArguments {
fn create_asset_kind(seed: u32) -> NativeOrWithId<u32> {
if seed % 2 > 0 {
NativeOrWithId::Native
} else {
NativeOrWithId::WithId(seed / 2)
}
}

fn create_beneficiary(seed: [u8; 32]) -> AccountId {
AccountId::from_entropy(&mut seed.as_slice()).unwrap()
}
}

impl pallet_tx_pause::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -1267,7 +1304,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = AssetRate;
type PayoutPeriod = SpendPayoutPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = PalletTreasuryArguments;
}

impl pallet_asset_rate::Config for Runtime {
Expand All @@ -1279,7 +1316,7 @@ impl pallet_asset_rate::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_asset_rate::weights::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = AssetRateArguments;
}

parameter_types! {
Expand Down

0 comments on commit fef1701

Please sign in to comment.