Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 346471d

Browse files
authored
Short circuit Treasury::Spend benchmark for NeverEnsureOrigin (#11562)
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: parity-processbot <>
1 parent 3bfb4cc commit 346471d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

frame/treasury/src/benchmarking.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,22 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
6666
}
6767

6868
benchmarks_instance_pallet! {
69+
// This benchmark is short-circuited if `SpendOrigin` cannot provide
70+
// a successful origin, in which case `spend` is un-callable and can use weight=0.
6971
spend {
7072
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
71-
let origin = T::SpendOrigin::successful_origin();
73+
let origin = T::SpendOrigin::try_successful_origin();
7274
let beneficiary = T::Lookup::lookup(beneficiary_lookup.clone()).unwrap();
7375
let call = Call::<T, I>::spend { amount: value, beneficiary: beneficiary_lookup };
74-
}: { call.dispatch_bypass_filter(origin)? }
76+
}: {
77+
if let Ok(origin) = origin.clone() {
78+
call.dispatch_bypass_filter(origin)?;
79+
}
80+
}
7581
verify {
76-
assert_last_event::<T, I>(Event::SpendApproved { proposal_index: 0, amount: value, beneficiary }.into())
82+
if origin.is_ok() {
83+
assert_last_event::<T, I>(Event::SpendApproved { proposal_index: 0, amount: value, beneficiary }.into())
84+
}
7785
}
7886

7987
propose_spend {

0 commit comments

Comments
 (0)