Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make clippy happy #6666

Merged
merged 10 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ impl<Ext: RethCliExt> Commands<Ext> {

#[cfg(test)]
mod tests {
use clap::CommandFactory;

use crate::args::{utils::SUPPORTED_CHAINS, ColorMode};

use super::*;
use crate::args::ColorMode;
use clap::CommandFactory;

#[test]
fn parse_color_mode() {
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/commands/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
#[cfg(test)]
mod tests {
use super::*;
use crate::args::utils::SUPPORTED_CHAINS;
use reth_discv4::DEFAULT_DISCOVERY_PORT;
use std::{
net::{IpAddr, Ipv4Addr},
Expand Down
7 changes: 2 additions & 5 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,14 +1262,11 @@ mod tests {
blocks::BlockChainTestData, create_test_provider_factory_with_chain_spec,
TestExecutorFactory,
},
BlockWriter, BundleStateWithReceipts, ProviderFactory,
ProviderFactory,
};
use reth_revm::EvmProcessorFactory;
use reth_trie::StateRoot;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::HashMap;

fn setup_externals(
exec_res: Vec<BundleStateWithReceipts>,
Expand Down
9 changes: 4 additions & 5 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use reth_provider::{
use reth_rpc_types::engine::{
CancunPayloadFields, ExecutionPayload, PayloadStatus, PayloadStatusEnum, PayloadValidationError,
};

use reth_stages::{ControlFlow, Pipeline, PipelineError};
use reth_tasks::TaskSpawner;
use reth_tokio_util::EventListeners;
Expand Down Expand Up @@ -1896,8 +1895,8 @@ mod tests {
use reth_provider::{BlockWriter, ProviderFactory};
use reth_rpc_types::engine::{ForkchoiceState, ForkchoiceUpdated, PayloadStatus};
use reth_rpc_types_compat::engine::payload::try_block_to_payload_v1;
use reth_stages::{ExecOutput, PipelineError, StageError};
use std::{collections::VecDeque, sync::Arc, time::Duration};
use reth_stages::{ExecOutput, StageError};
use std::{collections::VecDeque, sync::Arc};
use tokio::sync::oneshot::error::TryRecvError;

// Pipeline error is propagated.
Expand Down Expand Up @@ -2353,10 +2352,10 @@ mod tests {

mod new_payload {
use super::*;
use reth_interfaces::test_utils::{generators, generators::random_block};
use reth_interfaces::test_utils::generators::random_block;
use reth_primitives::{
genesis::{Genesis, GenesisAllocator},
Hardfork, U256,
Hardfork,
};
use reth_provider::test_utils::blocks::BlockChainTestData;

Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/beacon/src/engine/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,16 @@ mod tests {
use reth_db::{mdbx::DatabaseEnv, test_utils::TempDatabase};
use reth_interfaces::{p2p::either::EitherDownloader, test_utils::TestFullBlockClient};
use reth_primitives::{
constants::ETHEREUM_BLOCK_GAS_LIMIT, stage::StageCheckpoint, BlockBody, ChainSpec,
ChainSpecBuilder, Header, SealedHeader, MAINNET,
constants::ETHEREUM_BLOCK_GAS_LIMIT, stage::StageCheckpoint, BlockBody, ChainSpecBuilder,
Header, SealedHeader, MAINNET,
};
use reth_provider::{
test_utils::{create_test_provider_factory_with_chain_spec, TestExecutorFactory},
BundleStateWithReceipts,
};
use reth_stages::{test_utils::TestStages, ExecOutput, StageError};
use reth_tasks::TokioTaskExecutor;
use std::{collections::VecDeque, future::poll_fn, ops::Range, sync::Arc};
use std::{collections::VecDeque, future::poll_fn, ops::Range};
use tokio::sync::watch;

struct TestPipelineBuilder {
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/common/src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn ommer_reward(
#[cfg(test)]
mod tests {
use super::*;
use reth_primitives::{MAINNET, U256};
use reth_primitives::MAINNET;

#[test]
fn calc_base_block_reward() {
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ mod tests {
test_utils::generators::{self, Rng},
};
use reth_primitives::{
constants::eip4844::DATA_GAS_PER_BLOB, hex_literal::hex, proofs, Account, Address,
BlockBody, BlockHash, BlockHashOrNumber, Bytes, ChainSpecBuilder, Header, Signature,
TransactionKind, TransactionSigned, Withdrawal, Withdrawals, MAINNET, U256,
hex_literal::hex, proofs, Account, Address, BlockBody, BlockHash, BlockHashOrNumber, Bytes,
ChainSpecBuilder, Signature, TransactionKind, TransactionSigned, Withdrawal, Withdrawals,
MAINNET, U256,
};
use std::ops::RangeBounds;

Expand Down
5 changes: 1 addition & 4 deletions crates/interfaces/src/test_utils/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ pub fn random_log<R: Rng>(rng: &mut R, address: Option<Address>, topics_count: O
#[cfg(test)]
mod tests {
use super::*;
use reth_primitives::{
hex, public_key_to_address, AccessList, Signature, TransactionKind, TxEip1559,
};
use secp256k1::KeyPair;
use reth_primitives::{hex, public_key_to_address, AccessList, Signature, TxEip1559};
use std::str::FromStr;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/net/common/src/bandwidth_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod tests {
use super::*;
use tokio::{
io::{duplex, AsyncReadExt, AsyncWriteExt, DuplexStream},
net::{TcpListener, TcpStream},
net::TcpListener,
};

async fn duplex_stream_ping_pong(
Expand Down
2 changes: 1 addition & 1 deletion crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ mod tests {
use alloy_rlp::{Decodable, Encodable};
use rand::{thread_rng, Rng};
use reth_primitives::{hex, mainnet_nodes, ForkHash};
use std::{future::poll_fn, net::Ipv4Addr};
use std::future::poll_fn;

#[tokio::test]
async fn test_configured_enr_forkid_entry() {
Expand Down
2 changes: 1 addition & 1 deletion crates/net/discv4/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub fn rng_message(rng: &mut impl RngCore) -> Message {
mod tests {
use super::*;
use crate::Discv4Event;
use std::net::{IpAddr, Ipv4Addr};
use std::net::Ipv4Addr;

/// This test creates two local UDP sockets. The mocked discovery service responds to specific
/// messages and we check the actual service receives answers
Expand Down
1 change: 0 additions & 1 deletion crates/net/dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ mod tests {
use reth_primitives::{Hardfork, MAINNET};
use secp256k1::rand::thread_rng;
use std::{future::poll_fn, net::Ipv4Addr};
use tokio_stream::StreamExt;

#[tokio::test]
async fn test_start_root_sync() {
Expand Down
1 change: 0 additions & 1 deletion crates/net/dns/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ fn ensure_strip_key(input: &mut &str, key: &str, err: &'static str) -> ParseEntr
#[cfg(test)]
mod tests {
use super::*;
use secp256k1::SecretKey;

#[test]
fn parse_root_entry() {
Expand Down
3 changes: 1 addition & 2 deletions crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,11 @@ mod tests {
test_utils::{generate_bodies, TestBodiesClient},
};
use assert_matches::assert_matches;
use futures_util::stream::StreamExt;
use reth_db::test_utils::create_test_rw_db;
use reth_interfaces::test_utils::{generators, generators::random_block_range, TestConsensus};
use reth_primitives::{BlockBody, B256, MAINNET};
use reth_provider::ProviderFactory;
use std::{collections::HashMap, sync::Arc};
use std::collections::HashMap;

// Check that the blocks are emitted in order of block number, not in order of
// first-downloaded
Expand Down
7 changes: 1 addition & 6 deletions crates/net/downloaders/src/bodies/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,7 @@ mod tests {
bodies::test_utils::zip_blocks,
test_utils::{generate_bodies, TestBodiesClient},
};
use reth_interfaces::{
p2p::bodies::response::BlockResponse,
test_utils::{generators, generators::random_header_range, TestConsensus},
};
use reth_primitives::B256;
use std::sync::Arc;
use reth_interfaces::test_utils::{generators, generators::random_header_range, TestConsensus};

/// Check if future returns empty bodies without dispathing any requests.
#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_interfaces::p2p::{
use reth_primitives::{
BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, PeerId, B256,
};
use std::{self, collections::HashMap, path::Path};
use std::{collections::HashMap, path::Path};
use thiserror::Error;
use tokio::{fs::File, io::AsyncReadExt};
use tokio_stream::StreamExt;
Expand Down
1 change: 0 additions & 1 deletion crates/net/downloaders/src/headers/reverse_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,6 @@ mod tests {
use crate::headers::test_utils::child_header;
use assert_matches::assert_matches;
use reth_interfaces::test_utils::{TestConsensus, TestHeadersClient};
use reth_primitives::SealedHeader;

/// Tests that `replace_number` works the same way as Option::replace
#[test]
Expand Down
1 change: 0 additions & 1 deletion crates/net/ecies/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use secp256k1::{
};
use sha2::Sha256;
use sha3::Keccak256;
use std::convert::TryFrom;

const PROTOCOL_VERSION: usize = 4;

Expand Down
2 changes: 1 addition & 1 deletion crates/net/ecies/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
mod tests {
use super::*;
use crate::util::pk2id;
use secp256k1::{rand, SECP256K1};
use secp256k1::SECP256K1;
use tokio::net::{TcpListener, TcpStream};

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion crates/net/eth-wire/src/multiplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ mod tests {
connect_passthrough, eth_handshake, eth_hello,
proto::{test_hello, TestProtoMessage},
},
UnauthedEthStream, UnauthedP2PStream,
UnauthedP2PStream,
};
use tokio::{net::TcpListener, sync::oneshot};
use tokio_util::codec::Decoder;
Expand Down
4 changes: 1 addition & 3 deletions crates/net/eth-wire/src/p2pstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,7 @@ impl Decodable for ProtocolVersion {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
capability::SharedCapability, test_utils::eth_hello, DisconnectReason, EthVersion,
};
use crate::{capability::SharedCapability, test_utils::eth_hello, EthVersion};
use tokio::net::{TcpListener, TcpStream};
use tokio_util::codec::Decoder;

Expand Down
6 changes: 1 addition & 5 deletions crates/net/eth-wire/src/types/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use reth_primitives::{Block, Bytes, TransactionSigned, TxHash, B256, U128};
use std::{collections::HashMap, mem, sync::Arc};

#[cfg(feature = "arbitrary")]
use proptest::prelude::*;

#[cfg(feature = "arbitrary")]
use proptest::{arbitrary::Arbitrary, collection::vec};
use proptest::{collection::vec, prelude::*};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -664,7 +661,6 @@ impl FromIterator<(TxHash, Option<(u8, usize)>)> for RequestTxHashes {
#[cfg(test)]
mod tests {
use super::*;
use alloy_rlp::{Decodable, Encodable};
use bytes::BytesMut;
use reth_primitives::hex;
use std::str::FromStr;
Expand Down
1 change: 0 additions & 1 deletion crates/net/eth-wire/src/types/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ impl From<EthVersion> for &'static str {
#[cfg(test)]
mod tests {
use super::{EthVersion, ParseVersionError};
use std::{convert::TryFrom, string::ToString};

#[test]
fn test_eth_version_try_from_str() {
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::hash::BuildHasher;
use derive_more::{Deref, DerefMut};
use itertools::Itertools;
use linked_hash_set::LinkedHashSet;
use schnellru::{self, ByLength, Limiter, RandomState, Unlimited};
use schnellru::{ByLength, Limiter, RandomState, Unlimited};
use std::{borrow::Borrow, fmt, hash::Hash, num::NonZeroUsize};

/// A minimal LRU cache based on a `LinkedHashSet` with limited capacity.
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub(crate) enum BlockResponseOutcome {
mod tests {
use super::*;
use crate::{peers::PeersManager, PeersConfig};
use reth_primitives::{SealedHeader, B256, B512};
use reth_primitives::{SealedHeader, B512};
use std::future::poll_fn;

#[tokio::test(flavor = "multi_thread")]
Expand Down
4 changes: 1 addition & 3 deletions crates/net/network/src/session/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ fn calculate_new_timeout(current_timeout: Duration, estimated_rtt: Duration) ->
mod tests {
use super::*;
use crate::session::{
config::{INITIAL_REQUEST_TIMEOUT, PROTOCOL_BREACH_REQUEST_TIMEOUT},
handle::PendingSessionEvent,
config::PROTOCOL_BREACH_REQUEST_TIMEOUT, handle::PendingSessionEvent,
start_pending_incoming_session,
};
use reth_ecies::{stream::ECIESStream, util::pk2id};
Expand All @@ -773,7 +772,6 @@ mod tests {
use reth_net_common::bandwidth_meter::{BandwidthMeter, MeteredStream};
use reth_primitives::{ForkFilter, Hardfork, MAINNET};
use secp256k1::{SecretKey, SECP256K1};
use std::time::Duration;
use tokio::{
net::{TcpListener, TcpStream},
sync::mpsc,
Expand Down
7 changes: 3 additions & 4 deletions crates/net/network/src/transactions/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ impl FilterAnnouncement for EthAnnouncementFilter {
let NewPooledTransactionHashes68 { mut hashes, mut types, mut sizes } = msg;

debug_assert!(
hashes.len() == types.len() && hashes.len() == sizes.len(), "`%hashes`, `%types` and `%sizes` should all be the same length, decoding of `NewPooledTransactionHashes68` should handle this,
`%hashes`: {hashes:?},
`%types`: {types:?},
hashes.len() == types.len() && hashes.len() == sizes.len(), "`%hashes`, `%types` and `%sizes` should all be the same length, decoding of `NewPooledTransactionHashes68` should handle this,
`%hashes`: {hashes:?},
`%types`: {types:?},
`%sizes: {sizes:?}`"
);

Expand Down Expand Up @@ -332,7 +332,6 @@ impl FilterAnnouncement for EthAnnouncementFilter {
#[cfg(test)]
mod test {
use super::*;
use reth_eth_wire::MAX_MESSAGE_SIZE;
use reth_primitives::B256;
use std::str::FromStr;

Expand Down
17 changes: 8 additions & 9 deletions crates/net/network/tests/it/txgossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ async fn test_4844_tx_gossip_penalization() {
let network_handle = peer0.network();

let peer0_reputation_before =
peer1.peer_handle().peer_by_id(peer0.peer_id().clone()).await.unwrap().reputation();
peer1.peer_handle().peer_by_id(*peer0.peer_id()).await.unwrap().reputation();

// sends txs directly to peer1
network_handle.send_transactions(peer1.peer_id().clone(), signed_txs);
network_handle.send_transactions(*peer1.peer_id(), signed_txs);

let received = peer1_tx_listener.recv().await.unwrap();

let peer0_reputation_after =
peer1.peer_handle().peer_by_id(peer0.peer_id().clone()).await.unwrap().reputation();
peer1.peer_handle().peer_by_id(*peer0.peer_id()).await.unwrap().reputation();
assert_ne!(peer0_reputation_before, peer0_reputation_after);
assert_eq!(received, txs[1].transaction().hash);

Expand Down Expand Up @@ -130,24 +130,23 @@ async fn test_sending_invalid_transactions() {
input: Default::default(),
};
let tx = TransactionSigned::from_transaction_and_signature(tx.into(), Default::default());
peer0.network().send_transactions(peer1.peer_id().clone(), vec![Arc::new(tx)]);
peer0.network().send_transactions(*peer1.peer_id(), vec![Arc::new(tx)]);
}

// await disconnect for bad tx spam
while let Some(ev) = peer1_events.next().await {
if let Some(ev) = peer1_events.next().await {
match ev {
NetworkEvent::SessionClosed { peer_id, .. } => {
assert_eq!(peer_id, *peer0.peer_id());
break
}
NetworkEvent::SessionEstablished { .. } => {
panic!("unexpected event")
panic!("unexpected SessionEstablished event")
}
NetworkEvent::PeerAdded(_) => {
panic!("unexpected event")
panic!("unexpected PeerAdded event")
}
NetworkEvent::PeerRemoved(_) => {
panic!("unexpected event")
panic!("unexpected PeerRemoved event")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/node-core/src/args/payload_builder_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TypedValueParser for ExtradataValueParser {
#[cfg(test)]
mod tests {
use super::*;
use clap::{Args, Parser};
use clap::Parser;

/// A helper type to parse Args more easily
#[derive(Parser)]
Expand Down
Loading
Loading