referrerpolicy=no-referrer-when-downgrade

pallet_root_testing/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! # Root Testing Pallet
19//!
20//! Pallet that contains extrinsics that can be useful in testing.
21//!
22//! NOTE: This pallet should only be used for testing purposes and should not be used in production
23//! runtimes!
24
25#![cfg_attr(not(feature = "std"), no_std)]
26
27use frame_support::{dispatch::DispatchResult, sp_runtime::Perbill};
28
29pub use pallet::*;
30
31#[frame_support::pallet(dev_mode)]
32pub mod pallet {
33	use super::*;
34	use frame_support::pallet_prelude::*;
35	use frame_system::pallet_prelude::*;
36
37	#[pallet::config]
38	pub trait Config: frame_system::Config {
39		/// The overarching event type.
40		#[allow(deprecated)]
41		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
42	}
43
44	#[pallet::pallet]
45	pub struct Pallet<T>(_);
46
47	#[pallet::event]
48	#[pallet::generate_deposit(pub(super) fn deposit_event)]
49	pub enum Event<T: Config> {
50		/// Event dispatched when the trigger_defensive extrinsic is called.
51		DefensiveTestCall,
52	}
53
54	#[pallet::call]
55	impl<T: Config> Pallet<T> {
56		/// A dispatch that will fill the block weight up to the given ratio.
57		#[pallet::call_index(0)]
58		#[pallet::weight(*_ratio * T::BlockWeights::get().max_block)]
59		pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResult {
60			ensure_root(origin)?;
61			Ok(())
62		}
63
64		#[pallet::call_index(1)]
65		#[pallet::weight(0)]
66		pub fn trigger_defensive(origin: OriginFor<T>) -> DispatchResult {
67			ensure_root(origin)?;
68			frame_support::defensive!("root_testing::trigger_defensive was called.");
69			Self::deposit_event(Event::DefensiveTestCall);
70			Ok(())
71		}
72	}
73}