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

Commit

Permalink
Sample benchmarking that compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov committed Jul 22, 2022
1 parent f07deed commit 9a179aa
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion parachains/runtimes/assets/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ impl_runtime_apis! {
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);

Expand All @@ -810,14 +813,89 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError};

use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

use xcm::latest::{
AssetId::*, Fungibility::*, Junctions::*, MultiAsset, MultiAssets, MultiLocation,
Response,
};
use xcm_config::{Local, DotLocation};

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(DotLocation::get())
}
fn worst_case_holding() -> MultiAssets {
// Statemint only knows about DOT (?).
vec![MultiAsset{
id: Concrete(Local::get()),
fun: Fungible(1_000_000 * UNITS),
}].into()
}
}

//TODO: Not sure how this should work
parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Local::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
Local::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) },
));
}

impl pallet_xcm_benchmarks::fungible::Config for Runtime {
type TransactAsset = Balances;

type CheckedAccount = xcm_config::CheckingAccount;
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;

fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(DotLocation::get()),
fun: Fungible(1 * UNITS),
}
}
}

impl pallet_xcm_benchmarks::generic::Config for Runtime {
type Call = Call;

fn worst_case_response() -> (u64, Response) {
(0u64, Response::Version(Default::default()))
}

fn transact_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(DotLocation::get())
}

fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(DotLocation::get())
}

fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let origin = DotLocation::get();
let assets: MultiAssets = (Concrete(Local::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}
}

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;


let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand Down

0 comments on commit 9a179aa

Please sign in to comment.