Skip to content

Commit

Permalink
chore(lints): fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Sep 10, 2024
1 parent f970b9a commit e1026a5
Show file tree
Hide file tree
Showing 94 changed files with 409 additions and 400 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ tungstenite = "0.21.0"
crossbeam-queue = "0.3.11"
parking_lot = { version = "0.12.3" }

once_cell = "1.19.0"
tempfile = "3.10.1"
path-absolutize = "3.1.1"
pathdiff = "0.2.1"
Expand Down Expand Up @@ -129,16 +128,17 @@ mv = { version = "0.1.0" }
[workspace.lints]
rustdoc.private_doc_tests = "deny"

rust.future_incompatible = {level = "deny", priority = -1 }
rust.nonstandard_style = {level = "deny", priority = -1 }
rust.rust_2018_idioms = {level = "deny", priority = -1 }
rust.unused = { level = "deny", priority = -1 }

rust.anonymous_parameters = "deny"
rust.future_incompatible = "deny"
rust.missing_copy_implementations = "deny"
rust.missing_docs = "deny"
rust.nonstandard_style = "deny"
rust.rust_2018_idioms = "deny"
rust.trivial_casts = "deny"
rust.trivial_numeric_casts = "deny"
rust.unsafe_code = "deny"
rust.unused = "deny"
rust.unused_import_braces = "deny"
rust.variant_size_differences = "deny"
rust.explicit_outlives_requirements = "deny"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM --platform=linux/amd64 archlinux:base-devel AS builder

ARG NIGHTLY_VERSION=2024-04-18
ARG NIGHTLY_VERSION=2024-09-09

RUN <<EOT
set -eux
Expand Down
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ thiserror = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true, features = ["macros", "signal"] }
tokio-util = { workspace = true, features = ["rt"] }
once_cell = { workspace = true }
owo-colors = { workspace = true, features = ["supports-colors"] }
supports-color = { workspace = true }
toml = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub mod samples;

const EVENTS_BUFFER_CAPACITY: usize = 10_000;

/// Iroha is an
/// [Orchestrator](https://en.wikipedia.org/wiki/Orchestration_%28computing%29)
/// of the system. It configures, coordinates and manages transactions
/// and queries processing, work of consensus and storage.
Expand Down Expand Up @@ -527,7 +526,7 @@ fn validate_config(config: &Config) -> Result<(), ConfigError> {
// These cause race condition in tests, due to them actually binding TCP listeners
// Since these validations are primarily for the convenience of the end user,
// it seems a fine compromise to run it only in release mode
#[cfg(release)]
#[cfg(not(test))]
{
validate_try_bind_address(&mut emitter, &config.network.address);
validate_try_bind_address(&mut emitter, &config.torii.address);
Expand Down Expand Up @@ -608,7 +607,7 @@ fn validate_directory_path(emitter: &mut Emitter<ConfigError>, path: &WithOrigin
}
}

#[cfg(release)]
#[cfg(not(test))]
fn validate_try_bind_address(emitter: &mut Emitter<ConfigError>, value: &WithOrigin<SocketAddr>) {
use std::net::TcpListener;

Expand Down
4 changes: 2 additions & 2 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module contains the sample configurations used for testing and benchmarking throughout Iroha.
use std::{collections::HashSet, str::FromStr};
use std::collections::HashSet;

use iroha_config::{base::toml::TomlSource, parameters::actual::Root as Config};
use iroha_crypto::{ExposedPrivateKey, KeyPair, PublicKey};
Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn get_trusted_peers(public_key: Option<&PublicKey>) -> HashSet<PeerId> {
),
]
.iter()
.map(|(a, k)| PeerId::new(a.parse().expect("Valid"), PublicKey::from_str(k).unwrap()))
.map(|(a, k)| PeerId::new(a.parse().expect("Valid"), k.parse().unwrap()))
.collect();
if let Some(pubkey) = public_key {
trusted_peers.insert(PeerId {
Expand Down
1 change: 0 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ assertables = { workspace = true }

tracing-subscriber = { workspace = true, features = ["fmt", "ansi"] }
tracing-flame = "0.2.0"
once_cell = { workspace = true }

trybuild = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl MeasurerUnit {
iroha_logger::error!(?error, "Failed to submit transaction");
}

nonce = nonce.checked_add(1).unwrap_or(nonzero!(1_u32));
nonce = nonce.checked_add(1).unwrap_or_else(|| nonzero!(1_u32));
thread::sleep(time::Duration::from_micros(interval_us_per_tx));
}
Err(mpsc::TryRecvError::Disconnected) => {
Expand Down
16 changes: 5 additions & 11 deletions client/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ fn account_registration_test(config: Config) -> Result<(), Error> {

fn asset_registration_test(config: Config) -> Result<(), Error> {
// #region register_asset_crates
use std::str::FromStr as _;

use iroha::{
client::Client,
crypto::KeyPair,
Expand All @@ -159,7 +157,7 @@ fn asset_registration_test(config: Config) -> Result<(), Error> {

// #region register_asset_create_asset
// Create an asset
let asset_def_id = AssetDefinitionId::from_str("time#looking_glass")
let asset_def_id = "time#looking_glass".parse::<AssetDefinitionId>()
.expect("Valid, because the string contains no whitespace, has a single '#' character and is not empty after");
// #endregion register_asset_create_asset

Expand Down Expand Up @@ -193,11 +191,9 @@ fn asset_registration_test(config: Config) -> Result<(), Error> {

fn asset_minting_test(config: Config) -> Result<(), Error> {
// #region mint_asset_crates
use std::str::FromStr;

use iroha::{
client::Client,
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, Mint},
data_model::prelude::{AccountId, AssetId, Mint},
};
// #endregion mint_asset_crates

Expand All @@ -206,7 +202,7 @@ fn asset_minting_test(config: Config) -> Result<(), Error> {

// Define the instances of an Asset and Account
// #region mint_asset_define_asset_account
let roses = AssetDefinitionId::from_str("rose#wonderland")
let roses = "rose#wonderland".parse()
.expect("Valid, because the string contains no whitespace, has a single '#' character and is not empty after");
let alice: AccountId = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland".parse()
.expect("Valid, because before @ is a valid public key and after @ is a valid name i.e. a string with no spaces or forbidden chars");
Expand Down Expand Up @@ -247,11 +243,9 @@ fn asset_minting_test(config: Config) -> Result<(), Error> {

fn asset_burning_test(config: Config) -> Result<(), Error> {
// #region burn_asset_crates
use std::str::FromStr;

use iroha::{
client::Client,
data_model::prelude::{AccountId, AssetDefinitionId, AssetId, Burn},
data_model::prelude::{AccountId, AssetId, Burn},
};
// #endregion burn_asset_crates

Expand All @@ -260,7 +254,7 @@ fn asset_burning_test(config: Config) -> Result<(), Error> {

// #region burn_asset_define_asset_account
// Define the instances of an Asset and Account
let roses = AssetDefinitionId::from_str("rose#wonderland")
let roses = "rose#wonderland".parse()
.expect("Valid, because the string contains no whitespace, has a single '#' character and is not empty after");
let alice: AccountId = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland".parse()
.expect("Valid, because before @ is a valid public key and after @ is a valid name i.e. a string with no spaces or forbidden chars");
Expand Down
6 changes: 2 additions & 4 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,13 +1101,11 @@ pub mod executor {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use iroha_primitives::small::SmallStr;
use test_samples::gen_account_in;

use super::*;
use crate::config::{BasicAuth, Config, WebLogin};
use crate::config::{BasicAuth, Config};

const LOGIN: &str = "mad_hatter";
const PASSWORD: &str = "ilovetea";
Expand Down Expand Up @@ -1163,7 +1161,7 @@ mod tests {
fn authorization_header() {
let client = Client::new(Config {
basic_auth: Some(BasicAuth {
web_login: WebLogin::from_str(LOGIN).expect("Failed to create valid `WebLogin`"),
web_login: LOGIN.parse().expect("Failed to create valid `WebLogin`"),
password: SmallStr::from_str(PASSWORD),
}),
..config_factory()
Expand Down
6 changes: 4 additions & 2 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ mod tests {

#[test]
fn web_login_ok() {
let _ok = WebLogin::from_str("alice").expect("input is valid");
let _ok: WebLogin = "alice".parse().expect("input is valid");
}

#[test]
fn web_login_bad() {
let _err = WebLogin::from_str("alice:wonderland").expect_err("input has `:`");
let _err = "alice:wonderland"
.parse::<WebLogin>()
.expect_err("input has `:`");
}

fn config_sample() -> toml::Table {
Expand Down
12 changes: 8 additions & 4 deletions client/src/http_default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Defaults for various items used in communication over http(s).
use std::{net::TcpStream, str::FromStr};
use std::net::TcpStream;

use attohttpc::{
body as atto_body, RequestBuilder as AttoHttpRequestBuilder, Response as AttoHttpResponse,
Expand All @@ -16,7 +16,8 @@ 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}"))
str.parse::<HeaderName>()
.wrap_err_with(|| format!("Failed to parse header name {str}"))
}

/// Default request builder implemented on top of `attohttpc` crate.
Expand Down Expand Up @@ -112,9 +113,12 @@ impl DefaultWebSocketRequestBuilder {
let builder = self.0?;
let mut request = builder
.uri_ref()
.ok_or(eyre!("Missing URI"))?
.ok_or_else(|| eyre!("Missing URI"))?
.into_client_request()?;
for (header, value) in builder.headers_ref().ok_or(eyre!("No headers found"))? {
for (header, value) in builder
.headers_ref()
.ok_or_else(|| eyre!("No headers found"))?
{
request.headers_mut().entry(header).or_insert(value.clone());
}
Ok(DefaultWebSocketStreamRequest(request))
Expand Down
Loading

0 comments on commit e1026a5

Please sign in to comment.