5

In Config of my pallet I have:

type FilteredOrigin: EnsureOriginWithArg<
            Self::RuntimeOrigin,
            SomeEnum,
            Success = Self::AccountId
        >;

And there is an extrinsic in my pallet extrinsic_name where i do a check T::FilteredOrigin::ensure_origin(origin)

Firstly I wrote the bench like this using v1:

    extrinsic_name{
        let origin = T::FilteredOrigin::try_successful_origin(&SomeEnum::SomeOption).unwrap();
        // omitted
        let data = Data {...};
    }: _(origin, data)

And got the following error: expected associated type <T as frame_system::Config>::RuntimeOrigin found enum Result<RawOrigin<<T as frame_system::Config>::AccountId>, <T as frame_system::Config>::RuntimeOrigin>

Then I found a solution in one of the frame's pallets (<T::RuntimeOrigin> added):

    extrinsic_name{
        let origin = T::FilteredOrigin::try_successful_origin(&SomeEnum::SomeOption).unwrap();
        // omitted
        let data = Data {...};
    }: _<T::RuntimeOrigin>(origin, data)

Now I'm trying to use frame_benchmarking::v2, I have written the following code and got the same error:

#[benchmarks]
mod benchmarks {
    use super::*;

    #[benchmark]
    fn extrinsic_name() {
        let origin = T::FilteredOrigin::try_successful_origin(&SomeEnum::SomeOption).unwrap();
        
        // omitted
        let data = Data {...};

        #[extrinsic_call]
        _(origin, data);
    }
}

I guess the solution is described in the doc, also there is an example of doing similar thing in the pallet-lottery and I should do this way:

#[benchmarks]
mod benchmarks {
    use super::*;

    #[benchmark]
    fn extrinsic_name() {
        let origin = T::FilteredOrigin::try_successful_origin(&SomeEnum::SomeOption).unwrap();
        
        // omitted
        let data = Data {...};

        #[extrinsic_call]
        _(origin as T::RuntimeOrigin, data);
    }
}

But compiler complains to this casting. On the other hand this is working in pallet-lottery. Could someone please clarify the problem occured here and point out what am I doing wrong?

2
  • Do you have the source code handy or some reproducible example? It should work as you described in the last block of code. Could be that you are not yet using the version where we fixed that. I tried it locally and it works for me so far. Jun 7 at 13:37
  • @OliverTale-Yazdi I am using polkadot-v0.9.40 branch for frame-benchmarking or 4.0.0-dev version as it set in Cargo.lock Jun 7 at 13:40

1 Answer 1

2

This is a bug that was fixed in #13845. It is included in Substrate tag polkadot-v0.9.42.

So please update to that version or remain with the V1 benchmarking.
If you find any more bugs, please report them on GitHub. The V2 syntax is not stabilized yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.