mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Allow where clause in benchmarking (#6461)
* WIP * handle where clause in benchmarking * doc * maybe better syntax * line width
This commit is contained in:
committed by
GitHub
parent
fb56eacd8d
commit
ff897c1acc
@@ -30,13 +30,17 @@ use frame_support::{
|
||||
use frame_system::{RawOrigin, ensure_signed, ensure_none};
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Test {
|
||||
trait Store for Module<T: Trait> as Test where
|
||||
<T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event>
|
||||
{
|
||||
Value get(fn value): Option<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
pub struct Module<T: Trait> for enum Call where
|
||||
origin: T::Origin, <T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event>
|
||||
{
|
||||
#[weight = 0]
|
||||
fn set_value(origin, n: u32) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
@@ -56,11 +60,16 @@ impl_outer_origin! {
|
||||
pub enum Origin for Test where system = frame_system {}
|
||||
}
|
||||
|
||||
pub trait Trait {
|
||||
pub trait OtherTrait {
|
||||
type OtherEvent;
|
||||
}
|
||||
|
||||
pub trait Trait: OtherTrait where Self::OtherEvent: Into<Self::Event> {
|
||||
type Event;
|
||||
type BlockNumber;
|
||||
type AccountId: 'static + Default + Decode;
|
||||
type Origin: From<frame_system::RawOrigin<Self::AccountId>> + Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>;
|
||||
type Origin: From<frame_system::RawOrigin<Self::AccountId>> +
|
||||
Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
@@ -100,6 +109,10 @@ impl Trait for Test {
|
||||
type AccountId = u64;
|
||||
}
|
||||
|
||||
impl OtherTrait for Test {
|
||||
type OtherEvent = ();
|
||||
}
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
@@ -107,6 +120,8 @@ fn new_test_ext() -> sp_io::TestExternalities {
|
||||
}
|
||||
|
||||
benchmarks!{
|
||||
where_clause { where <T as OtherTrait>::OtherEvent: Into<<T as Trait>::Event> }
|
||||
|
||||
_ {
|
||||
// Define a common range for `b`.
|
||||
let b in 1 .. 1000 => ();
|
||||
@@ -156,13 +171,13 @@ benchmarks!{
|
||||
#[test]
|
||||
fn benchmarks_macro_works() {
|
||||
// Check benchmark creation for `set_value`.
|
||||
let selected_benchmark = SelectedBenchmark::set_value;
|
||||
let selected = SelectedBenchmark::set_value;
|
||||
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected);
|
||||
assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]);
|
||||
|
||||
let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
|
||||
&selected_benchmark,
|
||||
&selected,
|
||||
&[(BenchmarkParameter::b, 1)],
|
||||
).expect("failed to create closure");
|
||||
|
||||
@@ -174,12 +189,12 @@ fn benchmarks_macro_works() {
|
||||
#[test]
|
||||
fn benchmarks_macro_rename_works() {
|
||||
// Check benchmark creation for `other_dummy`.
|
||||
let selected_benchmark = SelectedBenchmark::other_name;
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
|
||||
let selected = SelectedBenchmark::other_name;
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected);
|
||||
assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]);
|
||||
|
||||
let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
|
||||
&selected_benchmark,
|
||||
&selected,
|
||||
&[(BenchmarkParameter::b, 1)],
|
||||
).expect("failed to create closure");
|
||||
|
||||
@@ -190,13 +205,13 @@ fn benchmarks_macro_rename_works() {
|
||||
|
||||
#[test]
|
||||
fn benchmarks_macro_works_for_non_dispatchable() {
|
||||
let selected_benchmark = SelectedBenchmark::sort_vector;
|
||||
let selected = SelectedBenchmark::sort_vector;
|
||||
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
|
||||
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected);
|
||||
assert_eq!(components, vec![(BenchmarkParameter::x, 1, 10000)]);
|
||||
|
||||
let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
|
||||
&selected_benchmark,
|
||||
&selected,
|
||||
&[(BenchmarkParameter::x, 1)],
|
||||
).expect("failed to create closure");
|
||||
|
||||
@@ -206,10 +221,10 @@ fn benchmarks_macro_works_for_non_dispatchable() {
|
||||
#[test]
|
||||
fn benchmarks_macro_verify_works() {
|
||||
// Check postcondition for benchmark `set_value` is valid.
|
||||
let selected_benchmark = SelectedBenchmark::set_value;
|
||||
let selected = SelectedBenchmark::set_value;
|
||||
|
||||
let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::verify(
|
||||
&selected_benchmark,
|
||||
&selected,
|
||||
&[(BenchmarkParameter::b, 1)],
|
||||
).expect("failed to create closure");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user