Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

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

Merged
9 commits merged into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -417,7 +417,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
topics: vec![],
},
EventRecord {
Expand All @@ -440,7 +440,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
topics: vec![],
},
EventRecord {
Expand Down
2 changes: 1 addition & 1 deletion frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark
use frame_support::traits::OnInitialize;

use crate::Module as Bounties;
use pallet_treasury::Module as Treasury;
use pallet_treasury::Pallet as Treasury;

const SEED: u32 = 0;

Expand Down
6 changes: 3 additions & 3 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Config for Test {
type WeightInfo = ();
}

type TreasuryError = pallet_treasury::Error::<Test, pallet_treasury::DefaultInstance>;
type TreasuryError = pallet_treasury::Error::<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
Expand Down Expand Up @@ -268,7 +268,7 @@ fn reject_already_rejected_spend_proposal_fails() {
fn reject_non_existent_spend_proposal_fails() {
new_test_ext().execute_with(|| {
assert_noop!(Treasury::reject_proposal(Origin::root(), 0),
pallet_treasury::Error::<Test, pallet_treasury::DefaultInstance>::InvalidIndex);
pallet_treasury::Error::<Test, _>::InvalidIndex);
});
}

Expand Down Expand Up @@ -457,7 +457,7 @@ fn close_bounty_works() {
assert_eq!(Balances::free_balance(0), 100 - deposit);

assert_eq!(Bounties::bounties(0), None);
assert!(!pallet_treasury::Proposals::<Test>::contains_key(0));
assert!(!pallet_treasury::Proposals::<Test, _>::contains_key(0));

assert_eq!(Bounties::bounty_descriptions(0), None);
});
Expand Down
2 changes: 1 addition & 1 deletion frame/tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl<T: Config> Module<T> {
tips.sort_by_key(|i| i.1);

let treasury = Self::account_id();
let max_payout = pallet_treasury::Module::<T>::pot();
let max_payout = pallet_treasury::Pallet::<T>::pot();

let mut payout = tips[tips.len() / 2].1.min(max_payout);
if !tip.deposit.is_zero() {
Expand Down
11 changes: 6 additions & 5 deletions frame/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", features = ["derive"], optional = true }
impl-trait-for-tuples = "0.2.1"

sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" }
sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" }

frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "3.0.0", default-features = false, path = "../support" }
frame-system = { version = "3.0.0", default-features = false, path = "../system" }
pallet-balances = { version = "3.0.0", default-features = false, path = "../balances" }
impl-trait-for-tuples = "0.2.1"

frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true }

[dev-dependencies]
sp-io ={ version = "3.0.0", path = "../../primitives/io" }
Expand All @@ -32,8 +33,8 @@ sp-storage = { version = "3.0.0", path = "../../primitives/storage" }
[features]
default = ["std"]
std = [
"serde",
"codec/std",
"serde",
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
Expand Down
8 changes: 4 additions & 4 deletions frame/treasury/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Treasury Module
# Treasury Pallet

The Treasury module provides a "pot" of funds that can be managed by stakeholders in the system and
The Treasury pallet provides a "pot" of funds that can be managed by stakeholders in the system and
a structure for making spending proposals from this pot.

## Overview

The Treasury Module itself provides the pot to store funds, and a means for stakeholders to propose,
The Treasury Pallet itself provides the pot to store funds, and a means for stakeholders to propose,
approve, and deny expenditures. The chain will need to provide a method (e.g.inflation, fees) for
collecting funds.

Expand All @@ -19,7 +19,7 @@ and use the funds to pay developers.
approved.
- **Deposit:** Funds that a proposer must lock when making a proposal. The deposit will be returned
or slashed if the proposal is approved or rejected respectively.
- **Pot:** Unspent funds accumulated by the treasury module.
- **Pot:** Unspent funds accumulated by the treasury pallet.

## Interface

Expand Down
19 changes: 8 additions & 11 deletions frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,29 +42,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<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.
Expand Down
Loading