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
+6 -11
View File
@@ -93,13 +93,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
use sp_runtime::{traits::StaticLookup, DispatchResult};
use sp_std::prelude::*;
use sp_runtime::{DispatchResult, traits::StaticLookup};
use frame_support::{
weights::GetDispatchInfo,
traits::UnfilteredDispatchable,
};
use frame_support::{traits::UnfilteredDispatchable, weights::GetDispatchInfo};
#[cfg(test)]
mod mock;
@@ -110,9 +107,9 @@ pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::{DispatchResult, *};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::{*, DispatchResult};
#[pallet::config]
pub trait Config: frame_system::Config {
@@ -120,7 +117,7 @@ pub mod pallet {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
/// A sudo-able call.
type Call: Parameter + UnfilteredDispatchable<Origin=Self::Origin> + GetDispatchInfo;
type Call: Parameter + UnfilteredDispatchable<Origin = Self::Origin> + GetDispatchInfo;
}
#[pallet::pallet]
@@ -233,7 +230,7 @@ pub mod pallet {
pub fn sudo_as(
origin: OriginFor<T>,
who: <T::Lookup as StaticLookup>::Source,
call: Box<<T as Config>::Call>
call: Box<<T as Config>::Call>,
) -> DispatchResultWithPostInfo {
// This is a public call, so we ensure that the origin is some signed account.
let sender = ensure_signed(origin)?;
@@ -282,9 +279,7 @@ pub mod pallet {
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
key: Default::default(),
}
Self { key: Default::default() }
}
}
+18 -22
View File
@@ -18,20 +18,25 @@
//! Test utilities
use super::*;
use frame_support::{parameter_types, traits::GenesisBuild};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_io;
use crate as sudo;
use frame_support::traits::Filter;
use frame_support::{
parameter_types,
traits::{Filter, GenesisBuild},
};
use frame_system::limits;
use sp_core::H256;
use sp_io;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
// Logger module to track execution.
#[frame_support::pallet]
pub mod logger {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
#[pallet::config]
pub trait Config: frame_system::Config {
@@ -48,7 +53,7 @@ pub mod logger {
pub fn privileged_i32_log(
origin: OriginFor<T>,
i: i32,
weight: Weight
weight: Weight,
) -> DispatchResultWithPostInfo {
// Ensure that the `origin` is `Root`.
ensure_root(origin)?;
@@ -61,7 +66,7 @@ pub mod logger {
pub fn non_privileged_log(
origin: OriginFor<T>,
i: i32,
weight: Weight
weight: Weight,
) -> DispatchResultWithPostInfo {
// Ensure that the `origin` is some signed account.
let sender = ensure_signed(origin)?;
@@ -82,22 +87,13 @@ pub mod logger {
#[pallet::storage]
#[pallet::getter(fn account_log)]
pub(super) type AccountLog<T: Config> = StorageValue<
_,
Vec<T::AccountId>,
ValueQuery
>;
pub(super) type AccountLog<T: Config> = StorageValue<_, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn i32_log)]
pub(super) type I32Log<T> = StorageValue<
_,
Vec<i32>,
ValueQuery
>;
pub(super) type I32Log<T> = StorageValue<_, Vec<i32>, ValueQuery>;
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
@@ -169,8 +165,8 @@ pub type LoggerCall = logger::Call<Test>;
// Build test environment by setting the root `key` for the Genesis.
pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
sudo::GenesisConfig::<Test>{
key: root_key,
}.assimilate_storage(&mut t).unwrap();
sudo::GenesisConfig::<Test> { key: root_key }
.assimilate_storage(&mut t)
.unwrap();
t.into()
}
+7 -7
View File
@@ -18,17 +18,17 @@
//! Tests for the module.
use super::*;
use frame_support::{assert_noop, assert_ok};
use mock::{
Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System,
Event as TestEvent,
new_test_ext, Call, Event as TestEvent, Logger, LoggerCall, Origin, Sudo, SudoCall, System,
Test,
};
use frame_support::{assert_ok, assert_noop};
#[test]
fn test_setup_works() {
// Environment setup, logger storage, and sudo `key` retrieval should work as expected.
new_test_ext(1).execute_with(|| {
assert_eq!(Sudo::key(), 1u64);
assert_eq!(Sudo::key(), 1u64);
assert!(Logger::i32_log().is_empty());
assert!(Logger::account_log().is_empty());
});
@@ -105,7 +105,7 @@ fn set_key_basics() {
new_test_ext(1).execute_with(|| {
// A root `key` can change the root `key`
assert_ok!(Sudo::set_key(Origin::signed(1), 2));
assert_eq!(Sudo::key(), 2u64);
assert_eq!(Sudo::key(), 2u64);
});
new_test_ext(1).execute_with(|| {
@@ -146,14 +146,14 @@ fn sudo_as_basics() {
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log(42, 1)));
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
assert_eq!(Logger::i32_log(), vec![42i32]);
// The correct user makes the call within `sudo_as`.
// The correct user makes the call within `sudo_as`.
assert_eq!(Logger::account_log(), vec![2]);
});
}
#[test]
fn sudo_as_emits_events_correctly() {
new_test_ext(1).execute_with(|| {
new_test_ext(1).execute_with(|| {
// Set block number to 1 because events are not emitted on block 0.
System::set_block_number(1);