Skip to content

Commit

Permalink
pallet-treasury: Improve remove_approval benchmark (paritytech#5713)
Browse files Browse the repository at this point in the history
When `SpendOrigin` doesn't return any `succesful_origin`, it doesn't
mean that `RejectOrigin` will do the same. Thus, this pr fixes a
potential wrong benchmarked weight for when `SpendOrigin` is set to e.g.
`NeverOrigin`.
  • Loading branch information
bkchr authored Sep 17, 2024
1 parent 43cd6fd commit 9cdbdc5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
10 changes: 10 additions & 0 deletions prdoc/pr_5713.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "pallet-treasury: Improve `remove_approval` benchmark"

doc:
- audience: Runtime Dev
description: |
Fix the `remove_approval` benchmark when `SpendOrigin` doesn't return any `succesful_origin`.

crates:
- name: pallet-treasury
bump: patch
29 changes: 22 additions & 7 deletions substrate/frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,31 @@ mod benchmarks {

#[benchmark]
fn remove_approval() -> Result<(), BenchmarkError> {
let origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
Treasury::<T, _>::spend_local(origin, value, beneficiary_lookup)?;
let proposal_id = ProposalCount::<T, _>::get() - 1;
let (spend_exists, proposal_id) =
if let Ok(origin) = T::SpendOrigin::try_successful_origin() {
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
Treasury::<T, _>::spend_local(origin, value, beneficiary_lookup)?;
let proposal_id = ProposalCount::<T, _>::get() - 1;

(true, proposal_id)
} else {
(false, 0)
};

let reject_origin =
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(reject_origin as T::RuntimeOrigin, proposal_id);
#[block]
{
let res =
Treasury::<T, _>::remove_approval(reject_origin as T::RuntimeOrigin, proposal_id);

if spend_exists {
assert_ok!(res);
} else {
assert_err!(res, Error::<T, _>::ProposalNotApproved);
}
}

Ok(())
}
Expand Down

0 comments on commit 9cdbdc5

Please sign in to comment.