Skip to content

Commit

Permalink
[refactor] #3053: Fix clippy lints (#3054)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix authored Jan 11, 2023
1 parent 6bdfd7c commit 2e1db47
Show file tree
Hide file tree
Showing 76 changed files with 489 additions and 669 deletions.
386 changes: 158 additions & 228 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions actor/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ impl Broker {

/// Number of subscribers for specific message
pub fn subscribers<M: BrokerMessage + Send + Sync>(&self) -> usize {
let entry = if let Entry::Occupied(entry) = self.entry(TypeId::of::<M>()) {
entry
} else {
let Entry::Occupied(entry) = self.entry(TypeId::of::<M>()) else {
return 0;
};

Expand All @@ -120,9 +118,7 @@ impl Broker {

/// Synchronously send message via broker.
pub fn issue_send_sync<M: BrokerMessage + Send + Sync>(&self, m: &M) {
let mut entry = if let Entry::Occupied(entry) = self.entry(TypeId::of::<M>()) {
entry
} else {
let Entry::Occupied(mut entry) = self.entry(TypeId::of::<M>()) else {
return;
};

Expand Down Expand Up @@ -154,9 +150,7 @@ impl Broker {

/// Send message via broker
pub async fn issue_send<M: BrokerMessage + Send + Sync>(&self, m: M) {
let mut entry = if let Entry::Occupied(entry) = self.entry(TypeId::of::<M>()) {
entry
} else {
let Entry::Occupied(mut entry) = self.entry(TypeId::of::<M>()) else {
return;
};

Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ thiserror = "1.0.38"
tokio = { version = "1.23.0", features = ["sync", "time", "rt", "io-util", "rt-multi-thread", "macros", "fs", "signal"] }
warp = "0.3.3"
serial_test = "0.8.0"
lazy_static = "1.4.0"

[build-dependencies]
anyhow = "1.0.68"
Expand Down
27 changes: 11 additions & 16 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use std::{panic, sync::Arc};

use color_eyre::eyre::{eyre, Result, WrapErr};
use eyre::ContextCompat;
use eyre::ContextCompat as _;
use iroha_actor::{broker::*, prelude::*};
use iroha_config::{
base::proxy::{LoadFromDisk, LoadFromEnv, Override},
iroha::{Configuration, ConfigurationProxy},
path::ConfigPath,
path::Path as ConfigPath,
};
use iroha_core::{
block_sync::BlockSynchronizer,
Expand Down Expand Up @@ -57,26 +57,21 @@ pub struct Arguments {
pub config_path: ConfigPath,
}

const CONFIGURATION_PATH: &str = "config";
const GENESIS_PATH: &str = "genesis";
lazy_static::lazy_static! {
/// Default configuration path
pub static ref CONFIGURATION_PATH: &'static std::path::Path = std::path::Path::new("config");
/// Default genesis path
pub static ref GENESIS_PATH : &'static std::path::Path = std::path::Path::new("genesis");
}

const SUBMIT_GENESIS: bool = false;

impl Default for Arguments {
fn default() -> Self {
Self {
submit_genesis: SUBMIT_GENESIS,
genesis_path: Some(ConfigPath::default(GENESIS_PATH).unwrap_or_else(|e| {
panic!(
"Default genesis path `{}` has extension, but it should not have one. {e:?}",
GENESIS_PATH
)
})),
config_path: ConfigPath::default(CONFIGURATION_PATH).unwrap_or_else(|e| {
panic!(
"Default config path `{}` has extension, but it should not have one. {e:?}",
GENESIS_PATH
)
}),
genesis_path: Some(ConfigPath::default(*GENESIS_PATH)),
config_path: ConfigPath::default(*CONFIGURATION_PATH),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Iroha peer command-line interface.

use eyre::WrapErr as _;
use iroha_config::path::ConfigPath;
use iroha_config::path::Path as ConfigPath;
use iroha_core::prelude::AllowAll;
use iroha_permissions_validators::public_blockchain::default_permissions;

Expand Down
2 changes: 2 additions & 0 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl Torii {
}
}

#[allow(opaque_hidden_inferred_bound)]
#[cfg(feature = "telemetry")]
/// Helper function to create router. This router can tested without starting up an HTTP server
fn create_telemetry_router(
Expand Down Expand Up @@ -483,6 +484,7 @@ impl Torii {
}

/// Helper function to create router. This router can tested without starting up an HTTP server
#[allow(opaque_hidden_inferred_bound)]
pub(crate) fn create_api_router(
&self,
) -> impl warp::Filter<Extract = impl warp::Reply> + Clone + Send {
Expand Down
14 changes: 4 additions & 10 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,12 @@ fn query_requests(criterion: &mut Criterion) {
success_count += 1;
}
Err(e) => {
eprintln!("Query failed: {}", e);
eprintln!("Query failed: {e}");
failures_count += 1;
}
});
});
println!(
"Success count: {}, Failures count: {}",
success_count, failures_count
);
println!("Success count: {success_count}, Failures count: {failures_count}");
group.finish();
if (failures_count + success_count) > 0 {
assert!(
Expand Down Expand Up @@ -180,16 +177,13 @@ fn instruction_submits(criterion: &mut Criterion) {
match iroha_client.submit(mint_asset) {
Ok(_) => success_count += 1,
Err(e) => {
eprintln!("Failed to execute instruction: {}", e);
eprintln!("Failed to execute instruction: {e}");
failures_count += 1;
}
};
})
});
println!(
"Success count: {}, Failures count: {}",
success_count, failures_count
);
println!("Success count: {success_count}, Failures count: {failures_count}");
group.finish();
if (failures_count + success_count) > 0 {
assert!(
Expand Down
4 changes: 2 additions & 2 deletions client/benches/tps/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn main() {
|guard| {
guard.flush().expect("Flushed data without errors");
println!("Tracing data outputted to file: {}", &args[1]);
println!("TPS was {}", tps);
println!("Config was {:?}", config);
println!("TPS was {tps}");
println!("Config was {config:?}");
},
)
}
2 changes: 1 addition & 1 deletion client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ fn asset_id(account_name: UnitName) -> AssetId {

#[allow(clippy::expect_used)]
fn account_id(name: UnitName) -> AccountId {
format!("{}@wonderland", name).parse().expect("Valid")
format!("{name}@wonderland").parse().expect("Valid")
}
10 changes: 5 additions & 5 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ fn generate_genesis(num_domains: u32) -> RawGenesisBlock {
let key_pair = get_key_pair();
for i in 0_u32..num_domains {
builder = builder
.domain(format!("wonderland-{}", i).parse().expect("Valid"))
.domain(format!("wonderland-{i}").parse().expect("Valid"))
.account(
format!("Alice-{}", i).parse().expect("Valid"),
format!("Alice-{i}").parse().expect("Valid"),
key_pair.public_key().clone(),
)
.asset(
format!("xor-{}", i).parse().expect("Valid"),
format!("xor-{i}").parse().expect("Valid"),
AssetValueType::Quantity,
)
.finish_domain();
Expand Down Expand Up @@ -64,9 +64,9 @@ fn create_million_accounts_directly() {
let (_rt, _peer, test_client) = <PeerBuilder>::new().start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
for i in 0_u32..1_000_000_u32 {
let domain_id: DomainId = format!("wonderland-{}", i).parse().expect("Valid");
let domain_id: DomainId = format!("wonderland-{i}").parse().expect("Valid");
let normal_account_id = AccountId::new(
format!("bob-{}", i).parse().expect("Valid"),
format!("bob-{i}").parse().expect("Valid"),
domain_id.clone(),
);
let create_domain = RegisterBox::new(Domain::new(domain_id));
Expand Down
8 changes: 4 additions & 4 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl Client {
if let Some(basic_auth) = &configuration.basic_auth {
let credentials = format!("{}:{}", basic_auth.web_login, basic_auth.password);
let encoded = base64::encode(credentials);
headers.insert(String::from("Authorization"), format!("Basic {}", encoded));
headers.insert(String::from("Authorization"), format!("Basic {encoded}"));
}

Ok(Self {
Expand Down Expand Up @@ -435,7 +435,7 @@ impl Client {
let response = req
.build()?
.send()
.wrap_err_with(|| format!("Failed to send transaction with hash {:?}", hash))?;
.wrap_err_with(|| format!("Failed to send transaction with hash {hash:?}"))?;
resp_handler.handle(response)?;
Ok(hash)
}
Expand Down Expand Up @@ -993,7 +993,7 @@ impl Client {
/// If sending request or decoding fails
pub fn set_config(&self, post_config: PostConfiguration) -> Result<bool> {
let body = serde_json::to_vec(&post_config)
.wrap_err(format!("Failed to serialize {:?}", post_config))?;
.wrap_err(format!("Failed to serialize {post_config:?}"))?;
let url = &format!("{}/{}", self.torii_url, uri::CONFIGURATION);
let resp = DefaultRequestBuilder::new(HttpMethod::POST, url)
.header(http::header::CONTENT_TYPE, APPLICATION_JSON)
Expand Down Expand Up @@ -1651,7 +1651,7 @@ mod tests {
.headers
.get("Authorization")
.expect("Expected `Authorization` header");
let expected_value = format!("Basic {}", ENCRYPTED_CREDENTIALS);
let expected_value = format!("Basic {ENCRYPTED_CREDENTIALS}");
assert_eq!(value, &expected_value);
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/http_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Bytes = Vec<u8>;
type AttoHttpRequestBuilderWithBytes = AttoHttpRequestBuilder<atto_body::Bytes<Bytes>>;

fn header_name_from_str(str: &str) -> Result<HeaderName> {
HeaderName::from_str(str).wrap_err_with(|| format!("Failed to parse header name {}", str))
HeaderName::from_str(str).wrap_err_with(|| format!("Failed to parse header name {str}"))
}

/// Default request builder implemented on top of `attohttpc` crate.
Expand Down Expand Up @@ -65,7 +65,7 @@ impl DefaultRequest {
let response = self
.0
.send()
.wrap_err_with(|| format!("Failed to send http {} request to {}", method, url))?;
.wrap_err_with(|| format!("Failed to send http {method} request to {url}"))?;

ClientResponse(response).try_into()
}
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn permissions_disallow_asset_transfer() {
.expect_err("Transaction was not rejected.");
let rejection_reason = err
.downcast_ref::<PipelineRejectionReason>()
.unwrap_or_else(|| panic!("Error {} is not PipelineRejectionReasons.", err));
.unwrap_or_else(|| panic!("Error {err} is not PipelineRejectionReasons."));
//Then
assert!(matches!(
rejection_reason,
Expand Down Expand Up @@ -156,7 +156,7 @@ fn permissions_disallow_asset_burn() {
.expect_err("Transaction was not rejected.");
let rejection_reason = err
.downcast_ref::<PipelineRejectionReason>()
.unwrap_or_else(|| panic!("Error {} is not PipelineRejectionReasons.", err));
.unwrap_or_else(|| panic!("Error {err} is not PipelineRejectionReasons."));
//Then
assert!(matches!(
rejection_reason,
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/query_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fn non_existent_account_is_specific_error() {
match err {
ClientQueryError::QueryError(QueryError::Find(err)) => match *err {
FindError::Domain(id) => assert_eq!(id.name.as_ref(), "regalia"),
x => panic!("FindError::Domain expected, got {:?}", x),
x => panic!("FindError::Domain expected, got {x:?}"),
},
x => panic!("Unexpected error: {:?}", x),
x => panic!("Unexpected error: {x:?}"),
};
}
8 changes: 4 additions & 4 deletions client/tests/integration/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn correct_pagination_assets_after_creating_new_one() {

for i in 0..10_u128 {
let asset_definition_id =
AssetDefinitionId::from_str(&format!("xor{}#wonderland", i)).expect("Valid");
AssetDefinitionId::from_str(&format!("xor{i}#wonderland")).expect("Valid");
let asset_definition = AssetDefinition::store(asset_definition_id.clone());
let mut asset_metadata = Metadata::new();
asset_metadata
Expand Down Expand Up @@ -128,7 +128,7 @@ fn correct_sorting_of_asset_definitions() {

for i in 0..10_u128 {
let asset_definition_id =
AssetDefinitionId::from_str(&format!("xor{}#wonderland", i)).expect("Valid");
AssetDefinitionId::from_str(&format!("xor{i}#wonderland")).expect("Valid");
let mut asset_metadata = Metadata::new();
asset_metadata
.insert_with_limits(
Expand Down Expand Up @@ -180,7 +180,7 @@ fn correct_sorting_of_asset_definitions() {
let mut instructions = vec![];

for i in 0..10_u128 {
let account_id = AccountId::from_str(&format!("bob{}@wonderland", i)).expect("Valid");
let account_id = AccountId::from_str(&format!("bob{i}@wonderland")).expect("Valid");
let mut account_metadata = Metadata::new();
account_metadata
.insert_with_limits(
Expand Down Expand Up @@ -237,7 +237,7 @@ fn correct_sorting_of_asset_definitions() {
let mut instructions = vec![];

for i in 0..10_u128 {
let domain_id = DomainId::from_str(&format!("neverland{}", i)).expect("Valid");
let domain_id = DomainId::from_str(&format!("neverland{i}")).expect("Valid");
let mut domain_metadata = Metadata::new();
domain_metadata
.insert_with_limits(
Expand Down
4 changes: 1 addition & 3 deletions client/tests/integration/triggers/time_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ fn time_trigger_execution_count_error_should_be_less_than_15_percent() -> Result
- core::cmp::min(actual_value, expected_value)) as f32;
assert!(
error < acceptable_error,
"error = {}, but acceptable error = {}",
error,
acceptable_error
"error = {error}, but acceptable error = {acceptable_error}"
);

Ok(())
Expand Down
1 change: 1 addition & 0 deletions client_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ color-eyre = "0.6.2"
clap = { version = "3.2.23", features = ["derive"] }
dialoguer = { version = "0.10.2", default-features = false }
json5 = "0.4.1"
lazy_static = "1.4.0"

[build-dependencies]
anyhow = "1.0.68"
Expand Down
Loading

0 comments on commit 2e1db47

Please sign in to comment.