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
+73 -29
View File
@@ -17,18 +17,27 @@
//! Testing utilities.
use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer};
use std::{fmt::{self, Debug}, ops::Deref, cell::RefCell};
use crate::codec::{Codec, Encode, Decode};
use crate::traits::{
self, Checkable, Applyable, BlakeTwo256, OpaqueKeys,
SignedExtension, Dispatchable, DispatchInfoOf, PostDispatchInfoOf,
use crate::{
codec::{Codec, Decode, Encode},
generic,
traits::{
self, Applyable, BlakeTwo256, Checkable, DispatchInfoOf, Dispatchable, OpaqueKeys,
PostDispatchInfoOf, SignedExtension, ValidateUnsigned,
},
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
ApplyExtrinsicResultWithInfo, CryptoTypeId, KeyTypeId,
};
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer};
use sp_core::{
crypto::{key_types, CryptoType, Dummy, Public},
U256,
};
pub use sp_core::{sr25519, H256};
use std::{
cell::RefCell,
fmt::{self, Debug},
ops::Deref,
};
use crate::traits::ValidateUnsigned;
use crate::{generic, KeyTypeId, CryptoTypeId, ApplyExtrinsicResultWithInfo};
pub use sp_core::{H256, sr25519};
use sp_core::{crypto::{CryptoType, Dummy, key_types, Public}, U256};
use crate::transaction_validity::{TransactionValidity, TransactionValidityError, TransactionSource};
/// A dummy type which can be used instead of regular cryptographic primitives.
///
@@ -36,7 +45,20 @@ use crate::transaction_validity::{TransactionValidity, TransactionValidityError,
/// 2. Can be converted to any `Public` key.
/// 3. Implements `RuntimeAppPublic` so it can be used instead of regular application-specific
/// crypto.
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, Debug, Hash, Serialize, Deserialize, PartialOrd, Ord)]
#[derive(
Default,
PartialEq,
Eq,
Clone,
Encode,
Decode,
Debug,
Hash,
Serialize,
Deserialize,
PartialOrd,
Ord,
)]
pub struct UintAuthorityId(pub u64);
impl From<u64> for UintAuthorityId {
@@ -68,7 +90,10 @@ impl AsRef<[u8]> for UintAuthorityId {
// Unsafe, i know, but it's test code and it's just there because it's really convenient to
// keep `UintAuthorityId` as a u64 under the hood.
unsafe {
std::slice::from_raw_parts(&self.0 as *const u64 as *const _, std::mem::size_of::<u64>())
std::slice::from_raw_parts(
&self.0 as *const u64 as *const _,
std::mem::size_of::<u64>(),
)
}
}
}
@@ -80,7 +105,7 @@ thread_local! {
impl UintAuthorityId {
/// Set the list of keys returned by the runtime call for all keys of that type.
pub fn set_all_keys<T: Into<UintAuthorityId>>(keys: impl IntoIterator<Item=T>) {
pub fn set_all_keys<T: Into<UintAuthorityId>>(keys: impl IntoIterator<Item = T>) {
ALL_KEYS.with(|l| *l.borrow_mut() = keys.into_iter().map(Into::into).collect())
}
}
@@ -180,7 +205,8 @@ impl Header {
pub struct ExtrinsicWrapper<Xt>(Xt);
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt>
where Xt: parity_util_mem::MallocSizeOf
where
Xt: parity_util_mem::MallocSizeOf,
{
type Call = ();
type SignaturePayload = ();
@@ -191,7 +217,10 @@ where Xt: parity_util_mem::MallocSizeOf
}
impl<Xt: Encode> serde::Serialize for ExtrinsicWrapper<Xt> {
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
}
}
@@ -219,8 +248,9 @@ pub struct Block<Xt> {
pub extrinsics: Vec<Xt>,
}
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug + traits::Extrinsic> traits::Block
for Block<Xt>
impl<
Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug + traits::Extrinsic,
> traits::Block for Block<Xt>
{
type Extrinsic = Xt;
type Header = Header;
@@ -243,7 +273,10 @@ impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug
}
}
impl<'a, Xt> Deserialize<'a> for Block<Xt> where Block<Xt>: Decode {
impl<'a, Xt> Deserialize<'a> for Block<Xt>
where
Block<Xt>: Decode,
{
fn deserialize<D: Deserializer<'a>>(de: D) -> Result<Self, D::Error> {
let r = <Vec<u8>>::deserialize(de)?;
Decode::decode(&mut &r[..])
@@ -273,8 +306,14 @@ impl<Call, Extra> TestXt<Call, Extra> {
// Non-opaque extrinsics always 0.
parity_util_mem::malloc_size_of_is_0!(any: TestXt<Call, Extra>);
impl<Call, Extra> Serialize for TestXt<Call, Extra> where TestXt<Call, Extra>: Encode {
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: Serializer {
impl<Call, Extra> Serialize for TestXt<Call, Extra>
where
TestXt<Call, Extra>: Encode,
{
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
}
}
@@ -287,7 +326,9 @@ impl<Call, Extra> Debug for TestXt<Call, Extra> {
impl<Call: Codec + Sync + Send, Context, Extra> Checkable<Context> for TestXt<Call, Extra> {
type Checked = Self;
fn check(self, _: &Context) -> Result<Self::Checked, TransactionValidityError> { Ok(self) }
fn check(self, _: &Context) -> Result<Self::Checked, TransactionValidityError> {
Ok(self)
}
}
impl<Call: Codec + Sync + Send, Extra> traits::Extrinsic for TestXt<Call, Extra> {
@@ -303,23 +344,26 @@ impl<Call: Codec + Sync + Send, Extra> traits::Extrinsic for TestXt<Call, Extra>
}
}
impl<Call, Extra> traits::ExtrinsicMetadata for TestXt<Call, Extra> where
impl<Call, Extra> traits::ExtrinsicMetadata for TestXt<Call, Extra>
where
Call: Codec + Sync + Send,
Extra: SignedExtension<AccountId=u64, Call=Call>,
Extra: SignedExtension<AccountId = u64, Call = Call>,
{
type SignedExtensions = Extra;
const VERSION: u8 = 0u8;
}
impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Dispatchable<Origin=Origin>,
Extra: SignedExtension<AccountId=u64, Call=Call>,
impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra>
where
Call:
'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Dispatchable<Origin = Origin>,
Extra: SignedExtension<AccountId = u64, Call = Call>,
Origin: From<Option<u64>>,
{
type Call = Call;
/// Checks to see if this is a valid *transaction*. It returns information on it if so.
fn validate<U: ValidateUnsigned<Call=Self::Call>>(
fn validate<U: ValidateUnsigned<Call = Self::Call>>(
&self,
source: TransactionSource,
info: &DispatchInfoOf<Self::Call>,
@@ -336,7 +380,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where
/// Executes all necessary logic needed prior to dispatch and deconstructs into function call,
/// index and sender.
fn apply<U: ValidateUnsigned<Call=Self::Call>>(
fn apply<U: ValidateUnsigned<Call = Self::Call>>(
self,
info: &DispatchInfoOf<Self::Call>,
len: usize,