diff --git a/substrate/frame/benchmarking/src/lib.rs b/substrate/frame/benchmarking/src/lib.rs index 42eeac483f..11c755e06c 100644 --- a/substrate/frame/benchmarking/src/lib.rs +++ b/substrate/frame/benchmarking/src/lib.rs @@ -644,7 +644,7 @@ macro_rules! benchmark_backend { &self, components: &[($crate::BenchmarkParameter, u32)], verify: bool - ) -> Result<$crate::Box Result<(), $crate::BenchmarkError>>, &'static str> { + ) -> Result<$crate::Box Result<(), $crate::BenchmarkError>>, $crate::BenchmarkError> { $( // Prepare instance let $param = components.iter() @@ -717,7 +717,7 @@ macro_rules! selected_benchmark { &self, components: &[($crate::BenchmarkParameter, u32)], verify: bool - ) -> Result<$crate::Box Result<(), $crate::BenchmarkError>>, &'static str> { + ) -> Result<$crate::Box Result<(), $crate::BenchmarkError>>, $crate::BenchmarkError> { match self { $( Self::$bench => < @@ -1246,7 +1246,7 @@ macro_rules! impl_benchmark_test_suite { } } }, - Ok(Ok(_)) => (), + Ok(Ok(())) => (), } } assert!(!anything_failed); diff --git a/substrate/frame/benchmarking/src/tests.rs b/substrate/frame/benchmarking/src/tests.rs index af9a4e7f4a..a2cf381e6e 100644 --- a/substrate/frame/benchmarking/src/tests.rs +++ b/substrate/frame/benchmarking/src/tests.rs @@ -41,6 +41,7 @@ mod pallet_test { pub trait Config: frame_system::Config { type LowerBound: Get; type UpperBound: Get; + type MaybeItem: Get>; } #[pallet::storage] @@ -112,11 +113,13 @@ impl frame_system::Config for Test { parameter_types! { pub const LowerBound: u32 = 1; pub const UpperBound: u32 = 100; + pub const MaybeItem: Option = None; } impl pallet_test::Config for Test { type LowerBound = LowerBound; type UpperBound = UpperBound; + type MaybeItem = MaybeItem; } fn new_test_ext() -> sp_io::TestExternalities { @@ -218,6 +221,13 @@ mod benchmarks { } ))?; } + + skip_benchmark { + let value = T::MaybeItem::get().ok_or(BenchmarkError::Skip)?; + }: { + // This should never be reached. + assert!(value > 100); + } } #[test] @@ -334,6 +344,11 @@ mod benchmarks { assert_err!(Pallet::::test_benchmark_bad_verify(), "You forgot to sort!"); assert_ok!(Pallet::::test_benchmark_no_components()); assert_ok!(Pallet::::test_benchmark_variable_components()); + assert!(matches!( + Pallet::::test_benchmark_override_benchmark(), + Err(BenchmarkError::Override(_)), + )); + assert_eq!(Pallet::::test_benchmark_skip_benchmark(), Err(BenchmarkError::Skip),); }); } } diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index d54e32f0ce..158f5c5b57 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -318,7 +318,7 @@ pub trait BenchmarkingSetup { &self, components: &[(BenchmarkParameter, u32)], verify: bool, - ) -> Result Result<(), BenchmarkError>>, &'static str>; + ) -> Result Result<(), BenchmarkError>>, BenchmarkError>; } /// Grab an account, seeded by a name and index. diff --git a/substrate/frame/bounties/src/benchmarking.rs b/substrate/frame/bounties/src/benchmarking.rs index 832c053f02..798d929d24 100644 --- a/substrate/frame/bounties/src/benchmarking.rs +++ b/substrate/frame/bounties/src/benchmarking.rs @@ -134,7 +134,8 @@ benchmarks! { Bounties::::on_initialize(T::BlockNumber::zero()); let bounty_id = BountyCount::get() - 1; - let curator = T::Lookup::lookup(curator_lookup)?; + let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?; + let beneficiary = T::Lookup::unlookup(account("beneficiary", 0, SEED)); }: _(RawOrigin::Signed(curator), bounty_id, beneficiary) @@ -144,7 +145,8 @@ benchmarks! { Bounties::::on_initialize(T::BlockNumber::zero()); let bounty_id = BountyCount::get() - 1; - let curator = T::Lookup::lookup(curator_lookup)?; + let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?; + let beneficiary_account: T::AccountId = account("beneficiary", 0, SEED); let beneficiary = T::Lookup::unlookup(beneficiary_account.clone()); @@ -181,7 +183,7 @@ benchmarks! { Bounties::::on_initialize(T::BlockNumber::zero()); let bounty_id = BountyCount::get() - 1; - let curator = T::Lookup::lookup(curator_lookup)?; + let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?; }: _(RawOrigin::Signed(curator), bounty_id, Vec::new()) verify { assert_last_event::(RawEvent::BountyExtended(bounty_id).into()) diff --git a/substrate/frame/collective/Cargo.toml b/substrate/frame/collective/Cargo.toml index 4b1051e793..722309ee90 100644 --- a/substrate/frame/collective/Cargo.toml +++ b/substrate/frame/collective/Cargo.toml @@ -39,6 +39,7 @@ std = [ "sp-runtime/std", "frame-system/std", "log/std", + "frame-benchmarking/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/substrate/frame/contracts/src/benchmarking/mod.rs b/substrate/frame/contracts/src/benchmarking/mod.rs index 74877e5b83..db657e6183 100644 --- a/substrate/frame/contracts/src/benchmarking/mod.rs +++ b/substrate/frame/contracts/src/benchmarking/mod.rs @@ -1213,7 +1213,7 @@ benchmarks! { for addr in &addresses { if let Some(_) = ContractInfoOf::::get(&addr) { - return Err("Expected that contract does not exist at this point."); + return Err("Expected that contract does not exist at this point.".into()); } } }: call(origin, callee, 0u32.into(), Weight::max_value(), vec![]) @@ -2241,7 +2241,7 @@ benchmarks! { ); } #[cfg(not(feature = "std"))] - return Err("Run this bench with a native runtime in order to see the schedule."); + return Err("Run this bench with a native runtime in order to see the schedule.".into()); }: {} // Execute one erc20 transfer using the ink! erc20 example contract. diff --git a/substrate/frame/election-provider-multi-phase/src/benchmarking.rs b/substrate/frame/election-provider-multi-phase/src/benchmarking.rs index 9c734c4823..154d3b2f26 100644 --- a/substrate/frame/election-provider-multi-phase/src/benchmarking.rs +++ b/substrate/frame/election-provider-multi-phase/src/benchmarking.rs @@ -278,7 +278,8 @@ frame_benchmarking::benchmarks! { let witness = SolutionOrSnapshotSize { voters: v, targets: t }; let raw_solution = solution_with_size::(witness, a, d)?; let ready_solution = - >::feasibility_check(raw_solution, ElectionCompute::Signed)?; + >::feasibility_check(raw_solution, ElectionCompute::Signed) + .map_err(<&str>::from)?; >::put(Phase::Signed); // assume a queued solution is stored, regardless of where it comes from. >::put(ready_solution); @@ -307,7 +308,7 @@ frame_benchmarking::benchmarks! { ..Default::default() }; - >::create_snapshot()?; + >::create_snapshot().map_err(<&str>::from)?; MultiPhase::::on_initialize_open_signed(); >::put(1); diff --git a/substrate/frame/im-online/src/benchmarking.rs b/substrate/frame/im-online/src/benchmarking.rs index 4000ce339a..2a2d837a4b 100644 --- a/substrate/frame/im-online/src/benchmarking.rs +++ b/substrate/frame/im-online/src/benchmarking.rs @@ -83,7 +83,7 @@ benchmarks! { let call = Call::heartbeat(input_heartbeat, signature); }: { ImOnline::::validate_unsigned(TransactionSource::InBlock, &call) - .map_err(|e| -> &'static str { e.into() })?; + .map_err(<&str>::from)?; } validate_unsigned_and_then_heartbeat { @@ -93,7 +93,7 @@ benchmarks! { let call = Call::heartbeat(input_heartbeat, signature); }: { ImOnline::::validate_unsigned(TransactionSource::InBlock, &call) - .map_err(|e| -> &'static str { e.into() })?; + .map_err(<&str>::from)?; call.dispatch_bypass_filter(RawOrigin::None.into())?; } } diff --git a/substrate/frame/indices/Cargo.toml b/substrate/frame/indices/Cargo.toml index 1ef4527f60..c226ea2cf2 100644 --- a/substrate/frame/indices/Cargo.toml +++ b/substrate/frame/indices/Cargo.toml @@ -42,5 +42,6 @@ std = [ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/multisig/Cargo.toml b/substrate/frame/multisig/Cargo.toml index 7ccdf7c7a0..8431425649 100644 --- a/substrate/frame/multisig/Cargo.toml +++ b/substrate/frame/multisig/Cargo.toml @@ -39,5 +39,6 @@ std = [ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"]