1953 defensive testing extrinsic (#1998)

# Description

The `trigger_defensive` call has been added to the `root-testing`
pallet. The idea is to have this pallet running on `Rococo/Westend` and
use it to verify if the runtime monitoring works end-to-end.

To accomplish this, `trigger_defensive` dispatches an event when it is
called.

Closes #1953

# Checklist

- [x] My PR includes a detailed description as outlined in the
"Description" section above
- [ ] My PR follows the [labeling requirements](CONTRIBUTING.md#Process)
of this project (at minimum one label for `T`
  required)
- [ ] I have made corresponding changes to the documentation (if
applicable)
- [ ] I have added tests that prove my fix is effective or that my
feature works (if applicable)

You can remove the "Checklist" section once all have been checked. Thank
you for your contribution!

✄
-----------------------------------------------------------------------------

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Adel Arja
2023-10-31 14:35:19 -03:00
committed by GitHub
parent 64f4b15640
commit 6e2f94f81c
9 changed files with 53 additions and 9 deletions
+21 -3
View File
@@ -24,8 +24,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::dispatch::DispatchResult;
use sp_runtime::Perbill;
use frame_support::{dispatch::DispatchResult, sp_runtime::Perbill};
pub use pallet::*;
@@ -36,11 +35,21 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {}
pub trait Config: frame_system::Config {
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event dispatched when the trigger_defensive extrinsic is called.
DefensiveTestCall,
}
#[pallet::call]
impl<T: Config> Pallet<T> {
/// A dispatch that will fill the block weight up to the given ratio.
@@ -50,5 +59,14 @@ pub mod pallet {
ensure_root(origin)?;
Ok(())
}
#[pallet::call_index(1)]
#[pallet::weight(0)]
pub fn trigger_defensive(origin: OriginFor<T>) -> DispatchResult {
ensure_root(origin)?;
frame_support::defensive!("root_testing::trigger_defensive was called.");
Self::deposit_event(Event::DefensiveTestCall);
Ok(())
}
}
}