Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: cleaning up unused imports and variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberb committed Jan 19, 2024
1 parent fba8847 commit 98d77d5
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 65 deletions.
2 changes: 1 addition & 1 deletion crates/topos-p2p/src/tests/command/random_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn no_random_peer() {
.await
.expect("Unable to create p2p network");

let mut runtime = runtime.bootstrap().await.unwrap();
let runtime = runtime.bootstrap().await.unwrap();

spawn(runtime.run());

Expand Down
12 changes: 5 additions & 7 deletions crates/topos-tce-api/tests/grpc/certificate_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ use base64ct::{Base64, Encoding};
use rstest::rstest;
use std::sync::Arc;
use test_log::test;
use tokio_stream::Stream;
use topos_api::grpc::tce::v1::{GetLastPendingCertificatesRequest, LastPendingCertificate};
use topos_core::uci::Certificate;
use topos_tce_api::RuntimeEvent;
use topos_test_sdk::{
certificates::create_certificate_chain,
constants::{SOURCE_SUBNET_ID_1, TARGET_SUBNET_ID_1},
storage::{create_fullnode_store, create_validator_store, storage_client},
tce::public_api::{broadcast_stream, create_public_api, PublicApiContext},
tce::public_api::{broadcast_stream, create_public_api},
};

use topos_tce_storage::{types::CertificateDeliveredWithPositions, validator::ValidatorStore};
Expand All @@ -22,12 +20,12 @@ async fn fetch_latest_pending_certificates() {
let validator_store: Arc<ValidatorStore> =
create_validator_store(vec![], futures::future::ready(fullnode_store.clone())).await;

let (tx, rx): (
let (_, _): (
_,
tokio::sync::broadcast::Receiver<CertificateDeliveredWithPositions>,
) = tokio::sync::broadcast::channel(10);

let (mut api_context, _) = create_public_api(
let (api_context, _) = create_public_api(
storage_client(vec![]),
broadcast_stream(),
futures::future::ready(validator_store.clone()),
Expand Down Expand Up @@ -73,12 +71,12 @@ async fn fetch_latest_pending_certificates_with_conflicts() {
let validator_store: Arc<ValidatorStore> =
create_validator_store(vec![], futures::future::ready(fullnode_store.clone())).await;

let (tx, rx): (
let (_, _): (
_,
tokio::sync::broadcast::Receiver<CertificateDeliveredWithPositions>,
) = tokio::sync::broadcast::channel(10);

let (mut api_context, _) = create_public_api(
let (api_context, _) = create_public_api(
storage_client(vec![]),
broadcast_stream(),
futures::future::ready(validator_store.clone()),
Expand Down
8 changes: 4 additions & 4 deletions crates/topos-tce-broadcast/src/tests/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn can_start(#[future] create_validator_store: Arc<ValidatorStore>) {
.unwrap(),
);

let mut manager = TaskManager::new(
let manager = TaskManager::new(
message_receiver,
SubscriptionsView::default(),
event_sender,
Expand All @@ -60,21 +60,21 @@ async fn can_start(#[future] create_validator_store: Arc<ValidatorStore>) {
.take()
.expect("Failed to create certificate");

message_sender
let _ = message_sender
.send(crate::DoubleEchoCommand::Broadcast {
need_gossip: false,
cert: child.certificate.clone(),
})
.await;

message_sender
let _ = message_sender
.send(crate::DoubleEchoCommand::Broadcast {
need_gossip: false,
cert: parent.certificate.clone(),
})
.await;

message_sender
let _ = message_sender
.send(crate::DoubleEchoCommand::Broadcast {
need_gossip: false,
cert: parent.certificate.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/topos-tce-gatekeeper/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::future::IntoFuture;

use rstest::{fixture, rstest};
use rstest::fixture;
use test_log::test;
use tokio::spawn;
use topos_p2p::PeerId;
Expand Down
11 changes: 4 additions & 7 deletions crates/topos-tce/src/tests/api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::sync::Arc;

use libp2p::PeerId;
use prost::Message;
use rstest::rstest;
use test_log::test;
use tokio::sync::{mpsc, oneshot};
use topos_core::api::grpc::tce::v1::{double_echo_request, DoubleEchoRequest, Echo, Gossip, Ready};
use topos_crypto::{messages::MessageSigner, validator_id::ValidatorId};
use topos_crypto::messages::MessageSigner;
use topos_tce_storage::{store::WriteStore, types::PendingResult};
use topos_test_sdk::{
certificates::create_certificate_chain,
Expand All @@ -26,7 +23,7 @@ async fn handle_new_certificate(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, _) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate = certificates.pop().unwrap().certificate;

Expand All @@ -53,7 +50,7 @@ async fn handle_certificate_in_precedence_pool(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, _) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 2);
let certificate = certificates.pop().unwrap().certificate;

Expand All @@ -80,7 +77,7 @@ async fn handle_certificate_already_delivered(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, _) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate_delivered = certificates.pop().unwrap();

Expand Down
21 changes: 8 additions & 13 deletions crates/topos-tce/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use libp2p::PeerId;
use rstest::{fixture, rstest};
use std::{
collections::{HashMap, HashSet},
future::IntoFuture,
net::SocketAddr,
sync::Arc,
};
use std::{collections::HashSet, future::IntoFuture, sync::Arc};
use tce_transport::ProtocolEvents;
use tokio_stream::Stream;
use topos_tce_api::RuntimeEvent;
use topos_tce_gatekeeper::{Gatekeeper, GatekeeperClient};
use topos_tce_gatekeeper::Gatekeeper;

use tokio::sync::{broadcast, mpsc};
use topos_crypto::messages::MessageSigner;
Expand Down Expand Up @@ -104,12 +99,12 @@ pub async fn setup_test(
) {
let validator_store = create_validator_store.await;
let is_validator = false;
let mut message_signer = Arc::new(MessageSigner::new(&[5u8; 32]).unwrap());
let message_signer = Arc::new(MessageSigner::new(&[5u8; 32]).unwrap());
let validator_id = message_signer.public_address.into();

let (broadcast_sender, broadcast_receiver) = broadcast::channel(1);
let (broadcast_sender, _) = broadcast::channel(1);

let (tce_cli, tce_stream) = ReliableBroadcastClient::new(
let (tce_cli, _) = ReliableBroadcastClient::new(
ReliableBroadcastConfig {
tce_params: tce_transport::ReliableBroadcastParams::default(),
validator_id,
Expand All @@ -122,7 +117,7 @@ pub async fn setup_test(
.await;

let (shutdown_p2p, _) = mpsc::channel(1);
let (p2p_sender, mut p2p_receiver) = mpsc::channel(1);
let (p2p_sender, p2p_receiver) = mpsc::channel(1);
let grpc_over_p2p = GrpcOverP2P::new(p2p_sender.clone());
let network_client = NetworkClient {
retry_ttl: 10,
Expand All @@ -135,9 +130,9 @@ pub async fn setup_test(
let (api_context, _api_stream) = create_public_api.await;
let api_client = api_context.client;

let (gatekeeper_client, gatekeeper) = Gatekeeper::builder().into_future().await.unwrap();
let (gatekeeper_client, _) = Gatekeeper::builder().into_future().await.unwrap();

let (mut context, _) = AppContext::new(
let (context, _) = AppContext::new(
is_validator,
StorageClient::new(validator_store.clone()),
tce_cli,
Expand Down
8 changes: 4 additions & 4 deletions crates/topos-tce/src/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn handle_gossip(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, _) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate = certificates.pop().unwrap().certificate;

Expand All @@ -52,7 +52,7 @@ async fn handle_echo(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, message_signer) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate = certificates.pop().unwrap().certificate;
let validator_id: ValidatorId = message_signer.public_address.into();
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn handle_ready(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, message_signer) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate = certificates.pop().unwrap().certificate;
let validator_id: ValidatorId = message_signer.public_address.into();
Expand Down Expand Up @@ -110,7 +110,7 @@ async fn handle_already_delivered(
Arc<MessageSigner>,
),
) {
let (mut context, mut p2p_receiver, message_signer) = setup_test.await;
let (mut context, _, _) = setup_test.await;
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1);
let certificate_delivered = certificates.pop().unwrap();
let certificate = certificate_delivered.certificate.clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/topos-test-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod sequencer;
pub mod storage;
pub mod tce;

use rand::Rng;
use std::{
collections::HashSet,
net::SocketAddr,
Expand All @@ -17,7 +18,6 @@ use std::{
};

use lazy_static::lazy_static;
use rand::Rng;
use rstest::fixture;

lazy_static! {
Expand Down
8 changes: 1 addition & 7 deletions crates/topos-test-sdk/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use rand::Rng;
use rstest::fixture;
use std::path::PathBuf;
use std::sync::Arc;
use std::thread;
use std::{
path::PathBuf,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};

use topos_core::types::CertificateDelivered;
use topos_tce_storage::{
Expand Down
1 change: 0 additions & 1 deletion crates/topos-test-sdk/src/tce/gatekeeper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::error::Error;
use std::future::IntoFuture;

use libp2p::PeerId;
use tokio::spawn;
use tokio::task::JoinHandle;

Expand Down
2 changes: 1 addition & 1 deletion crates/topos-test-sdk/src/tce/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use topos_tce_synchronizer::SynchronizerError;
use topos_tce_synchronizer::SynchronizerEvent;

pub async fn create_synchronizer(
gatekeeper_client: GatekeeperClient,
_: GatekeeperClient,
network_client: NetworkClient,
store: Arc<ValidatorStore>,
) -> (
Expand Down
1 change: 0 additions & 1 deletion crates/topos/tests/cert_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use topos_core::{
},
uci::{Certificate, SubnetId, CERTIFICATE_ID_LENGTH, SUBNET_ID_LENGTH},
};
use topos_tce_transport::ReliableBroadcastParams;
use topos_test_sdk::{certificates::create_certificate_chains, tce::create_network};
use tracing::{debug, info, warn};

Expand Down
14 changes: 4 additions & 10 deletions crates/topos/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use assert_cmd::{assert, prelude::*};
use libp2p::swarm::dial_opts::DialOpts;
use libp2p::swarm::{DialError, ListenError, SwarmEvent};
use libp2p::{build_multiaddr, Multiaddr, PeerId, Swarm};
use predicates::prelude::*;
use assert_cmd::prelude::*;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::thread;
Expand All @@ -12,7 +8,6 @@ use tokio::fs::OpenOptions;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use toml::map::Map;
use toml::Value;
use topos::install_polygon_edge;
use topos_test_sdk::create_folder;

use crate::utils::setup_polygon_edge;
Expand Down Expand Up @@ -342,7 +337,6 @@ async fn command_node_up_with_old_config(
// Create config file
let node_up_home_env = tmp_home_dir.to_str().unwrap();
let node_edge_path_env = setup_polygon_edge(node_up_home_env).await;
let node_up_role_env = "validator";
let node_up_name_env = "test_node_up_old_config";
let node_up_subnet_env = "topos";

Expand Down Expand Up @@ -388,9 +382,9 @@ async fn command_node_up_with_old_config(
panic!("TCE configuration table malformed");
}

file.set_len(0).await;
file.seek(std::io::SeekFrom::Start(0)).await;
file.write_all(toml::to_string(&current)?.as_bytes()).await;
let _ = file.set_len(0).await;
let _ = file.seek(std::io::SeekFrom::Start(0)).await;
let _ = file.write_all(toml::to_string(&current)?.as_bytes()).await;

drop(file);

Expand Down
8 changes: 2 additions & 6 deletions crates/topos/tests/node.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
mod utils;

use std::{
path::PathBuf,
process::{Command, ExitStatus},
thread,
};
use std::{path::PathBuf, process::Command};

use assert_cmd::prelude::*;
use sysinfo::{Pid, PidExt, ProcessExt, Signal, System, SystemExt};
Expand Down Expand Up @@ -81,7 +77,7 @@ async fn command_node_up_sigterm() -> Result<(), Box<dyn std::error::Error>> {

let mut cmd = tokio::process::Command::from(cmd).spawn().unwrap();
let pid = cmd.id().unwrap();
let sigterm_wait = tokio::time::sleep(std::time::Duration::from_secs(10)).await;
let _ = tokio::time::sleep(std::time::Duration::from_secs(10)).await;

let s = System::new_all();
if let Some(process) = s.process(Pid::from_u32(pid)) {
Expand Down
7 changes: 6 additions & 1 deletion crates/topos/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use predicates::prelude::*;
use regex::Regex;
use std::path::PathBuf;
use std::process::Command;
use tempfile::tempdir;
use topos::install_polygon_edge;

// Have to allow dead_code because clippy doesn't recognize it is being used in the tests
#[cfg(test)]
#[allow(dead_code)]
pub fn sanitize_config_folder_path(cmd_out: &str) -> String {
// Sanitize the result here:
// When run locally, we get /Users/<username>/.config/topos
Expand All @@ -17,6 +18,8 @@ pub fn sanitize_config_folder_path(cmd_out: &str) -> String {
.to_string()
}

// Have to allow dead_code because clippy doesn't recognize it is being used in the tests
#[allow(dead_code)]
pub async fn setup_polygon_edge(path: &str) -> String {
let installation_path = std::env::current_dir().unwrap().join(path);
let binary_path = installation_path.join("polygon-edge");
Expand All @@ -37,6 +40,8 @@ pub async fn setup_polygon_edge(path: &str) -> String {
installation_path.to_str().unwrap().to_string()
}

// Have to allow dead_code because clippy doesn't recognize it is being used in the tests
#[allow(dead_code)]
pub async fn generate_polygon_edge_genesis_file(
polygon_edge_bin: &str,
home_path: &str,
Expand Down

0 comments on commit 98d77d5

Please sign in to comment.