Migrate pallet-treasury to the new pallet attribute macro (#9197)

* Migrate pallet-treasury to the new pallet attribute macro

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix bounties/tips tests

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* fix

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Update frame/treasury/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update frame/treasury/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* use `GenesisBuild`

* fix imports

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Qinxuan Chen
2021-07-13 15:26:58 +08:00
committed by GitHub
parent e01ac8cea0
commit e256877eb0
10 changed files with 278 additions and 241 deletions
+8 -11
View File
@@ -19,18 +19,16 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use super::{*, Pallet as Treasury};
use frame_benchmarking::{benchmarks_instance_pallet, account, impl_benchmark_test_suite};
use frame_support::{traits::OnInitialize, ensure};
use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks_instance, account, impl_benchmark_test_suite};
use frame_support::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,
@@ -44,7 +42,7 @@ 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(
@@ -52,21 +50,20 @@ fn create_approved_proposals<T: Config<I>, I: Instance>(n: u32) -> Result<(), &'
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<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! {
benchmarks_instance_pallet! {
propose_spend {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
// Whitelist caller account from further DB operations.