mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
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:
@@ -20,22 +20,22 @@
|
||||
//! See [`TestApi`] for more information.
|
||||
|
||||
use codec::Encode;
|
||||
use futures::future::ready;
|
||||
use parking_lot::RwLock;
|
||||
use sp_blockchain::CachedHeaderMetadata;
|
||||
use sp_runtime::{
|
||||
generic::{self, BlockId},
|
||||
traits::{BlakeTwo256, Hash as HashT, Block as BlockT, Header as _},
|
||||
traits::{BlakeTwo256, Block as BlockT, Hash as HashT, Header as _},
|
||||
transaction_validity::{
|
||||
TransactionValidity, ValidTransaction, TransactionValidityError, InvalidTransaction,
|
||||
TransactionSource,
|
||||
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
|
||||
ValidTransaction,
|
||||
},
|
||||
};
|
||||
use std::collections::{HashSet, HashMap, BTreeMap};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use substrate_test_runtime_client::{
|
||||
runtime::{Index, AccountId, Block, BlockNumber, Extrinsic, Hash, Header, Transfer},
|
||||
runtime::{AccountId, Block, BlockNumber, Extrinsic, Hash, Header, Index, Transfer},
|
||||
AccountKeyring::{self, *},
|
||||
};
|
||||
use sp_blockchain::CachedHeaderMetadata;
|
||||
use futures::future::ready;
|
||||
|
||||
/// Error type used by [`TestApi`].
|
||||
#[derive(Debug, derive_more::From, derive_more::Display)]
|
||||
@@ -130,12 +130,9 @@ impl TestApi {
|
||||
block_number
|
||||
.checked_sub(1)
|
||||
.and_then(|num| {
|
||||
chain.block_by_number
|
||||
.get(&num)
|
||||
.map(|blocks| {
|
||||
blocks[0].0.header.hash()
|
||||
})
|
||||
}).unwrap_or_default()
|
||||
chain.block_by_number.get(&num).map(|blocks| blocks[0].0.header.hash())
|
||||
})
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
self.push_block_with_parent(parent_hash, xts, is_best_block)
|
||||
@@ -154,7 +151,9 @@ impl TestApi {
|
||||
let block_number = if parent == Hash::default() {
|
||||
0
|
||||
} else {
|
||||
*self.chain.read()
|
||||
*self
|
||||
.chain
|
||||
.read()
|
||||
.block_by_hash
|
||||
.get(&parent)
|
||||
.expect("`parent` exists")
|
||||
@@ -182,7 +181,11 @@ impl TestApi {
|
||||
|
||||
let mut chain = self.chain.write();
|
||||
chain.block_by_hash.insert(hash, block.clone());
|
||||
chain.block_by_number.entry(block_number).or_default().push((block, is_best_block.into()));
|
||||
chain
|
||||
.block_by_number
|
||||
.entry(block_number)
|
||||
.or_default()
|
||||
.push((block, is_best_block.into()));
|
||||
}
|
||||
|
||||
fn hash_and_length_inner(ex: &Extrinsic) -> (Hash, usize) {
|
||||
@@ -195,9 +198,7 @@ impl TestApi {
|
||||
/// Next time transaction pool will try to validate this
|
||||
/// extrinsic, api will return invalid result.
|
||||
pub fn add_invalid(&self, xts: &Extrinsic) {
|
||||
self.chain.write().invalid_hashes.insert(
|
||||
Self::hash_and_length_inner(xts).0
|
||||
);
|
||||
self.chain.write().invalid_hashes.insert(Self::hash_and_length_inner(xts).0);
|
||||
}
|
||||
|
||||
/// Query validation requests received.
|
||||
@@ -242,7 +243,8 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
|
||||
match self.block_id_to_number(at) {
|
||||
Ok(Some(number)) => {
|
||||
let found_best = self.chain
|
||||
let found_best = self
|
||||
.chain
|
||||
.read()
|
||||
.block_by_number
|
||||
.get(&number)
|
||||
@@ -253,24 +255,24 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
// the transaction. (This is not required for this test function, but in real
|
||||
// environment it would fail because of this).
|
||||
if !found_best {
|
||||
return ready(Ok(
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(1)).into())
|
||||
))
|
||||
return ready(Ok(Err(TransactionValidityError::Invalid(
|
||||
InvalidTransaction::Custom(1),
|
||||
)
|
||||
.into())))
|
||||
}
|
||||
},
|
||||
Ok(None) => return ready(Ok(
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(2)).into())
|
||||
)),
|
||||
Ok(None) =>
|
||||
return ready(Ok(Err(TransactionValidityError::Invalid(
|
||||
InvalidTransaction::Custom(2),
|
||||
)
|
||||
.into()))),
|
||||
Err(e) => return ready(Err(e)),
|
||||
}
|
||||
|
||||
let (requires, provides) = if let Some(transfer) = uxt.try_transfer() {
|
||||
let chain_nonce = self.chain.read().nonces.get(&transfer.from).cloned().unwrap_or(0);
|
||||
let requires = if chain_nonce == transfer.nonce {
|
||||
vec![]
|
||||
} else {
|
||||
vec![vec![chain_nonce as u8]]
|
||||
};
|
||||
let requires =
|
||||
if chain_nonce == transfer.nonce { vec![] } else { vec![vec![chain_nonce as u8]] };
|
||||
let provides = vec![vec![transfer.nonce as u8]];
|
||||
|
||||
(requires, provides)
|
||||
@@ -279,18 +281,13 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
};
|
||||
|
||||
if self.chain.read().invalid_hashes.contains(&self.hash_and_length(&uxt).0) {
|
||||
return ready(Ok(
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(0)).into())
|
||||
))
|
||||
return ready(Ok(Err(
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Custom(0)).into()
|
||||
)))
|
||||
}
|
||||
|
||||
let mut validity = ValidTransaction {
|
||||
priority: 1,
|
||||
requires,
|
||||
provides,
|
||||
longevity: 64,
|
||||
propagate: true,
|
||||
};
|
||||
let mut validity =
|
||||
ValidTransaction { priority: 1, requires, provides, longevity: 64, propagate: true };
|
||||
|
||||
(self.valid_modifier.read())(&mut validity);
|
||||
|
||||
@@ -302,11 +299,8 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
at: &BlockId<Self::Block>,
|
||||
) -> Result<Option<sc_transaction_pool::test_helpers::NumberFor<Self>>, Error> {
|
||||
Ok(match at {
|
||||
generic::BlockId::Hash(x) => self.chain
|
||||
.read()
|
||||
.block_by_hash
|
||||
.get(x)
|
||||
.map(|b| *b.header.number()),
|
||||
generic::BlockId::Hash(x) =>
|
||||
self.chain.read().block_by_hash.get(x).map(|b| *b.header.number()),
|
||||
generic::BlockId::Number(num) => Some(*num),
|
||||
})
|
||||
}
|
||||
@@ -317,11 +311,10 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
) -> Result<Option<sc_transaction_pool::test_helpers::BlockHash<Self>>, Error> {
|
||||
Ok(match at {
|
||||
generic::BlockId::Hash(x) => Some(x.clone()),
|
||||
generic::BlockId::Number(num) => self.chain
|
||||
.read()
|
||||
.block_by_number
|
||||
.get(num)
|
||||
.and_then(|blocks| blocks.iter().find(|b| b.1.is_best()).map(|b| b.0.header().hash())),
|
||||
generic::BlockId::Number(num) =>
|
||||
self.chain.read().block_by_number.get(num).and_then(|blocks| {
|
||||
blocks.iter().find(|b| b.1.is_best()).map(|b| b.0.header().hash())
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -334,16 +327,10 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
|
||||
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
|
||||
futures::future::ready(Ok(match id {
|
||||
BlockId::Number(num) => self.chain
|
||||
.read()
|
||||
.block_by_number
|
||||
.get(num)
|
||||
.map(|b| b[0].0.extrinsics().to_vec()),
|
||||
BlockId::Hash(hash) => self.chain
|
||||
.read()
|
||||
.block_by_hash
|
||||
.get(hash)
|
||||
.map(|b| b.extrinsics().to_vec()),
|
||||
BlockId::Number(num) =>
|
||||
self.chain.read().block_by_number.get(num).map(|b| b[0].0.extrinsics().to_vec()),
|
||||
BlockId::Hash(hash) =>
|
||||
self.chain.read().block_by_hash.get(hash).map(|b| b.extrinsics().to_vec()),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -352,16 +339,10 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
at: &BlockId<Self::Block>,
|
||||
) -> Result<Option<<Self::Block as BlockT>::Header>, Self::Error> {
|
||||
Ok(match at {
|
||||
BlockId::Number(num) => self.chain
|
||||
.read()
|
||||
.block_by_number
|
||||
.get(num)
|
||||
.map(|b| b[0].0.header().clone()),
|
||||
BlockId::Hash(hash) => self.chain
|
||||
.read()
|
||||
.block_by_hash
|
||||
.get(hash)
|
||||
.map(|b| b.header().clone()),
|
||||
BlockId::Number(num) =>
|
||||
self.chain.read().block_by_number.get(num).map(|b| b[0].0.header().clone()),
|
||||
BlockId::Hash(hash) =>
|
||||
self.chain.read().block_by_hash.get(hash).map(|b| b.header().clone()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -369,21 +350,14 @@ impl sc_transaction_pool::test_helpers::ChainApi for TestApi {
|
||||
impl sp_blockchain::HeaderMetadata<Block> for TestApi {
|
||||
type Error = Error;
|
||||
|
||||
fn header_metadata(
|
||||
&self,
|
||||
hash: Hash,
|
||||
) -> Result<CachedHeaderMetadata<Block>, Self::Error> {
|
||||
fn header_metadata(&self, hash: Hash) -> Result<CachedHeaderMetadata<Block>, Self::Error> {
|
||||
let chain = self.chain.read();
|
||||
let block = chain.block_by_hash.get(&hash).expect("Hash exists");
|
||||
|
||||
Ok(block.header().into())
|
||||
}
|
||||
|
||||
fn insert_header_metadata(
|
||||
&self,
|
||||
_: Hash,
|
||||
_: CachedHeaderMetadata<Block>,
|
||||
) {
|
||||
fn insert_header_metadata(&self, _: Hash, _: CachedHeaderMetadata<Block>) {
|
||||
unimplemented!("Not implemented for tests")
|
||||
}
|
||||
|
||||
@@ -396,12 +370,7 @@ impl sp_blockchain::HeaderMetadata<Block> for TestApi {
|
||||
///
|
||||
/// Part of the test api.
|
||||
pub fn uxt(who: AccountKeyring, nonce: Index) -> Extrinsic {
|
||||
let transfer = Transfer {
|
||||
from: who.into(),
|
||||
to: AccountId::default(),
|
||||
nonce,
|
||||
amount: 1,
|
||||
};
|
||||
let transfer = Transfer { from: who.into(), to: AccountId::default(), nonce, amount: 1 };
|
||||
let signature = transfer.using_encoded(|e| who.sign(e)).into();
|
||||
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: false }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user