Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 17 additions & 10 deletions frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@
use super::*;

use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks_instance, account, impl_benchmark_test_suite};
use frame_support::traits::OnInitialize;
use frame_benchmarking::{
benchmarks,
account,
impl_benchmark_test_suite,
};
use frame_support::{
ensure,
traits::OnInitialize
};

use crate::Module as Treasury;

const SEED: u32 = 0;

// Create the pre-requisite information needed to create a treasury `propose_spend`.
fn setup_proposal<T: Config<I>, I: Instance>(u: u32) -> (
fn setup_proposal<T: Config<I>, I: 'static>(u: u32) -> (
T::AccountId,
BalanceOf<T, I>,
<T::Lookup as StaticLookup>::Source,
Expand All @@ -44,28 +51,28 @@ fn setup_proposal<T: Config<I>, I: Instance>(u: u32) -> (
}

// Create proposals that are approved for use in `on_initialize`.
fn create_approved_proposals<T: Config<I>, I: Instance>(n: u32) -> Result<(), &'static str> {
fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> {
for i in 0 .. n {
let (caller, value, lookup) = setup_proposal::<T, I>(i);
Treasury::<T, I>::propose_spend(
RawOrigin::Signed(caller).into(),
value,
lookup
)?;
let proposal_id = <ProposalCount<I>>::get() - 1;
let proposal_id = <ProposalCount<T, I>>::get() - 1;
Treasury::<T, I>::approve_proposal(RawOrigin::Root.into(), proposal_id)?;
}
ensure!(<Approvals<I>>::get().len() == n as usize, "Not all approved");
ensure!(<Approvals<T, I>>::get().len() == n as usize, "Not all approved");
Ok(())
}

fn setup_pot_account<T: Config<I>, I: Instance>() {
fn setup_pot_account<T: Config<I>, I: 'static>() {
let pot_account = Treasury::<T, I>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
}

benchmarks_instance! {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use benchmarks_instance here

benchmarks! {

propose_spend {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
Expand Down Expand Up @@ -105,6 +112,6 @@ benchmarks_instance! {

impl_benchmark_test_suite!(
Treasury,
crate::tests::new_test_ext(),
crate::tests::Test,
crate::mock::new_test_ext(),
crate::mock::Test,
);
Loading