Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix treasury benchmarks when no SpendOrigin #3049

Merged
merged 8 commits into from
Sep 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions substrate/frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ fn create_spend_arguments<T: Config<I>, I: 'static>(
mod benchmarks {
use super::*;

// This benchmark is short-circuited if `SpendOrigin` cannot provide
// a successful origin, in which case `spend` is un-callable and can use weight=0.
/// This benchmark is short-circuited if `SpendOrigin` cannot provide
/// a successful origin, in which case `spend` is un-callable and can use weight=0.
#[benchmark]
fn spend_local() -> Result<(), BenchmarkError> {
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
Expand Down Expand Up @@ -215,6 +215,8 @@ mod benchmarks {
Ok(())
}

/// This benchmark is short-circuited if `SpendOrigin` cannot provide
/// a successful origin, in which case `spend` is un-callable and can use weight=0.
#[benchmark]
fn spend() -> Result<(), BenchmarkError> {
let origin =
Expand Down Expand Up @@ -248,9 +250,13 @@ mod benchmarks {
Ok(())
}

/// This benchmark is short-circuited if `SpendOrigin` cannot provide
/// a successful origin, in which case there is no spend to payout
/// and `payout` is un-callable and can use weight=0.
#[benchmark]
fn payout() -> Result<(), BenchmarkError> {
let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?;
let origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (asset_kind, amount, beneficiary, beneficiary_lookup) =
create_spend_arguments::<T, _>(SEED);
T::BalanceConverter::ensure_successful(asset_kind.clone());
Expand Down Expand Up @@ -279,9 +285,13 @@ mod benchmarks {
Ok(())
}

/// This benchmark is short-circuited if `SpendOrigin` cannot provide
/// a successful origin, in which case there is no spend to check
/// and `check_status` is un-callable and can use weight=0.
#[benchmark]
fn check_status() -> Result<(), BenchmarkError> {
let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?;
let origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (asset_kind, amount, beneficiary, beneficiary_lookup) =
create_spend_arguments::<T, _>(SEED);
T::BalanceConverter::ensure_successful(asset_kind.clone());
Expand Down Expand Up @@ -311,9 +321,13 @@ mod benchmarks {
Ok(())
}

/// This benchmark is short-circuited if `SpendOrigin` cannot provide
/// a successful origin, in which case there is no spend to void
/// and `void_spend` is un-callable and can use weight=0.
#[benchmark]
fn void_spend() -> Result<(), BenchmarkError> {
let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?;
let origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (asset_kind, amount, _, beneficiary_lookup) = create_spend_arguments::<T, _>(SEED);
T::BalanceConverter::ensure_successful(asset_kind.clone());
Treasury::<T, _>::spend(
Expand Down
Loading