referrerpolicy=no-referrer-when-downgrade

cumulus_pallet_session_benchmarking/
inner.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Benchmarking setup for pallet-session.
17#![cfg(feature = "runtime-benchmarks")]
18
19use alloc::{vec, vec::Vec};
20
21use codec::Decode;
22use frame_benchmarking::v2::*;
23use frame_system::RawOrigin;
24use pallet_session::*;
25pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
26pub trait Config: pallet_session::Config {}
27
28#[benchmarks]
29mod benchmarks {
30	use super::*;
31
32	#[benchmark]
33	fn set_keys() -> Result<(), BenchmarkError> {
34		let caller: T::AccountId = whitelisted_caller();
35		frame_system::Pallet::<T>::inc_providers(&caller);
36		let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
37		let proof: Vec<u8> = vec![0, 1, 2, 3];
38		<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
39
40		#[extrinsic_call]
41		_(RawOrigin::Signed(caller), keys, proof);
42
43		Ok(())
44	}
45
46	#[benchmark]
47	fn purge_keys() -> Result<(), BenchmarkError> {
48		let caller: T::AccountId = whitelisted_caller();
49		frame_system::Pallet::<T>::inc_providers(&caller);
50		let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
51		let proof: Vec<u8> = vec![0, 1, 2, 3];
52		<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
53		let _t = pallet_session::Pallet::<T>::set_keys(
54			RawOrigin::Signed(caller.clone()).into(),
55			keys,
56			proof,
57		);
58
59		#[extrinsic_call]
60		_(RawOrigin::Signed(caller));
61
62		Ok(())
63	}
64}