Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions substrate/frame/support/procedural/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use derive_syn_parse::Parse;
use frame_support_procedural_tools::generate_access_from_frame_or_crate;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens};
use quote::{quote, quote_spanned, ToTokens};
use syn::{
parse::{Nothing, ParseStream},
parse_quote,
Expand Down Expand Up @@ -959,12 +959,12 @@ fn expand_benchmark(
let origin = match origin {
Expr::Cast(t) => {
let ty = t.ty.clone();
quote! {
quote_spanned! { origin.span() =>
<<T as #frame_system::Config>::RuntimeOrigin as From<#ty>>::from(#origin);
}
},
_ => quote! {
#origin.into();
_ => quote_spanned! { origin.span() =>
Into::<<T as #frame_system::Config>::RuntimeOrigin>::into(#origin);
},
};

Expand Down Expand Up @@ -1008,6 +1008,7 @@ fn expand_benchmark(
let __call_decoded = <Call<#type_use_generics> as #codec::Decode>
::decode(&mut &__benchmarked_call_encoded[..])
.expect("call is encoded above, encoding must be correct");
#[allow(clippy::useless_conversion)]
let __origin = #origin;
<Call<#type_use_generics> as #traits::UnfilteredDispatchable>::dispatch_bypass_filter(
__call_decoded,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use frame_benchmarking::v2::*;

#[frame_support::pallet]
mod pallet {
use frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {}

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(1)]
#[pallet::weight(Weight::default())]
pub fn call_1(_origin: OriginFor<T>) -> DispatchResult {
Ok(())
}
}
}

pub use pallet::*;

#[benchmarks]
mod benches {
use super::*;
use frame_support::traits::OriginTrait;

#[benchmark]
fn call_1() {
let origin = 3u8;
#[extrinsic_call]
_(origin);
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: unused import: `frame_support::traits::OriginTrait`
--> tests/benchmark_ui/extrinsic_call_wrong_origin.rs:46:6
|
46 | use frame_support::traits::OriginTrait;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D unused-imports` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unused_imports)]`

error[E0277]: the trait bound `<T as frame_system::Config>::RuntimeOrigin: From<u8>` is not satisfied
--> tests/benchmark_ui/extrinsic_call_wrong_origin.rs:52:5
|
52 | _(origin);
| ^^^^^^ the trait `From<u8>` is not implemented for `<T as frame_system::Config>::RuntimeOrigin`
|
= note: required for `u8` to implement `Into<<T as frame_system::Config>::RuntimeOrigin>`
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
error[E0277]: the trait bound `T: frame_system::Config` is not satisfied
--> tests/benchmark_ui/invalid_origin.rs:30:8
|
30 | noop(1);
| ^ the trait `frame_system::Config` is not implemented for `T`
|
help: consider further restricting type parameter `T`
|
23 | #[benchmarks], T: frame_system::Config
| +++++++++++++++++++++++++

error[E0277]: the trait bound `<T as frame_support_test::Config>::RuntimeOrigin: From<{integer}>` is not satisfied
--> tests/benchmark_ui/invalid_origin.rs:23:1
--> tests/benchmark_ui/invalid_origin.rs:30:8
|
23 | #[benchmarks]
| ^^^^^^^^^^^^^ the trait `From<{integer}>` is not implemented for `<T as frame_support_test::Config>::RuntimeOrigin`
30 | noop(1);
| ^ the trait `From<{integer}>` is not implemented for `<T as frame_support_test::Config>::RuntimeOrigin`
|
= note: required for `{integer}` to implement `Into<<T as frame_support_test::Config>::RuntimeOrigin>`
= note: this error originates in the attribute macro `benchmarks` (in Nightly builds, run with -Z macro-backtrace for more info)
Loading