Skip to content

Commit

Permalink
[refactor]: apply most recent clippy suggestions (#4129)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic authored Dec 8, 2023
1 parent 2c3a4ce commit 6f2c04c
Show file tree
Hide file tree
Showing 40 changed files with 129 additions and 143 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
41 changes: 19 additions & 22 deletions config/base/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use serde::{Deserialize, Serialize};
struct ConfigurationProxy {
/// Inner structure
#[config(inner)]
optional_inner: Option<InnerConfigurationProxy>,
inner: Option<InnerConfigurationProxy>,
#[config(serde_as_str)]
pub optional_string_wrapper: Option<StringWrapper>,
pub optional_string: Option<String>,
pub optional_data: Option<Data>,
pub string_wrapper: Option<StringWrapper>,
pub string: Option<String>,
pub data: Option<Data>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Documented)]
Expand All @@ -33,13 +33,13 @@ struct Configuration {
impl ConfigurationProxy {
fn new_with_placeholders() -> Self {
Self {
optional_inner: Some(InnerConfigurationProxy {
inner: Some(InnerConfigurationProxy {
a: Some("string".to_owned()),
b: Some(42),
}),
optional_string_wrapper: Some(StringWrapper("string".to_owned())),
optional_string: Some("cool string".to_owned()),
optional_data: Some(Data {
string_wrapper: Some(StringWrapper("string".to_owned())),
string: Some("cool string".to_owned()),
data: Some(Data {
key: "key".to_owned(),
value: 34,
}),
Expand All @@ -48,10 +48,10 @@ impl ConfigurationProxy {

fn new_with_none() -> Self {
Self {
optional_inner: None,
optional_string_wrapper: None,
optional_string: None,
optional_data: None,
inner: None,
string_wrapper: None,
string: None,
data: None,
}
}
}
Expand Down Expand Up @@ -157,13 +157,10 @@ fn test_env_factory() -> TestEnv {
fn test_proxy_load_from_env() {
let config = ConfigurationProxy::new_with_placeholders();
let env_config = ConfigurationProxy::from_env(&test_env_factory()).expect("valid env");
assert_eq!(&env_config.optional_data, &config.optional_data);
assert_eq!(
&env_config.optional_string_wrapper,
&config.optional_string_wrapper
);
assert_eq!(&env_config.optional_string, &config.optional_string);
assert_eq!(&env_config.optional_inner, &config.optional_inner);
assert_eq!(&env_config.data, &config.data);
assert_eq!(&env_config.string_wrapper, &config.string_wrapper);
assert_eq!(&env_config.string, &config.string);
assert_eq!(&env_config.inner, &config.inner);
}

#[test]
Expand All @@ -172,15 +169,15 @@ fn test_can_load_inner_without_the_wrapping_config() {
env.remove_var("CONF_OPTIONAL_INNER");
let config = ConfigurationProxy::new_with_placeholders();
let env_config = ConfigurationProxy::from_env(&env).expect("valid env");
assert_eq!(&env_config.optional_inner, &config.optional_inner);
assert_eq!(&env_config.inner, &config.inner);
}

#[test]
fn test_proxy_combine_does_not_overload_with_none() {
let config = ConfigurationProxy::new_with_none();
let env_config = ConfigurationProxy::from_env(&test_env_factory()).expect("valid env");
let combine_config = env_config.clone().override_with(config);
assert_eq!(&env_config.optional_data, &combine_config.optional_data);
assert_eq!(&env_config.data, &combine_config.data);
}

#[test]
Expand All @@ -205,5 +202,5 @@ fn configuration_proxy_from_env_returns_err_on_parsing_error() {

let err = Target::from_env(&Env).expect_err("Must not be parsed");
let err = eyre::Report::new(err);
assert_eq!(format!("{err:?}"), "Failed to deserialize the field `FOO`\n\nCaused by:\n JSON5: --> 1:1\n |\n 1 | not u64 for sure\n | ^---\n |\n = expected array, boolean, null, number, object, or string\n\nLocation:\n config/base/tests/simple.rs:207:15");
assert_eq!(format!("{err:?}"), "Failed to deserialize the field `FOO`\n\nCaused by:\n JSON5: --> 1:1\n |\n 1 | not u64 for sure\n | ^---\n |\n = expected array, boolean, null, number, object, or string\n\nLocation:\n config/base/tests/simple.rs:204:15");
}
2 changes: 1 addition & 1 deletion config/src/iroha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Failed to parse Trusted Peers")]
fn parse_trusted_peers_fail_duplicate_peer_id() {
let trusted_peers_string = r#"[{"address":"127.0.0.1:1337", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address":"127.0.0.1:1337", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address":"localhost:1338", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address": "195.162.0.1:23", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}]"#;
let _result: TrustedPeers =
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
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
Loading

0 comments on commit 6f2c04c

Please sign in to comment.