Skip to content
Snippets Groups Projects
Unverified Commit 9cdbdc5a authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

pallet-treasury: Improve `remove_approval` benchmark (#5713)

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`.
parent 43cd6fd4
No related merge requests found
Pipeline #497404 waiting for manual action with stages
in 31 minutes and 58 seconds
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
......@@ -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(())
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment