Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
benchmarks fix
Browse files Browse the repository at this point in the history
  • Loading branch information
muharem committed Jul 3, 2023
1 parent 6f78c24 commit 5ba47db
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac

slot-range-helper = { path = "slot_range_helper", default-features = false }
xcm = { path = "../../xcm", default-features = false }
xcm-builder = { path = "../../xcm/xcm-builder", default-features = false }

[dev-dependencies]
hex-literal = "0.4.1"
Expand Down Expand Up @@ -97,6 +98,7 @@ std = [
"libsecp256k1/std",
"runtime-parachains/std",
"xcm/std",
"xcm-builder/std",
"sp-npos-elections/std",
]
runtime-benchmarks = [
Expand All @@ -107,7 +109,9 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"runtime-parachains/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks"
"pallet-fast-unstake/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
try-runtime = [
"runtime-parachains/try-runtime",
Expand Down
27 changes: 27 additions & 0 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ pub fn era_payout(
(staking_payout, rest)
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks {
use pallet_treasury::ArgumentsFactory;
use xcm::prelude::*;
use xcm_builder::LocatableAssetId;

/// Implements the [`ArgumentsFactory`] trait to provide factory methods for benchmarks
/// that require the `AssetKind` of [`LocatableAssetId`] and the `Beneficiary` of [`MultiLocation`].
/// The location of the asset is determined as a Parachain with an ID equal to the passed seed.
pub struct MultiLocationFactory;
impl ArgumentsFactory<LocatableAssetId, MultiLocation> for MultiLocationFactory {
fn create_asset_kind(seed: u32) -> LocatableAssetId {
LocatableAssetId {
asset_id: MultiLocation::new(
0,
X2(PalletInstance(seed.try_into().unwrap()), GeneralIndex(seed.into())),
)
.into(),
location: MultiLocation::new(0, X1(Parachain(seed))),
}
}
fn create_beneficiary(seed: [u8; 32]) -> MultiLocation {
MultiLocation::new(0, X1(AccountId32 { network: None, id: seed }))
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,14 @@ impl pallet_treasury::Config for Runtime {
IdentityConvert,
CloneIdentity,
>;
#[cfg(not(feature = "runtime-benchmarks"))]
type BalanceConverter = AssetRate;
#[cfg(feature = "runtime-benchmarks")]
type BalanceConverter = ();

type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::MultiLocationFactory;
}

parameter_types! {
Expand Down
6 changes: 6 additions & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,14 @@ impl pallet_treasury::Config for Runtime {
IdentityConvert,
CloneIdentity,
>;
#[cfg(not(feature = "runtime-benchmarks"))]
type BalanceConverter = AssetRate;
#[cfg(feature = "runtime-benchmarks")]
type BalanceConverter = ();

type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::MultiLocationFactory;
}

parameter_types! {
Expand Down
6 changes: 6 additions & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,14 @@ impl pallet_treasury::Config for Runtime {
IdentityConvert,
CloneIdentity,
>;
#[cfg(not(feature = "runtime-benchmarks"))]
type BalanceConverter = AssetRate;
#[cfg(feature = "runtime-benchmarks")]
type BalanceConverter = ();

type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::MultiLocationFactory;
}

parameter_types! {
Expand Down

0 comments on commit 5ba47db

Please sign in to comment.