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
+86 -111
View File
@@ -23,45 +23,43 @@
pub mod genesismap;
pub mod system;
use sp_std::{prelude::*, marker::PhantomData};
use codec::{Encode, Decode, Input, Error};
use codec::{Decode, Encode, Error, Input};
use sp_std::{marker::PhantomData, prelude::*};
use sp_application_crypto::{ecdsa, ed25519, sr25519, RuntimeAppPublic};
use sp_core::{offchain::KeyTypeId, ChangesTrieConfiguration, OpaqueMetadata, RuntimeDebug};
use sp_application_crypto::{ed25519, sr25519, ecdsa, RuntimeAppPublic};
use trie_db::{TrieMut, Trie};
use sp_trie::{PrefixedMemoryDB, StorageProof};
use sp_trie::trie_types::{TrieDB, TrieDBMut};
use sp_api::{decl_runtime_apis, impl_runtime_apis};
use sp_runtime::{
create_runtime_str, impl_opaque_keys,
ApplyExtrinsicResult, Perbill,
transaction_validity::{
TransactionValidity, ValidTransaction, TransactionValidityError, InvalidTransaction,
TransactionSource,
},
traits::{
BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT,
GetNodeBlockType, GetRuntimeBlockType, Verify, IdentityLookup,
},
use sp_trie::{
trie_types::{TrieDB, TrieDBMut},
PrefixedMemoryDB, StorageProof,
};
use trie_db::{Trie, TrieMut};
use cfg_if::cfg_if;
use frame_support::{parameter_types, traits::KeyOwnerProofSystem, weights::RuntimeDbWeight};
use frame_system::limits::{BlockLength, BlockWeights};
use sp_api::{decl_runtime_apis, impl_runtime_apis};
pub use sp_core::hash::H256;
use sp_inherents::{CheckInherentsResult, InherentData};
#[cfg(feature = "std")]
use sp_runtime::traits::NumberFor;
use sp_version::RuntimeVersion;
pub use sp_core::hash::H256;
use sp_runtime::{
create_runtime_str, impl_opaque_keys,
traits::{
BlakeTwo256, BlindCheckable, Block as BlockT, Extrinsic as ExtrinsicT, GetNodeBlockType,
GetRuntimeBlockType, IdentityLookup, Verify,
},
transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
ValidTransaction,
},
ApplyExtrinsicResult, Perbill,
};
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use frame_support::{
parameter_types,
traits::KeyOwnerProofSystem,
weights::RuntimeDbWeight,
};
use frame_system::limits::{BlockWeights, BlockLength};
use sp_inherents::{CheckInherentsResult, InherentData};
use cfg_if::cfg_if;
use sp_version::RuntimeVersion;
// Ensure Babe and Aura use the same crypto to simplify things a bit.
pub use sp_consensus_babe::{AuthorityId, Slot, AllowedSlots};
pub use sp_consensus_babe::{AllowedSlots, AuthorityId, Slot};
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
@@ -77,18 +75,19 @@ pub mod wasm_binary_logging_disabled {
/// Wasm binary unwrapped. If built with `SKIP_WASM_BUILD`, the function panics.
#[cfg(feature = "std")]
pub fn wasm_binary_unwrap() -> &'static [u8] {
WASM_BINARY.expect("Development wasm binary is not available. Testing is only \
supported with the flag disabled.")
WASM_BINARY.expect(
"Development wasm binary is not available. Testing is only \
supported with the flag disabled.",
)
}
/// Wasm binary unwrapped. If built with `SKIP_WASM_BUILD`, the function panics.
#[cfg(feature = "std")]
pub fn wasm_binary_logging_disabled_unwrap() -> &'static [u8] {
wasm_binary_logging_disabled::WASM_BINARY
.expect(
"Development wasm binary is not available. Testing is only supported with the flag \
disabled."
)
wasm_binary_logging_disabled::WASM_BINARY.expect(
"Development wasm binary is not available. Testing is only supported with the flag \
disabled.",
)
}
/// Test runtime version.
@@ -110,10 +109,7 @@ fn version() -> RuntimeVersion {
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
/// Calls in transactions.
@@ -130,12 +126,10 @@ impl Transfer {
#[cfg(feature = "std")]
pub fn into_signed_tx(self) -> Extrinsic {
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
.expect("Creates keyring from public key.").sign(&self.encode()).into();
Extrinsic::Transfer {
transfer: self,
signature,
exhaust_resources_when_not_first: false,
}
.expect("Creates keyring from public key.")
.sign(&self.encode())
.into();
Extrinsic::Transfer { transfer: self, signature, exhaust_resources_when_not_first: false }
}
/// Convert into a signed extrinsic, which will only end up included in the block
@@ -144,12 +138,10 @@ impl Transfer {
#[cfg(feature = "std")]
pub fn into_resources_exhausting_tx(self) -> Extrinsic {
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
.expect("Creates keyring from public key.").sign(&self.encode()).into();
Extrinsic::Transfer {
transfer: self,
signature,
exhaust_resources_when_not_first: true,
}
.expect("Creates keyring from public key.")
.sign(&self.encode())
.into();
Extrinsic::Transfer { transfer: self, signature, exhaust_resources_when_not_first: true }
}
}
@@ -174,7 +166,10 @@ parity_util_mem::malloc_size_of_is_0!(Extrinsic); // non-opaque extrinsic does n
#[cfg(feature = "std")]
impl serde::Serialize for Extrinsic {
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))
}
}
@@ -185,21 +180,22 @@ impl BlindCheckable for Extrinsic {
fn check(self) -> Result<Self, TransactionValidityError> {
match self {
Extrinsic::AuthoritiesChange(new_auth) => Ok(Extrinsic::AuthoritiesChange(new_auth)),
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first } => {
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first } =>
if sp_runtime::verify_encoded_lazy(&signature, &transfer, &transfer.from) {
Ok(Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first })
Ok(Extrinsic::Transfer {
transfer,
signature,
exhaust_resources_when_not_first,
})
} else {
Err(InvalidTransaction::BadProof.into())
}
},
},
Extrinsic::IncludeData(v) => Ok(Extrinsic::IncludeData(v)),
Extrinsic::StorageChange(key, value) => Ok(Extrinsic::StorageChange(key, value)),
Extrinsic::ChangesTrieConfigUpdate(new_config) =>
Ok(Extrinsic::ChangesTrieConfigUpdate(new_config)),
Extrinsic::OffchainIndexSet(key, value) =>
Ok(Extrinsic::OffchainIndexSet(key, value)),
Extrinsic::OffchainIndexClear(key) =>
Ok(Extrinsic::OffchainIndexClear(key)),
Extrinsic::OffchainIndexSet(key, value) => Ok(Extrinsic::OffchainIndexSet(key, value)),
Extrinsic::OffchainIndexClear(key) => Ok(Extrinsic::OffchainIndexClear(key)),
Extrinsic::Store(data) => Ok(Extrinsic::Store(data)),
}
}
@@ -301,9 +297,7 @@ impl<B: BlockT> codec::EncodeLike for DecodeFails<B> {}
impl<B: BlockT> DecodeFails<B> {
/// Create a new instance.
pub fn new() -> DecodeFails<B> {
DecodeFails {
_phantom: Default::default(),
}
DecodeFails { _phantom: Default::default() }
}
}
@@ -619,7 +613,8 @@ fn code_using_trie() -> u64 {
let pairs = [
(b"0103000000000000000464".to_vec(), b"0400000000".to_vec()),
(b"0103000000000000000469".to_vec(), b"0401000000".to_vec()),
].to_vec();
]
.to_vec();
let mut mdb = PrefixedMemoryDB::default();
let mut root = sp_std::default::Default::default();
@@ -627,10 +622,10 @@ fn code_using_trie() -> u64 {
let v = &pairs;
let mut t = TrieDBMut::<Hashing>::new(&mut mdb, &mut root);
for i in 0..v.len() {
let key: &[u8]= &v[i].0;
let key: &[u8] = &v[i].0;
let val: &[u8] = &v[i].1;
if !t.insert(key, val).is_ok() {
return 101;
return 101
}
}
t
@@ -645,8 +640,12 @@ fn code_using_trie() -> u64 {
}
}
iter_pairs.len() as u64
} else { 102 }
} else { 103 }
} else {
102
}
} else {
103
}
}
impl_opaque_keys! {
@@ -1206,29 +1205,15 @@ fn test_read_storage() {
fn test_read_child_storage() {
const STORAGE_KEY: &[u8] = b"unique_id_1";
const KEY: &[u8] = b":read_child_storage";
sp_io::default_child_storage::set(
STORAGE_KEY,
KEY,
b"test",
);
sp_io::default_child_storage::set(STORAGE_KEY, KEY, b"test");
let mut v = [0u8; 4];
let r = sp_io::default_child_storage::read(
STORAGE_KEY,
KEY,
&mut v,
0,
);
let r = sp_io::default_child_storage::read(STORAGE_KEY, KEY, &mut v, 0);
assert_eq!(r, Some(4));
assert_eq!(&v, b"test");
let mut v = [0u8; 4];
let r = sp_io::default_child_storage::read(
STORAGE_KEY,
KEY,
&mut v,
8,
);
let r = sp_io::default_child_storage::read(STORAGE_KEY, KEY, &mut v, 8);
assert_eq!(r, Some(0));
assert_eq!(&v, &[0, 0, 0, 0]);
}
@@ -1236,10 +1221,7 @@ fn test_read_child_storage() {
fn test_witness(proof: StorageProof, root: crate::Hash) {
use sp_externalities::Externalities;
let db: sp_trie::MemoryDB<crate::Hashing> = proof.into_memory_db();
let backend = sp_state_machine::TrieBackend::<_, crate::Hashing>::new(
db,
root,
);
let backend = sp_state_machine::TrieBackend::<_, crate::Hashing>::new(db, root);
let mut overlay = sp_state_machine::OverlayedChanges::default();
let mut cache = sp_state_machine::StorageTransactionCache::<_, _, BlockNumber>::default();
let mut ext = sp_state_machine::Ext::new(
@@ -1259,18 +1241,16 @@ fn test_witness(proof: StorageProof, root: crate::Hash) {
#[cfg(test)]
mod tests {
use substrate_test_runtime_client::{
prelude::*,
sp_consensus::BlockOrigin,
DefaultTestClientBuilderExt, TestClientBuilder,
runtime::TestAPI,
};
use sp_api::ProvideRuntimeApi;
use sp_runtime::generic::BlockId;
use sp_core::storage::well_known_keys::HEAP_PAGES;
use sp_state_machine::ExecutionStrategy;
use codec::Encode;
use sc_block_builder::BlockBuilderProvider;
use sp_api::ProvideRuntimeApi;
use sp_core::storage::well_known_keys::HEAP_PAGES;
use sp_runtime::generic::BlockId;
use sp_state_machine::ExecutionStrategy;
use substrate_test_runtime_client::{
prelude::*, runtime::TestAPI, sp_consensus::BlockOrigin, DefaultTestClientBuilderExt,
TestClientBuilder,
};
#[test]
fn heap_pages_is_respected() {
@@ -1307,9 +1287,8 @@ mod tests {
#[test]
fn test_storage() {
let client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::Both)
.build();
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);
@@ -1331,14 +1310,10 @@ mod tests {
#[test]
fn witness_backend_works() {
let (db, root) = witness_backend();
let backend = sp_state_machine::TrieBackend::<_, crate::Hashing>::new(
db,
root,
);
let backend = sp_state_machine::TrieBackend::<_, crate::Hashing>::new(db, root);
let proof = sp_state_machine::prove_read(backend, vec![b"value3"]).unwrap();
let client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::Both)
.build();
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);