referrerpolicy=no-referrer-when-downgrade

pallet_tx_pause/
benchmarking.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// 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.
17
18#![cfg(feature = "runtime-benchmarks")]
19
20use super::{Pallet as TxPause, *};
21use alloc::vec;
22use frame::benchmarking::prelude::*;
23
24#[benchmarks]
25mod benchmarks {
26	use super::*;
27
28	#[benchmark]
29	fn pause() {
30		let origin = T::PauseOrigin::try_successful_origin()
31			.expect("Tx-pause pallet is not usable without pause origin");
32		let full_name = name::<T>();
33
34		#[extrinsic_call]
35		_(origin as T::RuntimeOrigin, full_name.clone());
36
37		assert!(PausedCalls::<T>::get(full_name).is_some());
38	}
39
40	#[benchmark]
41	fn unpause() {
42		let unpause_origin = T::UnpauseOrigin::try_successful_origin()
43			.expect("Tx-pause pallet is not usable without pause origin");
44		let full_name = name::<T>();
45		TxPause::<T>::do_pause(full_name.clone()).unwrap();
46
47		#[extrinsic_call]
48		_(unpause_origin as T::RuntimeOrigin, full_name.clone());
49
50		assert!(PausedCalls::<T>::get(full_name).is_none());
51	}
52
53	impl_benchmark_test_suite!(TxPause, crate::mock::new_test_ext(), crate::mock::Test);
54}
55
56/// Longest possible name.
57fn name<T: Config>() -> RuntimeCallNameOf<T> {
58	let max_len = T::MaxNameLen::get() as usize;
59	(vec![1; max_len].try_into().unwrap(), vec![1; max_len].try_into().unwrap())
60}