Skip to content

Commit 240e20b

Browse files
paritytech-cmd-bot-polkadot-sdk[bot]bkchrggwpez
authored
[stable2407] Backport #5713 (#5739)
Backport #5713 into `stable2407` 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} --> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
1 parent 51a1705 commit 240e20b

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

prdoc/pr_5713.prdoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: "pallet-treasury: Improve `remove_approval` benchmark"
2+
3+
doc:
4+
- audience: Runtime Dev
5+
description: |
6+
Fix the `remove_approval` benchmark when `SpendOrigin` doesn't return any `succesful_origin`.
7+
8+
crates:
9+
- name: pallet-treasury
10+
bump: patch

substrate/frame/treasury/src/benchmarking.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use frame_benchmarking::{
2626
v2::*,
2727
};
2828
use frame_support::{
29-
ensure,
29+
assert_err, assert_ok, ensure,
3030
traits::{
3131
tokens::{ConversionFromAssetBalance, PaymentStatus},
3232
EnsureOrigin, OnInitialize,
@@ -126,16 +126,31 @@ mod benchmarks {
126126

127127
#[benchmark]
128128
fn remove_approval() -> Result<(), BenchmarkError> {
129-
let origin =
130-
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
131-
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
132-
Treasury::<T, _>::spend_local(origin, value, beneficiary_lookup)?;
133-
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
129+
let (spend_exists, proposal_id) =
130+
if let Ok(origin) = T::SpendOrigin::try_successful_origin() {
131+
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
132+
Treasury::<T, _>::spend_local(origin, value, beneficiary_lookup)?;
133+
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
134+
135+
(true, proposal_id)
136+
} else {
137+
(false, 0)
138+
};
139+
134140
let reject_origin =
135141
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
136142

137-
#[extrinsic_call]
138-
_(reject_origin as T::RuntimeOrigin, proposal_id);
143+
#[block]
144+
{
145+
let res =
146+
Treasury::<T, _>::remove_approval(reject_origin as T::RuntimeOrigin, proposal_id);
147+
148+
if spend_exists {
149+
assert_ok!(res);
150+
} else {
151+
assert_err!(res, Error::<T, _>::ProposalNotApproved);
152+
}
153+
}
139154

140155
Ok(())
141156
}

0 commit comments

Comments
 (0)