diff --git a/authority/src/lib.rs b/authority/src/lib.rs index 2502691fd..dd44d2cdb 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -20,13 +20,13 @@ #![allow(clippy::unused_unit)] use frame_support::{ - dispatch::PostDispatchInfo, + dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, pallet_prelude::*, traits::{ schedule::{DispatchTime, Named as ScheduleNamed, Priority}, EnsureOrigin, Get, IsType, OriginTrait, }, - weights::GetDispatchInfo, + weights::{DispatchClass, GetDispatchInfo, Pays}, }; use frame_system::{pallet_prelude::*, EnsureOneOf, EnsureRoot, EnsureSigned}; use sp_runtime::{ @@ -342,17 +342,17 @@ pub mod module { Ok(()) } - #[pallet::weight(T::WeightInfo::authorize_call())] + #[pallet::weight((T::WeightInfo::authorize_call(), DispatchClass::Operational))] pub fn authorize_call( origin: OriginFor, call: Box>, caller: Option, - ) -> DispatchResult { + ) -> DispatchResultWithPostInfo { ensure_root(origin)?; let hash = T::Hashing::hash_of(&call); SavedCalls::::insert(hash, (call, caller.clone())); Self::deposit_event(Event::AuthorizedCall(hash, caller)); - Ok(()) + Ok(Pays::No.into()) } #[pallet::weight(T::WeightInfo::remove_authorized_call())] diff --git a/authority/src/tests.rs b/authority/src/tests.rs index 530089ac0..29f44829c 100644 --- a/authority/src/tests.rs +++ b/authority/src/tests.rs @@ -5,6 +5,7 @@ use super::*; use frame_support::{ assert_noop, assert_ok, + dispatch::{DispatchErrorWithPostInfo, DispatchInfo}, traits::{schedule::DispatchTime, OriginTrait}, }; use frame_system::RawOrigin; @@ -405,6 +406,44 @@ fn call_size_limit() { ); } +#[test] +fn authorize_call_should_be_free_and_operational() { + ExtBuilder::default().build().execute_with(|| { + let call = Call::System(frame_system::Call::fill_block(Perbill::one())); + let authorize_call = Call::Authority(authority::Call::authorize_call(Box::new(call), None)); + + assert_eq!( + authorize_call.clone().get_dispatch_info(), + DispatchInfo { + weight: ::WeightInfo::authorize_call(), + class: DispatchClass::Operational, + pays_fee: Pays::Yes, + } + ); + + // successfull call doesn't pay fee + assert_eq!( + authorize_call.clone().dispatch(Origin::root()), + Ok(PostDispatchInfo { + actual_weight: None, + pays_fee: Pays::No + }) + ); + + // bad origin pays fee + assert_eq!( + authorize_call.dispatch(Origin::signed(1)), + Err(DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { + actual_weight: None, + pays_fee: Pays::Yes + }, + error: DispatchError::BadOrigin + }) + ); + }); +} + #[test] fn authorize_call_works() { ExtBuilder::default().build().execute_with(|| {