polkadot_runtime_parachains/initializer/benchmarking.rs
1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16
17use super::*;
18use frame_benchmarking::v2::*;
19use frame_system::RawOrigin;
20use polkadot_primitives::ConsensusLog;
21use sp_runtime::DigestItem;
22
23// Random large number for the digest
24const DIGEST_MAX_LEN: u32 = 65536;
25
26#[benchmarks]
27mod benchmarks {
28 use super::*;
29
30 #[benchmark]
31 fn force_approve(d: Linear<0, DIGEST_MAX_LEN>) -> Result<(), BenchmarkError> {
32 for _ in 0..d {
33 frame_system::Pallet::<T>::deposit_log(ConsensusLog::ForceApprove(d).into());
34 }
35
36 #[extrinsic_call]
37 _(RawOrigin::Root, d + 1);
38
39 assert_eq!(
40 frame_system::Pallet::<T>::digest().logs.last().unwrap(),
41 &DigestItem::from(ConsensusLog::ForceApprove(d + 1)),
42 );
43
44 Ok(())
45 }
46
47 impl_benchmark_test_suite!(
48 Pallet,
49 crate::mock::new_test_ext(Default::default()),
50 crate::mock::Test
51 );
52}