referrerpolicy=no-referrer-when-downgrade

pallet_xcm_benchmarks/generic/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17pub use pallet::*;
18
19#[cfg(feature = "runtime-benchmarks")]
20pub mod benchmarking;
21#[cfg(test)]
22mod mock;
23
24#[frame_support::pallet]
25pub mod pallet {
26	use frame_benchmarking::BenchmarkError;
27	use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::Encode};
28	use sp_runtime::traits::Dispatchable;
29	use xcm::latest::{
30		Asset, Assets, InteriorLocation, Junction, Location, NetworkId, Response, WeightLimit,
31	};
32
33	#[pallet::config]
34	pub trait Config<I: 'static = ()>: frame_system::Config + crate::Config {
35		type RuntimeCall: Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
36			+ GetDispatchInfo
37			+ From<frame_system::Call<Self>>
38			+ Encode;
39
40		/// The type of `fungible` that is being used under the hood.
41		///
42		/// This is useful for testing and checking.
43		type TransactAsset: frame_support::traits::fungible::Mutate<Self::AccountId>;
44
45		///	The response which causes the most runtime weight.
46		fn worst_case_response() -> (u64, Response);
47
48		/// The pair of asset collections which causes the most runtime weight if demanded to be
49		/// exchanged.
50		///
51		/// The first element in the returned tuple represents the assets that are being exchanged
52		/// from, whereas the second element represents the assets that are being exchanged to.
53		///
54		/// If set to `Err`, benchmarks which rely on an `exchange_asset` will be skipped.
55		fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError>;
56
57		/// A `(Location, Junction)` that is one of the `UniversalAliases` configured by the
58		/// XCM executor.
59		///
60		/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
61		fn universal_alias() -> Result<(Location, Junction), BenchmarkError>;
62
63		/// The `Location` and `RuntimeCall` used for successful transaction XCMs.
64		///
65		/// If set to `Err`, benchmarks which rely on a `transact_origin_and_runtime_call` will be
66		/// skipped.
67		fn transact_origin_and_runtime_call(
68		) -> Result<(Location, <Self as crate::generic::Config<I>>::RuntimeCall), BenchmarkError>;
69
70		/// A valid `Location` we can successfully subscribe to.
71		///
72		/// If set to `Err`, benchmarks which rely on a `subscribe_origin` will be skipped.
73		fn subscribe_origin() -> Result<Location, BenchmarkError>;
74
75		/// Return an origin, ticket, and assets that can be trapped and claimed.
76		fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError>;
77
78		/// The worst case buy execution weight limit and
79		/// asset to trigger the Trader::buy_execution in the XCM executor
80		/// Used to buy weight in benchmarks, for example in
81		/// `refund_surplus`.
82		fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError>;
83
84		/// Return an unlocker, owner and assets that can be locked and unlocked.
85		fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError>;
86
87		/// A `(Location, NetworkId, InteriorLocation)` we can successfully export message
88		/// to.
89		///
90		/// If set to `Err`, benchmarks which rely on `export_message` will be skipped.
91		fn export_message_origin_and_destination(
92		) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError>;
93
94		/// A `(Location, Location)` that is one of the `Aliasers` configured by the XCM
95		/// executor.
96		///
97		/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
98		fn alias_origin() -> Result<(Location, Location), BenchmarkError>;
99
100		/// Returns a valid pallet info for `ExpectPallet` or `QueryPallet` benchmark.
101		///
102		/// By default returns `frame_system::Pallet` info with expected pallet index `0`.
103		fn valid_pallet() -> frame_support::traits::PalletInfoData {
104			frame_support::traits::PalletInfoData {
105				index: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::index(),
106				name: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::name(),
107				module_name: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::module_name(),
108				crate_version: <frame_system::Pallet<Self> as frame_support::traits::PalletInfoAccess>::crate_version(),
109			}
110		}
111	}
112
113	#[pallet::pallet]
114	pub struct Pallet<T, I = ()>(_);
115}