Skip to content

Commit

Permalink
[stable2409] Backport #5713 (#5740)
Browse files Browse the repository at this point in the history
Backport #5713 into `stable2409` from bkchr.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
1 parent d33346c commit b470dea
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 b470dea

Please sign in to comment.