Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::cell::RefCell;

use frame_support::{
assert_noop, assert_ok, parameter_types, weights::Weight, traits::OnInitialize,
PalletId
PalletId, pallet_prelude::GenesisBuild,
};

use sp_core::H256;
Expand Down Expand Up @@ -146,15 +146,15 @@ 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();
pallet_balances::GenesisConfig::<Test>{
// Total issuance will be 200 with treasury account initialized at ED.
balances: vec![(0, 100), (1, 98), (2, 1)],
}.assimilate_storage(&mut t).unwrap();
pallet_treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
t.into()
}

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 Expand Up @@ -897,7 +897,7 @@ fn genesis_funding_works() {
// Total issuance will be 200 with treasury account initialized with 100.
balances: vec![(0, 100), (Treasury::account_id(), initial_funding)],
}.assimilate_storage(&mut t).unwrap();
pallet_treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
let mut t: sp_io::TestExternalities = t.into();

t.execute_with(|| {
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
6 changes: 3 additions & 3 deletions frame/tips/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::cell::RefCell;
use frame_support::{
assert_noop, assert_ok, parameter_types,
weights::Weight, traits::SortedMembers,
PalletId
PalletId, pallet_prelude::GenesisBuild,
};
use sp_runtime::Permill;
use sp_core::H256;
Expand Down Expand Up @@ -169,7 +169,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
// Total issuance will be 200 with treasury account initialized at ED.
balances: vec![(0, 100), (1, 98), (2, 1)],
}.assimilate_storage(&mut t).unwrap();
pallet_treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
t.into()
}

Expand Down Expand Up @@ -485,7 +485,7 @@ fn genesis_funding_works() {
// Total issuance will be 200 with treasury account initialized with 100.
balances: vec![(0, 100), (Treasury::account_id(), initial_funding)],
}.assimilate_storage(&mut t).unwrap();
pallet_treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
GenesisBuild::<Test>::assimilate_storage(&pallet_treasury::GenesisConfig, &mut t).unwrap();
let mut t: sp_io::TestExternalities = t.into();

t.execute_with(|| {
Expand Down
10 changes: 6 additions & 4 deletions frame/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ 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 = "4.0.0-dev", default-features = false, path = "../../primitives/std" }
sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../primitives/runtime" }

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

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

[dev-dependencies]
sp-io ={ version = "4.0.0-dev", path = "../../primitives/io" }
Expand All @@ -32,8 +34,8 @@ sp-storage = { version = "4.0.0-dev", 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