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

            
27
use frame_support::{dispatch::DispatchResult, sp_runtime::Perbill};
28

            
29
pub use pallet::*;
30

            
31
1990
#[frame_support::pallet(dev_mode)]
32
pub 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
		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
41
	}
42

            
43
554790
	#[pallet::pallet]
44
	pub struct Pallet<T>(_);
45

            
46
	#[pallet::event]
47
	#[pallet::generate_deposit(pub(super) fn deposit_event)]
48
	pub enum Event<T: Config> {
49
		/// Event dispatched when the trigger_defensive extrinsic is called.
50
		DefensiveTestCall,
51
	}
52

            
53
8097
	#[pallet::call]
54
	impl<T: Config> Pallet<T> {
55
		/// A dispatch that will fill the block weight up to the given ratio.
56
		#[pallet::call_index(0)]
57
		#[pallet::weight(*_ratio * T::BlockWeights::get().max_block)]
58
1788
		pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResult {
59
1788
			ensure_root(origin)?;
60
			Ok(())
61
		}
62

            
63
		#[pallet::call_index(1)]
64
		#[pallet::weight(0)]
65
177
		pub fn trigger_defensive(origin: OriginFor<T>) -> DispatchResult {
66
177
			ensure_root(origin)?;
67
			frame_support::defensive!("root_testing::trigger_defensive was called.");
68
			Self::deposit_event(Event::DefensiveTestCall);
69
			Ok(())
70
		}
71
	}
72
}