referrerpolicy=no-referrer-when-downgrade

pallet_remark/
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//! Benchmarks for remarks pallet
19
20#![cfg(feature = "runtime-benchmarks")]
21
22use super::*;
23use alloc::vec;
24use frame_benchmarking::v2::*;
25use frame_system::{EventRecord, Pallet as System, RawOrigin};
26
27#[cfg(test)]
28use crate::Pallet as Remark;
29
30fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
31	let events = System::<T>::events();
32	let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
33	let EventRecord { event, .. } = &events[events.len() - 1];
34	assert_eq!(event, &system_event);
35}
36
37#[benchmarks]
38mod benchmarks {
39	use super::*;
40
41	#[benchmark]
42	fn store(l: Linear<1, { 1024 * 1024 }>) {
43		let caller: T::AccountId = whitelisted_caller();
44
45		#[extrinsic_call]
46		_(RawOrigin::Signed(caller.clone()), vec![0u8; l as usize]);
47
48		assert_last_event::<T>(
49			Event::Stored {
50				sender: caller,
51				content_hash: sp_io::hashing::blake2_256(&vec![0u8; l as usize]).into(),
52			}
53			.into(),
54		);
55	}
56
57	impl_benchmark_test_suite!(Remark, crate::mock::new_test_ext(), crate::mock::Test);
58}