Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+9 -19
View File
@@ -19,20 +19,18 @@
#![cfg(feature = "runtime-benchmarks")]
use super::{*, Pallet as Treasury};
use super::{Pallet as Treasury, *};
use frame_benchmarking::{benchmarks_instance_pallet, account, impl_benchmark_test_suite};
use frame_support::{traits::OnInitialize, ensure};
use frame_benchmarking::{account, benchmarks_instance_pallet, impl_benchmark_test_suite};
use frame_support::{ensure, traits::OnInitialize};
use frame_system::RawOrigin;
const SEED: u32 = 0;
// Create the pre-requisite information needed to create a treasury `propose_spend`.
fn setup_proposal<T: Config<I>, I: 'static>(u: u32) -> (
T::AccountId,
BalanceOf<T, I>,
<T::Lookup as StaticLookup>::Source,
) {
fn setup_proposal<T: Config<I>, I: 'static>(
u: u32,
) -> (T::AccountId, BalanceOf<T, I>, <T::Lookup as StaticLookup>::Source) {
let caller = account("caller", u, SEED);
let value: BalanceOf<T, I> = T::ProposalBondMinimum::get().saturating_mul(100u32.into());
let _ = T::Currency::make_free_balance_be(&caller, value);
@@ -43,13 +41,9 @@ fn setup_proposal<T: Config<I>, I: 'static>(u: u32) -> (
// Create proposals that are approved for use in `on_initialize`.
fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> {
for i in 0 .. n {
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
)?;
Treasury::<T, I>::propose_spend(RawOrigin::Signed(caller).into(), value, lookup)?;
let proposal_id = <ProposalCount<T, I>>::get() - 1;
Treasury::<T, I>::approve_proposal(RawOrigin::Root.into(), proposal_id)?;
}
@@ -102,8 +96,4 @@ benchmarks_instance_pallet! {
}
}
impl_benchmark_test_suite!(
Treasury,
crate::tests::new_test_ext(),
crate::tests::Test,
);
impl_benchmark_test_suite!(Treasury, crate::tests::new_test_ext(), crate::tests::Test,);
+46 -40
View File
@@ -57,37 +57,40 @@
#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
#[cfg(test)]
mod tests;
mod benchmarking;
pub mod weights;
use codec::{Encode, Decode, MaxEncodedLen};
use codec::{Decode, Encode, MaxEncodedLen};
use sp_std::prelude::*;
use sp_runtime::{
traits::{AccountIdConversion, Saturating, StaticLookup, Zero},
Permill, RuntimeDebug,
};
use sp_std::prelude::*;
use frame_support::{
print,
traits::{
Zero, StaticLookup, AccountIdConversion, Saturating
}
Currency, ExistenceRequirement::KeepAlive, Get, Imbalance, OnUnbalanced,
ReservableCurrency, WithdrawReasons,
},
weights::Weight,
PalletId,
};
use frame_support::{print, PalletId};
use frame_support::traits::{
Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::KeepAlive,
ReservableCurrency, WithdrawReasons
};
use frame_support::weights::Weight;
pub use weights::WeightInfo;
pub use pallet::*;
pub use weights::WeightInfo;
pub type BalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type PositiveImbalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance;
pub type NegativeImbalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub type PositiveImbalanceOf<T, I = ()> = <<T as Config<I>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::PositiveImbalance;
pub type NegativeImbalanceOf<T, I = ()> = <<T as Config<I>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;
/// A trait to allow the Treasury Pallet to spend it's funds for other purposes.
/// There is an expectation that the implementer of this trait will correctly manage
@@ -130,9 +133,9 @@ pub struct Proposal<AccountId, Balance> {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
@@ -204,17 +207,14 @@ pub mod pallet {
Twox64Concat,
ProposalIndex,
Proposal<T::AccountId, BalanceOf<T, I>>,
OptionQuery
OptionQuery,
>;
/// Proposal indices that have been approved but not yet awarded.
#[pallet::storage]
#[pallet::getter(fn approvals)]
pub type Approvals<T: Config<I>, I: 'static = ()> = StorageValue<
_,
BoundedVec<ProposalIndex, T::MaxApprovals>,
ValueQuery
>;
pub type Approvals<T: Config<I>, I: 'static = ()> =
StorageValue<_, BoundedVec<ProposalIndex, T::MaxApprovals>, ValueQuery>;
#[pallet::genesis_config]
pub struct GenesisConfig;
@@ -229,10 +229,12 @@ pub mod pallet {
#[cfg(feature = "std")]
impl GenesisConfig {
/// Direct implementation of `GenesisBuild::assimilate_storage`.
#[deprecated(note = "use `<GensisConfig<T, I> as GenesisBuild<T, I>>::assimilate_storage` instead")]
#[deprecated(
note = "use `<GensisConfig<T, I> as GenesisBuild<T, I>>::assimilate_storage` instead"
)]
pub fn assimilate_storage<T: Config<I>, I: 'static>(
&self,
storage: &mut sp_runtime::Storage
storage: &mut sp_runtime::Storage,
) -> Result<(), String> {
<Self as GenesisBuild<T, I>>::assimilate_storage(self, storage)
}
@@ -272,8 +274,8 @@ pub mod pallet {
}
/// Old name generated by `decl_event`.
#[deprecated(note = "use `Event` instead")]
pub type RawEvent<T, I = ()> = Event<T, I>;
#[deprecated(note = "use `Event` instead")]
pub type RawEvent<T, I = ()> = Event<T, I>;
/// Error for the treasury pallet.
#[pallet::error]
@@ -320,7 +322,7 @@ pub mod pallet {
pub fn propose_spend(
origin: OriginFor<T>,
#[pallet::compact] value: BalanceOf<T, I>,
beneficiary: <T::Lookup as StaticLookup>::Source
beneficiary: <T::Lookup as StaticLookup>::Source,
) -> DispatchResult {
let proposer = ensure_signed(origin)?;
let beneficiary = T::Lookup::lookup(beneficiary)?;
@@ -349,11 +351,12 @@ pub mod pallet {
#[pallet::weight((T::WeightInfo::reject_proposal(), DispatchClass::Operational))]
pub fn reject_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::RejectOrigin::ensure_origin(origin)?;
let proposal = <Proposals<T, I>>::take(&proposal_id).ok_or(Error::<T, I>::InvalidIndex)?;
let proposal =
<Proposals<T, I>>::take(&proposal_id).ok_or(Error::<T, I>::InvalidIndex)?;
let value = proposal.bond;
let imbalance = T::Currency::slash_reserved(&proposal.proposer, value).0;
T::OnSlash::on_unbalanced(imbalance);
@@ -375,12 +378,13 @@ pub mod pallet {
#[pallet::weight((T::WeightInfo::approve_proposal(T::MaxApprovals::get()), DispatchClass::Operational))]
pub fn approve_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::ApproveOrigin::ensure_origin(origin)?;
ensure!(<Proposals<T, I>>::contains_key(proposal_id), Error::<T, I>::InvalidIndex);
Approvals::<T, I>::try_append(proposal_id).map_err(|_| Error::<T, I>::TooManyApprovals)?;
Approvals::<T, I>::try_append(proposal_id)
.map_err(|_| Error::<T, I>::TooManyApprovals)?;
Ok(())
}
}
@@ -444,7 +448,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
total_weight += T::WeightInfo::on_initialize_proposals(proposals_len);
// Call Runtime hooks to external pallet using treasury to compute spend funds.
T::SpendFunds::spend_funds( &mut budget_remaining, &mut imbalance, &mut total_weight, &mut missed_any);
T::SpendFunds::spend_funds(
&mut budget_remaining,
&mut imbalance,
&mut total_weight,
&mut missed_any,
);
if !missed_any {
// burn some proportion of the remaining budget if we run a surplus.
@@ -461,12 +470,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// proof: budget_remaining is account free balance minus ED;
// Thus we can't spend more than account free balance minus ED;
// Thus account is kept alive; qed;
if let Err(problem) = T::Currency::settle(
&account_id,
imbalance,
WithdrawReasons::TRANSFER,
KeepAlive
) {
if let Err(problem) =
T::Currency::settle(&account_id, imbalance, WithdrawReasons::TRANSFER, KeepAlive)
{
print("Inconsistent state - couldn't settle imbalance for funds spent by treasury");
// Nothing else to do here.
drop(problem);
+20 -13
View File
@@ -28,12 +28,12 @@ use sp_runtime::{
};
use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::OnInitialize, PalletId, pallet_prelude::GenesisBuild,
assert_noop, assert_ok, pallet_prelude::GenesisBuild, parameter_types, traits::OnInitialize,
PalletId,
};
use crate as treasury;
use super::*;
use crate as treasury;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -119,7 +119,7 @@ impl Config for Test {
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
type BurnDestination = (); // Just gets burned.
type WeightInfo = ();
type SpendFunds = ();
type MaxApprovals = MaxApprovals;
@@ -127,10 +127,12 @@ impl Config for Test {
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test>{
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();
}
.assimilate_storage(&mut t)
.unwrap();
GenesisBuild::<Test>::assimilate_storage(&crate::GenesisConfig, &mut t).unwrap();
t.into()
}
@@ -320,9 +322,9 @@ fn treasury_account_doesnt_get_deleted() {
#[test]
fn inexistent_account_works() {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test>{
balances: vec![(0, 100), (1, 99), (2, 1)],
}.assimilate_storage(&mut t).unwrap();
pallet_balances::GenesisConfig::<Test> { balances: vec![(0, 100), (1, 99), (2, 1)] }
.assimilate_storage(&mut t)
.unwrap();
// Treasury genesis config is not build thus treasury account does not exist
let mut t: sp_io::TestExternalities = t.into();
@@ -353,10 +355,12 @@ fn inexistent_account_works() {
fn genesis_funding_works() {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let initial_funding = 100;
pallet_balances::GenesisConfig::<Test>{
pallet_balances::GenesisConfig::<Test> {
// 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();
}
.assimilate_storage(&mut t)
.unwrap();
GenesisBuild::<Test>::assimilate_storage(&crate::GenesisConfig, &mut t).unwrap();
let mut t: sp_io::TestExternalities = t.into();
@@ -372,13 +376,16 @@ fn max_approvals_limited() {
Balances::make_free_balance_be(&Treasury::account_id(), u64::MAX);
Balances::make_free_balance_be(&0, u64::MAX);
for _ in 0 .. MaxApprovals::get() {
for _ in 0..MaxApprovals::get() {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
}
// One too many will fail
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), Error::<Test, _>::TooManyApprovals);
assert_noop!(
Treasury::approve_proposal(Origin::root(), 0),
Error::<Test, _>::TooManyApprovals
);
});
}
+1
View File
@@ -36,6 +36,7 @@
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]