From d9ca9b42fd40abe611dd199b9e9ea15942d17ace Mon Sep 17 00:00:00 2001 From: Kazunobu Ndong Date: Tue, 1 Aug 2023 14:01:06 +0900 Subject: [PATCH] Updated benchmarking --- pallets/roles/src/benchmarking.rs | 36 +++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/pallets/roles/src/benchmarking.rs b/pallets/roles/src/benchmarking.rs index 3b67fa64..c55d626d 100644 --- a/pallets/roles/src/benchmarking.rs +++ b/pallets/roles/src/benchmarking.rs @@ -1,20 +1,38 @@ //! Benchmarking setup for pallet-template - +#![cfg(feature = "runtime-benchmarks")] use super::*; + + #[allow(unused)] use crate::Pallet as Roles; -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(); + #[extrinsic_call] + do_something(RawOrigin::Signed(caller), value); + + assert_eq!(Something::::get(), Some(value)); + } + + #[benchmark] + fn cause_error() { + Something::::put(100u32); let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), s) - verify { - assert_eq!(Something::::get(), Some(s)); + #[extrinsic_call] + cause_error(RawOrigin::Signed(caller)); + + assert_eq!(Something::::get(), Some(101u32)); } - impl_benchmark_test_suite!(Roles, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); } +