Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sudo & sudo_as
  • Loading branch information
doordashcon committed May 1, 2023
commit 189045600b969ec21406fe0ff9ae6f84e5a77068
39 changes: 38 additions & 1 deletion frame/sudo/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Benchmarks for Sudo Pallet
//! Benchmarks for Sudo Pallet

use super::*;
use crate::Pallet;
Expand Down Expand Up @@ -46,5 +46,42 @@ mod benchmarks {
assert_last_event::<T>(Event::KeyChanged { old_sudoer: Some(caller) }.into());
}

#[benchmark]
fn sudo() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(caller.clone());

let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();

#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), Box::new(call.clone()));

let res = call.dispatch_bypass_filter(RawOrigin::Signed(caller.clone()).into());

assert_last_event::<T>(
Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) }.into(),
)
}

#[benchmark]
fn sudo_as() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(caller.clone());

let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();

let who: T::AccountId = account("as", 0, SEED);
let who_lookup = T::Lookup::unlookup(who.clone());

#[extrinsic_call]
_(RawOrigin::Signed(caller), who_lookup, Box::new(call.clone()));

let res = call.dispatch_bypass_filter(RawOrigin::Signed(who).into());

assert_last_event::<T>(
Event::SudoAsDone { sudo_result: res.map(|_| ()).map_err(|e| e.error) }.into(),
)
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_bench_ext(), crate::mock::Test);
}
5 changes: 3 additions & 2 deletions frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ pub mod pallet {
/// A sudo-able call.
type RuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ GetDispatchInfo;
+ GetDispatchInfo
+ From<frame_system::Call<Self>>;

/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -203,7 +204,7 @@ pub mod pallet {
/// ## Complexity
/// - O(1).
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::set_key())] // FIXME
#[pallet::weight(T::WeightInfo::set_key())]
pub fn set_key(
origin: OriginFor<T>,
new: AccountIdLookupOf<T>,
Expand Down