Skip to content

Commit

Permalink
[refactor]: apply new clippy suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Dec 8, 2023
1 parent 2c3a4ce commit d91fcc2
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 91 deletions.
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl NetworkRelay {
tokio::select! {
// Receive message from network
Some(msg) = receiver.recv() => self.handle_message(msg).await,
_ = self.shutdown_notify.notified() => {
() = self.shutdown_notify.notified() => {
iroha_logger::info!("NetworkRelay is being shut down.");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn simulate_transfer_fixed() {
)
}

#[should_panic]
#[test]
#[ignore = "long"]
#[should_panic(expected = "insufficient funds")]
fn simulate_insufficient_funds() {
simulate_transfer(
Fixed::try_from(20_f64).expect("Valid"),
Expand Down
4 changes: 3 additions & 1 deletion config/base/derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ pub fn extract_box_generic(box_seg: &mut syn::PathSegment) -> &mut syn::Type {
generics.args.len() == 1,
"`Box` should have exactly one generic argument"
);
let syn::GenericArgument::Type(generic_type) = generics.args.first_mut().expect("Can't be empty") else {
let syn::GenericArgument::Type(generic_type) =
generics.args.first_mut().expect("Can't be empty")
else {
panic!("`Box` should have type as a generic argument")
};

Expand Down
2 changes: 1 addition & 1 deletion core/benches/blocks/apply_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl WsvApplyBlocks {
.map(|instructions| {
let block =
create_block(&mut wsv, instructions, account_id.clone(), key_pair.clone());
wsv.apply_without_execution(&block).map(|_| block)
wsv.apply_without_execution(&block).map(|()| block)
})
.collect::<Result<Vec<_>, _>>()?
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl BlockSynchronizer {
loop {
tokio::select! {
_ = gossip_period.tick() => self.request_block().await,
_ = self.sumeragi.wsv_updated() => {
() = self.sumeragi.wsv_updated() => {
let (latest_hash, previous_hash) = self
.sumeragi
.apply_wsv(|wsv| (wsv.latest_block_hash(), wsv.previous_block_hash()));
Expand Down
4 changes: 2 additions & 2 deletions core/src/gossiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TransactionGossiper {
loop {
tokio::select! {
_ = gossip_period.tick() => self.gossip_transactions(),
_ = self.sumeragi.wsv_updated() => {
() = self.sumeragi.wsv_updated() => {
self.wsv = self.sumeragi.wsv_clone();
}
transaction_gossip = message_receiver.recv() => {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl TransactionGossiper {

match AcceptedTransaction::accept(tx, transaction_limits) {
Ok(tx) => match self.queue.push(tx, &self.wsv) {
Ok(_) => {}
Ok(()) => {}
Err(crate::queue::Failure {
tx,
err: crate::queue::Error::InBlockchain,
Expand Down
8 changes: 4 additions & 4 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Kura {
let mut block_data_buffer = vec![0_u8; block.length.try_into()?];

match block_store.read_block_data(block.start, &mut block_data_buffer) {
Ok(_) => match SignedBlock::decode_all_versioned(&block_data_buffer) {
Ok(()) => match SignedBlock::decode_all_versioned(&block_data_buffer) {
Ok(decoded_block) => {
if previous_block_hash != decoded_block.payload().header.previous_block_hash
{
Expand Down Expand Up @@ -416,7 +416,7 @@ impl BlockStore {
.map_err(|e| Error::MkDir(e, store_path.to_path_buf()))
{
Err(e) => Err(e),
Ok(_) => {
Ok(()) => {
if let Err(e) = fs::File::options()
.read(true)
.write(true)
Expand Down Expand Up @@ -560,7 +560,7 @@ impl BlockStore {
hashes_file
.read_exact(&mut buffer)
.add_err_context(&path)
.and_then(|_| HashOf::decode_all(&mut buffer.as_slice()).map_err(Error::Codec))
.and_then(|()| HashOf::decode_all(&mut buffer.as_slice()).map_err(Error::Codec))
})
.collect()
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Kura must be able to lock the blockstore: ")]
fn concurrent_lock() {
let dir = tempfile::tempdir().unwrap();
let _store = BlockStore::new(dir.path(), LockStatus::Unlocked);
Expand Down
13 changes: 2 additions & 11 deletions core/src/query/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ impl<I: IntoIterator + FromIterator<I::Item>> Batched<I> {

self.cursor = if let Some(cursor) = self.cursor {
if batch_size >= self.batch_size.get() {
let batch_size = self
.batch_size
.get()
.try_into()
.expect("usize should fit in u64");
let batch_size = self.batch_size.get().into();
Some(
cursor
.checked_add(batch_size)
Expand All @@ -76,12 +72,7 @@ impl<I: IntoIterator + FromIterator<I::Item>> Batched<I> {
None
}
} else if batch_size >= self.batch_size.get() {
Some(
self.batch_size
.get()
.try_into()
.expect("usize should fit in u64"),
)
Some(self.batch_size.get().into())
} else {
None
};
Expand Down
12 changes: 9 additions & 3 deletions core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,19 @@ mod tests {
.handle_query_output(query_output, &sorting, pagination, fetch_size)
.unwrap()
.into();
let Value::Vec(v) = batch else { panic!("not expected result") };
let Value::Vec(v) = batch else {
panic!("not expected result")
};
counter += v.len();

while cursor.cursor.is_some() {
let Ok(batched) = query_store_handle.handle_query_cursor(cursor) else { break };
let Ok(batched) = query_store_handle.handle_query_cursor(cursor) else {
break;
};
let (batch, new_cursor) = batched.into();
let Value::Vec(v) = batch else { panic!("not expected result") };
let Value::Vec(v) = batch else {
panic!("not expected result")
};
counter += v.len();

cursor = new_cursor;
Expand Down
4 changes: 1 addition & 3 deletions core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ pub mod isi {

match wsv.asset(&asset_id) {
Err(err) => match err {
QueryExecutionFail::Find(find_err)
if matches!(find_err, FindError::Asset(_)) =>
{
QueryExecutionFail::Find(FindError::Asset(_)) => {
assert_can_register(&asset_id.definition_id, wsv, &self.object.value)?;
let asset = wsv
.asset_or_insert(asset_id.clone(), self.object.value)
Expand Down
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/triggers/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<F: Clone + Serialize> Serialize for TriggersWithContext<'_, F> {
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.triggers.len()))?;
for (id, action) in self.triggers.iter() {
for (id, action) in self.triggers {
let action = self.set.get_original_action(action.clone());
map.serialize_entry(&id, &action)?;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl SnapshotMaker {
// Offload snapshot creation into blocking thread
self.create_snapshot().await;
},
_ = self.sumeragi.finalized_wsv_updated() => {
() = self.sumeragi.finalized_wsv_updated() => {
self.sumeragi.apply_finalized_wsv(|finalized_wsv| self.new_wsv_available = finalized_wsv.height() > 0);
}
_ = message_receiver.recv() => {
Expand Down
2 changes: 1 addition & 1 deletion core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl WorldStateView {
}
let wsv = self.clone();
let event = match self.process_trigger(&id, &action, event) {
Ok(_) => {
Ok(()) => {
succeed.push(id.clone());
TriggerCompletedEvent::new(id, TriggerCompletedOutcome::Success)
}
Expand Down
5 changes: 1 addition & 4 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ impl FromStr for PublicKey {
#[cfg(not(feature = "ffi_import"))]
impl PublicKey {
fn normalize(&self) -> String {
let multihash: &multihash::Multihash = &self
.clone()
.try_into()
.expect("Failed to get multihash representation.");
let multihash: &multihash::Multihash = &self.clone().into();
let bytes = Vec::try_from(multihash).expect("Failed to convert multihash to bytes.");

let mut bytes_iter = bytes.into_iter();
Expand Down
10 changes: 5 additions & 5 deletions crypto/src/signature/bls/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<C: BlsConfiguration + ?Sized> PublicKey<C> {

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
Ok(Self(
C::Generator::from_bytes(bytes).map_err(|e| Error::Parse(format!("{:?}", e)))?,
C::Generator::from_bytes(bytes).map_err(|e| Error::Parse(format!("{e:?}")))?,
))
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<C: BlsConfiguration + ?Sized> Signature<C> {

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
Ok(Signature(
C::SignatureGroup::from_bytes(bytes).map_err(|e| Error::Parse(format!("{:?}", e)))?,
C::SignatureGroup::from_bytes(bytes).map_err(|e| Error::Parse(format!("{e:?}")))?,
))
}
}
Expand All @@ -140,13 +140,13 @@ impl<C: BlsConfiguration + ?Sized> BlsImpl<C> {
fn parse_public_key(pk: &IrohaPublicKey) -> Result<PublicKey<C>, Error> {
assert_eq!(pk.digest_function, C::ALGORITHM);
PublicKey::from_bytes(&pk.payload)
.map_err(|e| Error::Parse(format!("Failed to parse public key: {}", e)))
.map_err(|e| Error::Parse(format!("Failed to parse public key: {e}")))
}

fn parse_private_key(sk: &IrohaPrivateKey) -> Result<PrivateKey, Error> {
assert_eq!(sk.digest_function, C::ALGORITHM);
PrivateKey::from_bytes(&sk.payload)
.map_err(|e| Error::Parse(format!("Failed to parse private key: {}", e)))
.map_err(|e| Error::Parse(format!("Failed to parse private key: {e}")))
}

// the names are from an RFC, not a good idea to change them
Expand All @@ -165,7 +165,7 @@ impl<C: BlsConfiguration + ?Sized> BlsImpl<C> {
let mut okm = [0u8; PRIVATE_KEY_SIZE];
let h = hkdf::Hkdf::<Sha256>::new(Some(&salt[..]), &ikm);
h.expand(&info[..], &mut okm).map_err(|err| {
Error::KeyGen(format!("Failed to generate keypair: {}", err))
Error::KeyGen(format!("Failed to generate keypair: {err}"))
})?;
let private_key: PrivateKey = PrivateKey::from(&okm);
(
Expand Down
6 changes: 1 addition & 5 deletions crypto/src/signature/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use std::convert::TryFrom;

use arrayref::array_ref;
use ed25519_dalek::{Signature, SigningKey, VerifyingKey as PK};
pub use ed25519_dalek::{
EXPANDED_SECRET_KEY_LENGTH as PRIVATE_KEY_SIZE, PUBLIC_KEY_LENGTH as PUBLIC_KEY_SIZE,
SIGNATURE_LENGTH as SIGNATURE_SIZE,
};
use iroha_primitives::const_vec::ConstVec;
use rand::{rngs::OsRng, SeedableRng};
use rand_chacha::ChaChaRng;
Expand Down Expand Up @@ -146,7 +142,7 @@ mod test {
assert!(result.is_ok());
assert!(result.unwrap());

assert_eq!(sig.len(), SIGNATURE_SIZE);
assert_eq!(sig.len(), ed25519_dalek::SIGNATURE_LENGTH);
assert_eq!(hex::encode(sig.as_slice()), SIGNATURE_1);

//Check if libsodium signs the message and this module still can verify it
Expand Down
6 changes: 3 additions & 3 deletions crypto/src/signature/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod ecdsa_secp256k1 {
pub fn sign(message: &[u8], sk: &PrivateKey) -> Result<Vec<u8>, Error> {
assert_eq!(sk.digest_function, ALGORITHM);
let signing_key = k256::SecretKey::from_slice(&sk.payload[..])
.map_err(|e| Error::Signing(format!("{:?}", e)))?;
.map_err(|e| Error::Signing(format!("{e:?}")))?;
let signing_key = k256::ecdsa::SigningKey::from(signing_key);

let signature: k256::ecdsa::Signature = signing_key.sign(message);
Expand All @@ -91,9 +91,9 @@ mod ecdsa_secp256k1 {
pub fn verify(message: &[u8], signature: &[u8], pk: &PublicKey) -> Result<bool, Error> {
let compressed_pk = Self::public_key_compressed(pk);
let verifying_key = k256::PublicKey::from_sec1_bytes(&compressed_pk)
.map_err(|e| Error::Signing(format!("{:?}", e)))?;
.map_err(|e| Error::Signing(format!("{e:?}")))?;
let signature = k256::ecdsa::Signature::from_slice(signature)
.map_err(|e| Error::Signing(format!("{:?}", e)))?;
.map_err(|e| Error::Signing(format!("{e:?}")))?;

let verifying_key = k256::ecdsa::VerifyingKey::from(verifying_key);

Expand Down
2 changes: 1 addition & 1 deletion data_model/derive/tests/partial_tagged_serde_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn partially_tagged_serde() {
Negate(Box::new(Atom(42))),
Negate(Box::new(Negate(Box::new(Atom(42))))),
];
let serialized_values = [r#"42"#, r#"{"Negate":42}"#, r#"{"Negate":{"Negate":42}}"#];
let serialized_values = [r"42", r#"{"Negate":42}"#, r#"{"Negate":{"Negate":42}}"#];

for (value, serialized_value) in values.iter().zip(serialized_values.iter()) {
let serialized = serde_json::to_string(value)
Expand Down
14 changes: 7 additions & 7 deletions data_model/src/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ mod tests {
],
events
.iter()
.cloned()
.filter(|event| PipelineEventFilter::new()
.filter(|&event| PipelineEventFilter::new()
.hash(Hash::prehashed([0_u8; Hash::LENGTH]))
.matches(event))
.cloned()
.collect::<Vec<PipelineEvent>>()
);
assert_eq!(
Expand All @@ -290,10 +290,10 @@ mod tests {
}],
events
.iter()
.cloned()
.filter(|event| PipelineEventFilter::new()
.filter(|&event| PipelineEventFilter::new()
.entity_kind(PipelineEntityKind::Block)
.matches(event))
.cloned()
.collect::<Vec<PipelineEvent>>()
);
assert_eq!(
Expand All @@ -304,19 +304,19 @@ mod tests {
}],
events
.iter()
.cloned()
.filter(|event| PipelineEventFilter::new()
.filter(|&event| PipelineEventFilter::new()
.entity_kind(PipelineEntityKind::Transaction)
.hash(Hash::prehashed([2_u8; Hash::LENGTH]))
.matches(event))
.cloned()
.collect::<Vec<PipelineEvent>>()
);
assert_eq!(
events,
events
.iter()
.filter(|&event| PipelineEventFilter::new().matches(event))
.cloned()
.filter(|event| PipelineEventFilter::new().matches(event))
.collect::<Vec<PipelineEvent>>()
)
}
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ pub mod ip_addr {
self.0
.iter()
.copied()
.zip(input.into_iter())
.zip(input)
.all(|(myself, other)| myself.applies(other))
}
}
Expand Down
1 change: 1 addition & 0 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ macro_rules! ffi_type {
type Target = $target;

#[inline]
#[allow(clippy::redundant_closure_call)]
unsafe fn is_valid(target: &Self::Target) -> bool {
$validity_fn(target)
}
Expand Down
Loading

0 comments on commit d91fcc2

Please sign in to comment.