mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
fix(pallet-benchmarking): split test functions in v2 (#3574)
Closes #376 --------- Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
629506ce06
commit
f4fbddec42
@@ -26,7 +26,7 @@ use core::{
|
||||
};
|
||||
use sp_runtime::traits::{Bounded, Hash, StaticLookup};
|
||||
|
||||
use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*, BenchmarkError};
|
||||
use frame_benchmarking::{account, v2::*, BenchmarkError};
|
||||
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
|
||||
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin};
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@ use super::*;
|
||||
|
||||
use crate::Pallet as Identity;
|
||||
use codec::Encode;
|
||||
use frame_benchmarking::{
|
||||
account, impl_benchmark_test_suite, v2::*, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_benchmarking::{account, v2::*, whitelisted_caller, BenchmarkError};
|
||||
use frame_support::{
|
||||
assert_ok, ensure,
|
||||
traits::{EnsureOrigin, Get, OnFinalize, OnInitialize},
|
||||
|
||||
@@ -23,7 +23,6 @@ use super::*;
|
||||
|
||||
use crate::Pallet as Lottery;
|
||||
use frame_benchmarking::{
|
||||
impl_benchmark_test_suite,
|
||||
v1::{account, whitelisted_caller, BenchmarkError},
|
||||
v2::*,
|
||||
};
|
||||
|
||||
@@ -431,7 +431,7 @@ pub fn benchmarks(
|
||||
let mut benchmarks_by_name_mappings: Vec<TokenStream2> = Vec::new();
|
||||
let test_idents: Vec<Ident> = benchmark_names_str
|
||||
.iter()
|
||||
.map(|n| Ident::new(format!("test_{}", n).as_str(), Span::call_site()))
|
||||
.map(|n| Ident::new(format!("test_benchmark_{}", n).as_str(), Span::call_site()))
|
||||
.collect();
|
||||
for i in 0..benchmark_names.len() {
|
||||
let name_ident = &benchmark_names[i];
|
||||
@@ -441,6 +441,37 @@ pub fn benchmarks(
|
||||
benchmarks_by_name_mappings.push(quote!(#name_str => Self::#test_ident()))
|
||||
}
|
||||
|
||||
let impl_test_function = content
|
||||
.iter_mut()
|
||||
.find_map(|item| {
|
||||
let Item::Macro(item_macro) = item else {
|
||||
return None;
|
||||
};
|
||||
|
||||
if !item_macro
|
||||
.mac
|
||||
.path
|
||||
.segments
|
||||
.iter()
|
||||
.any(|s| s.ident == "impl_benchmark_test_suite")
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let tokens = item_macro.mac.tokens.clone();
|
||||
*item = Item::Verbatim(quote! {});
|
||||
|
||||
Some(quote! {
|
||||
impl_test_function!(
|
||||
(#( {} #benchmark_names )*)
|
||||
(#( #extra_benchmark_names )*)
|
||||
(#( #skip_meta_benchmark_names )*)
|
||||
#tokens
|
||||
);
|
||||
})
|
||||
})
|
||||
.unwrap_or(quote! {});
|
||||
|
||||
// emit final quoted tokens
|
||||
let res = quote! {
|
||||
#(#mod_attrs)
|
||||
@@ -676,6 +707,8 @@ pub fn benchmarks(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#impl_test_function
|
||||
}
|
||||
#mod_vis use #mod_name::*;
|
||||
};
|
||||
@@ -733,7 +766,8 @@ fn expand_benchmark(
|
||||
let setup_stmts = benchmark_def.setup_stmts;
|
||||
let verify_stmts = benchmark_def.verify_stmts;
|
||||
let last_stmt = benchmark_def.last_stmt;
|
||||
let test_ident = Ident::new(format!("test_{}", name.to_string()).as_str(), Span::call_site());
|
||||
let test_ident =
|
||||
Ident::new(format!("test_benchmark_{}", name.to_string()).as_str(), Span::call_site());
|
||||
|
||||
// unroll params (prepare for quoting)
|
||||
let unrolled = UnrolledParams::from(&benchmark_def.params);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*, BenchmarkError};
|
||||
use frame_benchmarking::{account, v2::*, BenchmarkError};
|
||||
use frame_support::{
|
||||
dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo},
|
||||
weights::Weight,
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use codec::Encode;
|
||||
use frame_benchmarking::{impl_benchmark_test_suite, v2::*};
|
||||
use frame_benchmarking::v2::*;
|
||||
use frame_support::{dispatch::DispatchClass, storage, traits::Get};
|
||||
use frame_system::{Call, Pallet as System, RawOrigin};
|
||||
use sp_core::storage::well_known_keys;
|
||||
|
||||
Reference in New Issue
Block a user