1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
// This file is part of Astar.
// Copyright (C) Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
pub mod fungible;
pub mod generic;
#[cfg(test)]
mod mock;
use sp_std::vec::Vec;
/// A base trait for all individual pallets
pub trait Config: frame_system::Config + pallet_xcm_benchmarks::Config {}
/// This is a wrapper benchmark implementation over `Inner` by `Outer` by merging
/// the benches from `Inner` if they don't exist in `Outer`.
pub struct WrappedBenchmark<Outer, Inner>(core::marker::PhantomData<(Outer, Inner)>);
impl<Outer, Inner> frame_benchmarking::Benchmarking for WrappedBenchmark<Outer, Inner>
where
Outer: frame_benchmarking::Benchmarking,
Inner: frame_benchmarking::Benchmarking,
{
fn benchmarks(extra: bool) -> Vec<frame_benchmarking::BenchmarkMetadata> {
let mut outer = Outer::benchmarks(extra);
let inner = Inner::benchmarks(extra);
for meta in inner {
if !outer.iter().any(|m| m.name == meta.name) {
outer.push(meta)
}
}
outer
}
fn run_benchmark(
name: &[u8],
c: &[(frame_benchmarking::BenchmarkParameter, u32)],
whitelist: &[frame_support::traits::TrackedStorageKey],
verify: bool,
internal_repeats: u32,
) -> Result<Vec<frame_benchmarking::BenchmarkResult>, frame_benchmarking::BenchmarkError> {
if Outer::benchmarks(true).iter().any(|x| x.name == name) {
Outer::run_benchmark(name, c, whitelist, verify, internal_repeats)
} else {
Inner::run_benchmark(name, c, whitelist, verify, internal_repeats)
}
}
}