astar_xcm_benchmarks/
lib.rs

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