mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +00:00
Make clippy _a little_ more annoying (#10570)
* Clippy: +complexity * Update client/cli/src/arg_enums.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update bin/node/inspect/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update primitives/keystore/src/testing.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/elections/src/lib.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Update primitives/npos-elections/fuzzer/src/reduce.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Incorporating feedback * No need for Ok * Additional * Needed slice * Wigy's suggestions on less derefs * fix count * reverting changes brought in by option_map_unit_fn * add --all-targets Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -235,9 +235,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
// compatible. To ensure that we forward it by ref/value, we use the value given by the
|
||||
// the user. Otherwise if it is not using the block, we don't need to add anything.
|
||||
let input_borrows =
|
||||
params
|
||||
.iter()
|
||||
.map(|v| if type_is_using_block(&v.1) { v.2.clone() } else { None });
|
||||
params.iter().map(|v| if type_is_using_block(&v.1) { v.2 } else { None });
|
||||
|
||||
// Replace all `Block` with `NodeBlock`, add `'a` lifetime to references and collect
|
||||
// all the function inputs.
|
||||
@@ -380,7 +378,6 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
// Generate the generator function
|
||||
result.push(quote!(
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn #fn_name<
|
||||
R: #crate_::Encode + #crate_::Decode + PartialEq,
|
||||
NC: FnOnce() -> std::result::Result<R, #crate_::ApiError> + std::panic::UnwindSafe,
|
||||
|
||||
@@ -88,13 +88,13 @@ impl<H: HeaderT> sp_inherents::InherentDataProvider for InherentDataProvider<H>
|
||||
async fn try_handle_error(
|
||||
&self,
|
||||
identifier: &InherentIdentifier,
|
||||
error: &[u8],
|
||||
mut error: &[u8],
|
||||
) -> Option<Result<(), Error>> {
|
||||
if *identifier != INHERENT_IDENTIFIER {
|
||||
return None
|
||||
}
|
||||
|
||||
let error = InherentError::decode(&mut &error[..]).ok()?;
|
||||
let error = InherentError::decode(&mut error).ok()?;
|
||||
|
||||
Some(Err(Error::Application(Box::from(format!("{:?}", error)))))
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ mod implementation {
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_fields<'a>(name_str: &str, fields: Fields) -> TokenStream {
|
||||
fn derive_fields(name_str: &str, fields: Fields) -> TokenStream {
|
||||
match fields {
|
||||
Fields::Named { names, this } => {
|
||||
let names_str: Vec<_> = names.iter().map(|x| x.to_string()).collect();
|
||||
|
||||
@@ -482,9 +482,7 @@ mod tests {
|
||||
assert!(res.is_none());
|
||||
|
||||
// insert key, sign again
|
||||
let res =
|
||||
SyncCryptoStore::insert_unknown(&store, ECDSA, suri, pair.public().as_ref()).unwrap();
|
||||
assert_eq!((), res);
|
||||
SyncCryptoStore::insert_unknown(&store, ECDSA, suri, pair.public().as_ref()).unwrap();
|
||||
|
||||
let res =
|
||||
SyncCryptoStore::ecdsa_sign_prehashed(&store, ECDSA, &pair.public(), &msg).unwrap();
|
||||
|
||||
@@ -11,7 +11,7 @@ fn main() {
|
||||
loop {
|
||||
fuzz!(|fuzzer_data: &[u8]| {
|
||||
let result_decoded: Result<InnerTestSolutionCompact, Error> =
|
||||
<InnerTestSolutionCompact as codec::Decode>::decode(&mut &fuzzer_data[..]);
|
||||
<InnerTestSolutionCompact as codec::Decode>::decode(&mut &*fuzzer_data);
|
||||
// Ignore errors as not every random sequence of bytes can be decoded as
|
||||
// InnerTestSolutionCompact
|
||||
if let Ok(decoded) = result_decoded {
|
||||
|
||||
@@ -90,7 +90,7 @@ fn generate_random_phragmen_assignment(
|
||||
.map(|_| {
|
||||
let target =
|
||||
targets_to_chose_from.remove(rng.gen_range(0, targets_to_chose_from.len()));
|
||||
if winners.iter().find(|w| **w == target).is_none() {
|
||||
if winners.iter().all(|w| *w != target) {
|
||||
winners.push(target.clone());
|
||||
}
|
||||
(target, rng.gen_range(1 * KSM, 100 * KSM))
|
||||
|
||||
@@ -275,9 +275,8 @@ fn reduce_4<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32 {
|
||||
});
|
||||
|
||||
// remove either one of them.
|
||||
let who_removed = remove_indices.iter().find(|i| **i < 2usize).is_some();
|
||||
let other_removed =
|
||||
remove_indices.into_iter().find(|i| *i >= 2usize).is_some();
|
||||
let who_removed = remove_indices.iter().any(|i| *i < 2usize);
|
||||
let other_removed = remove_indices.into_iter().any(|i| i >= 2usize);
|
||||
|
||||
match (who_removed, other_removed) {
|
||||
(false, true) => {
|
||||
|
||||
@@ -62,17 +62,17 @@ fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExte
|
||||
|
||||
#[test]
|
||||
fn test_return_data() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_data");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_return_data");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_return_option_data() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_option_data");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_return_option_data");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_storage() {
|
||||
let mut ext = call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_set_storage");
|
||||
let mut ext = call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_set_storage");
|
||||
|
||||
let expected = "world";
|
||||
assert_eq!(expected.as_bytes(), &ext.ext().storage("hello".as_bytes()).unwrap()[..]);
|
||||
@@ -81,30 +81,30 @@ fn test_set_storage() {
|
||||
#[test]
|
||||
fn test_return_value_into_mutable_reference() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_return_value_into_mutable_reference",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_and_return_array() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_get_and_return_array");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_get_and_return_array");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_as_mutable_reference() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_array_as_mutable_reference");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_array_as_mutable_reference");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_return_input_public_key() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_input_public_key");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_return_input_public_key");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn host_function_not_found() {
|
||||
let err = call_wasm_method_with_result::<()>(&wasm_binary_unwrap()[..], "test_return_data")
|
||||
.unwrap_err();
|
||||
let err =
|
||||
call_wasm_method_with_result::<()>(wasm_binary_unwrap(), "test_return_data").unwrap_err();
|
||||
|
||||
assert!(err.contains("Instantiation: Export "));
|
||||
assert!(err.contains(" not found"));
|
||||
@@ -114,7 +114,7 @@ fn host_function_not_found() {
|
||||
#[should_panic(expected = "Invalid utf8 data provided")]
|
||||
fn test_invalid_utf8_data_should_return_an_error() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_invalid_utf8_data_should_return_an_error",
|
||||
);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ fn test_invalid_utf8_data_should_return_an_error() {
|
||||
#[test]
|
||||
fn test_overwrite_native_function_implementation() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_overwrite_native_function_implementation",
|
||||
);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ fn test_overwrite_native_function_implementation() {
|
||||
#[test]
|
||||
fn test_u128_i128_as_parameter_and_return_value() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_u128_i128_as_parameter_and_return_value",
|
||||
);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ fn test_u128_i128_as_parameter_and_return_value() {
|
||||
#[test]
|
||||
fn test_vec_return_value_memory_is_freed() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_vec_return_value_memory_is_freed",
|
||||
);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ fn test_vec_return_value_memory_is_freed() {
|
||||
#[test]
|
||||
fn test_encoded_return_value_memory_is_freed() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_encoded_return_value_memory_is_freed",
|
||||
);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ fn test_encoded_return_value_memory_is_freed() {
|
||||
#[test]
|
||||
fn test_array_return_value_memory_is_freed() {
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_unwrap()[..],
|
||||
wasm_binary_unwrap(),
|
||||
"test_array_return_value_memory_is_freed",
|
||||
);
|
||||
}
|
||||
@@ -162,14 +162,11 @@ fn test_array_return_value_memory_is_freed() {
|
||||
#[test]
|
||||
fn test_versionining_with_new_host_works() {
|
||||
// We call to the new wasm binary with new host function.
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_versionning_works");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_versionning_works");
|
||||
|
||||
// we call to the old wasm binary with a new host functions
|
||||
// old versions of host functions should be called and test should be ok!
|
||||
call_wasm_method::<HostFunctions>(
|
||||
&wasm_binary_deprecated_unwrap()[..],
|
||||
"test_versionning_works",
|
||||
);
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_deprecated_unwrap(), "test_versionning_works");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -224,7 +221,7 @@ fn test_tracing() {
|
||||
let _guard = tracing::subscriber::set_default(subscriber.clone());
|
||||
|
||||
// Call some method to generate a trace
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_data");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_return_data");
|
||||
|
||||
let inner = subscriber.0.lock().unwrap();
|
||||
assert!(inner.spans.contains("return_input_version_1"));
|
||||
@@ -232,5 +229,5 @@ fn test_tracing() {
|
||||
|
||||
#[test]
|
||||
fn test_return_input_as_tuple() {
|
||||
call_wasm_method::<HostFunctions>(&wasm_binary_unwrap()[..], "test_return_input_as_tuple");
|
||||
call_wasm_method::<HostFunctions>(wasm_binary_unwrap(), "test_return_input_as_tuple");
|
||||
}
|
||||
|
||||
@@ -33,19 +33,13 @@ use crate::{
|
||||
use sp_core::RuntimeDebug;
|
||||
|
||||
/// Generic header digest.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, parity_util_mem::MallocSizeOf))]
|
||||
pub struct Digest {
|
||||
/// A list of logs in the digest.
|
||||
pub logs: Vec<DigestItem>,
|
||||
}
|
||||
|
||||
impl Default for Digest {
|
||||
fn default() -> Self {
|
||||
Self { logs: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Digest {
|
||||
/// Get reference to all digest items.
|
||||
pub fn logs(&self) -> &[DigestItem] {
|
||||
|
||||
@@ -395,7 +395,7 @@ mod tests {
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
self.validate(who, call, info, len).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1074,7 +1074,7 @@ impl SignedExtension for () {
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
self.validate(who, call, info, len).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
}
|
||||
let (root, parent_txs) = self.storage_root(
|
||||
delta
|
||||
.map(|(k, v)| (&k[..], v.as_ref().map(|v| &v[..])))
|
||||
.map(|(k, v)| (k, v.as_ref().map(|v| &v[..])))
|
||||
.chain(child_roots.iter().map(|(k, v)| (&k[..], v.as_ref().map(|v| &v[..])))),
|
||||
state_version,
|
||||
);
|
||||
|
||||
@@ -581,7 +581,7 @@ where
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&storage_key.as_ref()),
|
||||
child_info = %HexDisplay::from(&storage_key),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = false,
|
||||
);
|
||||
@@ -599,7 +599,7 @@ where
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
ext_id = %HexDisplay::from(&self.id.to_le_bytes()),
|
||||
child_info = %HexDisplay::from(&storage_key.as_ref()),
|
||||
child_info = %HexDisplay::from(&storage_key),
|
||||
storage_root = %HexDisplay::from(&root.as_ref()),
|
||||
cached = false,
|
||||
);
|
||||
|
||||
@@ -203,7 +203,7 @@ where
|
||||
///
|
||||
/// This implementation will wipe the proof recorded in between calls. Consecutive calls will
|
||||
/// get their own proof from scratch.
|
||||
pub fn execute_and_prove<'a, R>(&mut self, execute: impl FnOnce() -> R) -> (R, StorageProof) {
|
||||
pub fn execute_and_prove<R>(&mut self, execute: impl FnOnce() -> R) -> (R, StorageProof) {
|
||||
let proving_backend = InMemoryProvingBackend::new(&self.backend);
|
||||
let mut proving_ext = Ext::new(
|
||||
&mut self.overlay,
|
||||
|
||||
@@ -138,9 +138,9 @@ impl IsFatalError for InherentError {
|
||||
impl InherentError {
|
||||
/// Try to create an instance ouf of the given identifier and data.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn try_from(id: &InherentIdentifier, data: &[u8]) -> Option<Self> {
|
||||
pub fn try_from(id: &InherentIdentifier, mut data: &[u8]) -> Option<Self> {
|
||||
if id == &INHERENT_IDENTIFIER {
|
||||
<InherentError as codec::Decode>::decode(&mut &data[..]).ok()
|
||||
<InherentError as codec::Decode>::decode(&mut data).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -227,7 +227,7 @@ impl sp_inherents::InherentDataProvider for InherentDataProvider {
|
||||
&self,
|
||||
inherent_data: &mut InherentData,
|
||||
) -> Result<(), sp_inherents::Error> {
|
||||
inherent_data.put_data(INHERENT_IDENTIFIER, &InherentType::from(self.timestamp))
|
||||
inherent_data.put_data(INHERENT_IDENTIFIER, &self.timestamp)
|
||||
}
|
||||
|
||||
async fn try_handle_error(
|
||||
|
||||
@@ -67,7 +67,7 @@ pub trait TransactionStorageProofInherentData {
|
||||
|
||||
impl TransactionStorageProofInherentData for InherentData {
|
||||
fn storage_proof(&self) -> Result<Option<TransactionStorageProof>, Error> {
|
||||
Ok(self.get_data(&INHERENT_IDENTIFIER)?)
|
||||
self.get_data(&INHERENT_IDENTIFIER)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,13 +98,13 @@ impl sp_inherents::InherentDataProvider for InherentDataProvider {
|
||||
async fn try_handle_error(
|
||||
&self,
|
||||
identifier: &InherentIdentifier,
|
||||
error: &[u8],
|
||||
mut error: &[u8],
|
||||
) -> Option<Result<(), Error>> {
|
||||
if *identifier != INHERENT_IDENTIFIER {
|
||||
return None
|
||||
}
|
||||
|
||||
let error = InherentError::decode(&mut &error[..]).ok()?;
|
||||
let error = InherentError::decode(&mut error).ok()?;
|
||||
|
||||
Some(Err(Error::Application(Box::from(format!("{:?}", error)))))
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ where
|
||||
L: TrieConfiguration,
|
||||
DB: hash_db::HashDBRef<L::Hash, trie_db::DBValue>,
|
||||
{
|
||||
Ok(TrieDB::<L>::new(&*db, root)?.get(key).map(|x| x.map(|val| val.to_vec()))?)
|
||||
TrieDB::<L>::new(&*db, root)?.get(key).map(|x| x.map(|val| val.to_vec()))
|
||||
}
|
||||
|
||||
/// Read a value from the trie with given Query.
|
||||
@@ -296,9 +296,9 @@ where
|
||||
Q: Query<L::Hash, Item = DBValue>,
|
||||
DB: hash_db::HashDBRef<L::Hash, trie_db::DBValue>,
|
||||
{
|
||||
Ok(TrieDB::<L>::new(&*db, root)?
|
||||
TrieDB::<L>::new(&*db, root)?
|
||||
.get_with(key, query)
|
||||
.map(|x| x.map(|val| val.to_vec()))?)
|
||||
.map(|x| x.map(|val| val.to_vec()))
|
||||
}
|
||||
|
||||
/// Determine the empty trie root.
|
||||
|
||||
Reference in New Issue
Block a user