3

Is there a way to benchmark an extrinsic whose expected behavior is to trigger an error?

I stumbled on a project where we have two instances of the same pallet. Instance1 will proceed normally for a given extrinsic, but Instance2 will intentionally fail (based on runtime condition setup for this instance), triggering an error.

I wonder if there is a way to benchmark the extrinsic for the failing condition and if not, how to gracefully handle this case.

1 Answer 1

3

You can benchmark failing calls. However, we normally don't do so since a failing transaction does not persist its changes to the DB, and that is normally the slowest part.

Keep in mind that you only have to benchmark the slowest path. Now if your slowest path is returning an error, then you indeed have to use that.
You can write it like this:

fail {
    let caller = RawOrigin::Signed(whitelisted_caller());
}: {
    Pallet::<T>::fail(caller.into()).expect_err("Should fail");
}

to be really correct it should exclude the overhead for the BaseCallFilter, so rather use:

fail {
    let caller = RawOrigin::Signed(whitelisted_caller());
    let call = Call::<T>::fail{};
}: {
    call.dispatch_bypass_filter(caller.into()).expect_err("Fails");
}

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.