1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
56// 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.
1718//! # 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!
2425#![cfg_attr(not(feature = "std"), no_std)]
2627use frame_support::{dispatch::DispatchResult, sp_runtime::Perbill};
2829pub use pallet::*;
3031#[frame_support::pallet(dev_mode)]
32pub mod pallet {
33use super::*;
34use frame_support::pallet_prelude::*;
35use frame_system::pallet_prelude::*;
3637#[pallet::config]
38pub trait Config: frame_system::Config {
39/// The overarching event type.
40#[allow(deprecated)]
41type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
42 }
4344#[pallet::pallet]
45pub struct Pallet<T>(_);
4647#[pallet::event]
48 #[pallet::generate_deposit(pub(super) fn deposit_event)]
49pub enum Event<T: Config> {
50/// Event dispatched when the trigger_defensive extrinsic is called.
51DefensiveTestCall,
52 }
5354#[pallet::call]
55impl<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)]
59pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResult {
60 ensure_root(origin)?;
61Ok(())
62 }
6364#[pallet::call_index(1)]
65 #[pallet::weight(0)]
66pub fn trigger_defensive(origin: OriginFor<T>) -> DispatchResult {
67 ensure_root(origin)?;
68frame_support::defensive!("root_testing::trigger_defensive was called.");
69Self::deposit_event(Event::DefensiveTestCall);
70Ok(())
71 }
72 }
73}