From 37ff3c0d2da37efd6a8d9ae78d4f6abeb57a31ca Mon Sep 17 00:00:00 2001 From: pgherveou Date: Tue, 2 Apr 2024 17:41:39 +0200 Subject: [PATCH] Fix test --- substrate/frame/benchmarking/src/v1.rs | 14 +++++--------- .../frame/support/procedural/src/benchmark.rs | 17 +++++------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/substrate/frame/benchmarking/src/v1.rs b/substrate/frame/benchmarking/src/v1.rs index af857d50a616f..068f951278343 100644 --- a/substrate/frame/benchmarking/src/v1.rs +++ b/substrate/frame/benchmarking/src/v1.rs @@ -1078,10 +1078,6 @@ macro_rules! impl_benchmark { // Always reset the state after the benchmark. $crate::__private::defer!($crate::benchmarking::wipe_db()); - // Set the block number to at least 1 so events are deposited. - if $crate::__private::Zero::is_zero(&frame_system::Pallet::::block_number()) { - frame_system::Pallet::::set_block_number(1u32.into()); - } $crate::__private::log::trace!( target: "benchmark", @@ -1095,6 +1091,11 @@ macro_rules! impl_benchmark { // benchmark. let whitelist = whitelist.clone(); let mut recording = $crate::BenchmarkRecording::new($crate::__private::Box::new(move || { + // Set the block number to at least 1 so events are deposited. + if $crate::__private::Zero::is_zero(&frame_system::Pallet::::block_number()) { + frame_system::Pallet::::set_block_number(1u32.into()); + } + // Commit the externalities to the database, flushing the DB cache. // This will enable worst case scenario for reading from the database. $crate::benchmarking::commit_db(); @@ -1222,11 +1223,6 @@ macro_rules! impl_benchmark_test { // Always reset the state after the benchmark. $crate::__private::defer!($crate::benchmarking::wipe_db()); - // Set the block number to at least 1 so events are deposited. - if $crate::__private::Zero::is_zero(&frame_system::Pallet::::block_number()) { - frame_system::Pallet::::set_block_number(1u32.into()); - } - // Run execution + verification >::test_instance(&selected_benchmark, &c) }; diff --git a/substrate/frame/support/procedural/src/benchmark.rs b/substrate/frame/support/procedural/src/benchmark.rs index a2d4ae545c304..4d83f5067b13e 100644 --- a/substrate/frame/support/procedural/src/benchmark.rs +++ b/substrate/frame/support/procedural/src/benchmark.rs @@ -739,10 +739,6 @@ pub fn benchmarks( #krate::__private::defer!(#krate::benchmarking::wipe_db()); // Set the block number to at least 1 so events are deposited. - if #krate::__private::Zero::is_zero(&#frame_system::Pallet::::block_number()) { - #frame_system::Pallet::::set_block_number(1u32.into()); - } - #krate::__private::log::trace!( target: "benchmark", "Start Benchmark: {} ({:?})", @@ -752,6 +748,10 @@ pub fn benchmarks( let whitelist = whitelist.clone(); let mut recording = #krate::BenchmarkRecording::new(#krate::__private::Box::new(move || { + if #krate::__private::Zero::is_zero(&#frame_system::Pallet::::block_number()) { + #frame_system::Pallet::::set_block_number(1u32.into()); + } + // Commit the externalities to the database, flushing the DB cache. // This will enable worst case scenario for reading from the database. #krate::benchmarking::commit_db(); @@ -1113,14 +1113,7 @@ fn expand_benchmark( | -> Result<(), #krate::BenchmarkError> { // Always reset the state after the benchmark. #krate::__private::defer!(#krate::benchmarking::wipe_db()); - - // Set the block number to at least 1 so events are deposited. - if #krate::__private::Zero::is_zero(&#frame_system::Pallet::::block_number()) { - #frame_system::Pallet::::set_block_number(1u32.into()); - } - - // Run execution + verification - < SelectedBenchmark as #krate::BenchmarkingSetup >::test_instance(&selected_benchmark, &c) + >::test_instance(&selected_benchmark, &c) }; if components.is_empty() {