mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Add benchmark to node-template pallet-template (#8239)
* Add benchmark to node-template pallet-template * export sp_std to avoid missing dep when using macro * fix more `sp_std` deps * remove unused * Update bin/node-template/pallets/template/src/benchmarking.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update bin/node-template/pallets/template/Cargo.toml Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -25,6 +25,12 @@ default-features = false
|
||||
version = "3.0.0"
|
||||
path = "../../../../frame/system"
|
||||
|
||||
[dependencies.frame-benchmarking]
|
||||
default-features = false
|
||||
version = "3.1.0"
|
||||
path = "../../../../frame/benchmarking"
|
||||
optional = true
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0.101" }
|
||||
|
||||
@@ -43,12 +49,13 @@ default-features = false
|
||||
version = "3.0.0"
|
||||
path = "../../../../primitives/runtime"
|
||||
|
||||
|
||||
[features]
|
||||
default = ['std']
|
||||
std = [
|
||||
'codec/std',
|
||||
'frame-support/std',
|
||||
'frame-system/std'
|
||||
'frame-system/std',
|
||||
'frame-benchmarking/std',
|
||||
]
|
||||
runtime-benchmarks = ["frame-benchmarking"]
|
||||
try-runtime = ["frame-support/try-runtime"]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//! Benchmarking setup for pallet-template
|
||||
|
||||
use super::*;
|
||||
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
|
||||
#[allow(unused)]
|
||||
use crate::Module as Template;
|
||||
|
||||
benchmarks! {
|
||||
do_something {
|
||||
let s in 0 .. 100;
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
}: _(RawOrigin::Signed(caller), s)
|
||||
verify {
|
||||
assert_eq!(Something::<T>::get(), Some(s));
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Template,
|
||||
crate::mock::new_test_ext(),
|
||||
crate::mock::Test,
|
||||
);
|
||||
@@ -12,6 +12,9 @@ mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
|
||||
@@ -46,7 +49,7 @@ pub mod pallet {
|
||||
/// parameters. [something, who]
|
||||
SomethingStored(u32, T::AccountId),
|
||||
}
|
||||
|
||||
|
||||
// Errors inform users that something went wrong.
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
|
||||
@@ -89,4 +89,5 @@ runtime-benchmarks = [
|
||||
"frame-system/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"template/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -475,6 +475,7 @@ impl_runtime_apis! {
|
||||
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
|
||||
add_benchmark!(params, batches, pallet_balances, Balances);
|
||||
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
|
||||
add_benchmark!(params, batches, template, TemplateModule);
|
||||
|
||||
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
|
||||
Ok(batches)
|
||||
|
||||
Reference in New Issue
Block a user