Use proper weights in the pallet-template (#13817)

* benchmarking to generate weights file

* add the calculated weights in the extrinsics

* use benchmarking v2 syntax to generate the weights

* minor syntax change when benchmarking

* added WeightInfo in the mock to pass tests

* minor cargo fmt format changes
This commit is contained in:
alexd10s
2023-04-06 12:27:43 +01:00
committed by GitHub
parent 0b3444c51d
commit 0d7402eb8c
7 changed files with 125 additions and 10 deletions
@@ -1,19 +1,34 @@
//! Benchmarking setup for pallet-template
#![cfg(feature = "runtime-benchmarks")]
use super::*;
#[allow(unused)]
use crate::Pallet as Template;
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
benchmarks! {
do_something {
let s in 0 .. 100;
#[benchmarks]
mod benchmarks {
use super::*;
#[benchmark]
fn do_something() {
let value = 100u32.into();
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), s)
verify {
assert_eq!(Something::<T>::get(), Some(s));
#[extrinsic_call]
do_something(RawOrigin::Signed(caller), value);
assert_eq!(Something::<T>::get(), Some(value));
}
#[benchmark]
fn cause_error() {
Something::<T>::put(100u32);
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
cause_error(RawOrigin::Signed(caller));
assert_eq!(Something::<T>::get(), Some(101u32));
}
impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);