Skip to content

Commit

Permalink
Move fake Sync protocol back to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kettlebell committed Nov 25, 2022
1 parent 0be19cb commit 6ad53a0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
2 changes: 0 additions & 2 deletions spectrum-network/src/protocol_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use std::pin::Pin;
use std::task::{Context, Poll};

pub mod codec;
#[cfg(feature = "integration_tests")]
pub mod fake_sync;
pub mod sync;
pub mod versioning;

Expand Down
3 changes: 1 addition & 2 deletions spectrum-network/src/protocol_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ pub mod combinators;
pub mod handshake;
mod message;
pub(crate) mod substream;
pub(crate) mod supported_protocol_vers;
pub use supported_protocol_vers::GetSupportedProtocolVer;
pub mod supported_protocol_vers;

use crate::protocol::ProtocolSpec;
use crate::protocol_upgrade::message::{Approve, APPROVE_SIZE};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use std::{

use libp2p::core::upgrade;

#[cfg(feature = "integration_tests")]
use crate::protocol_handler::fake_sync::FakeSyncSpec;
use crate::{
protocol::SYNC_PROTOCOL_ID,
protocol_handler::sync::message::SyncSpec,
Expand Down Expand Up @@ -40,13 +38,6 @@ impl GetSupportedProtocolId for SyncSpec {
}
}

#[cfg(feature = "integration_tests")]
impl GetSupportedProtocolId for FakeSyncSpec {
fn get_supported_id() -> SupportedProtocolId {
SupportedProtocolId(SYNC_PROTOCOL_ID)
}
}

/// A B-tree mapping from `SupportedProtocolVer` to `T`. Keys are ordered from highest to lowest.
/// Once created, the mapping itself cannot be altered, but the mapped values can be mutated.
#[derive(Debug, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use std::{
task::{Context, Poll},
};

use crate::{
use derive_more::Display;
use futures::{stream::FuturesOrdered, Future, Stream};
use libp2p::PeerId;
use serde::{Deserialize, Serialize};
use spectrum_network::{
peer_manager::Peers,
protocol::SYNC_PROTOCOL_ID,
protocol_handler::{
Expand All @@ -20,10 +24,6 @@ use crate::{
protocol_upgrade::supported_protocol_vers::{GetSupportedProtocolId, SupportedProtocolId},
types::{ProtocolId, ProtocolVer},
};
use derive_more::Display;
use futures::{stream::FuturesOrdered, Future, Stream};
use libp2p::PeerId;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum FakeSyncMessage {
Expand Down Expand Up @@ -52,7 +52,13 @@ impl FakeSyncSpec {
}
}

impl crate::protocol_handler::ProtocolSpec for FakeSyncSpec {
impl GetSupportedProtocolId for FakeSyncSpec {
fn get_supported_id() -> SupportedProtocolId {
SyncSpec::get_supported_id()
}
}

impl spectrum_network::protocol_handler::ProtocolSpec for FakeSyncSpec {
type THandshake = SyncHandshake;
type TMessage = FakeSyncMessage;
}
Expand Down Expand Up @@ -182,7 +188,7 @@ where
fn inject_protocol_enabled(
&mut self,
peer_id: PeerId,
_handshake: Option<<Self::TProto as crate::protocol_handler::ProtocolSpec>::THandshake>,
_handshake: Option<<Self::TProto as spectrum_network::protocol_handler::ProtocolSpec>::THandshake>,
) {
self.send_fake_msg(peer_id);
}
Expand Down
6 changes: 3 additions & 3 deletions spectrum-network/tests/integration_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, time::Duration};

mod fake_sync;
use crate::integration_tests::fake_sync::{FakeSyncBehaviour, FakeSyncMessage, FakeSyncMessageV1};
use futures::{
channel::{mpsc, oneshot},
StreamExt,
Expand All @@ -16,14 +17,13 @@ use spectrum_network::{
protocol::{ProtocolConfig, ProtocolSpec, SYNC_PROTOCOL_ID},
protocol_api::ProtocolMailbox,
protocol_handler::{
fake_sync::{FakeSyncBehaviour, FakeSyncMessage, FakeSyncMessageV1},
sync::{
message::{SyncMessage, SyncMessageV1, SyncSpec},
NodeStatus, SyncBehaviour,
},
MalformedMessage, ProtocolBehaviour, ProtocolHandler, ProtocolHandlerError,
},
protocol_upgrade::GetSupportedProtocolVer,
protocol_upgrade::supported_protocol_vers::GetSupportedProtocolVer,
types::{ProtocolId, ProtocolVer, Reputation},
};

Expand Down
2 changes: 1 addition & 1 deletion spectrum-network/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use spectrum_network::protocol_api::ProtocolMailbox;
use spectrum_network::protocol_handler::sync::message::SyncSpec;
use spectrum_network::protocol_handler::sync::{NodeStatus, SyncBehaviour};
use spectrum_network::protocol_handler::ProtocolHandler;
use spectrum_network::protocol_upgrade::GetSupportedProtocolVer;
use spectrum_network::protocol_upgrade::supported_protocol_vers::GetSupportedProtocolVer;
use spectrum_network::types::Reputation;
use std::collections::HashMap;
use std::{
Expand Down
4 changes: 2 additions & 2 deletions spectrum-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use spectrum_network::peer_manager::data::PeerDestination;
use spectrum_network::peer_manager::peers_state::PeerRepo;
use spectrum_network::peer_manager::{NetworkingConfig, PeerManager, PeerManagerConfig};
use spectrum_network::protocol::{ProtocolConfig, ProtocolSpec, SYNC_PROTOCOL_ID};
use spectrum_network::protocol_handler::sync::message::{SyncMessage, SyncMessageV1, SyncSpec};
use spectrum_network::protocol_handler::sync::message::SyncSpec;
use spectrum_network::protocol_handler::sync::{NodeStatus, SyncBehaviour};
use spectrum_network::protocol_handler::ProtocolHandler;
use spectrum_network::protocol_upgrade::GetSupportedProtocolVer;
use spectrum_network::protocol_upgrade::supported_protocol_vers::GetSupportedProtocolVer;
use spectrum_network::types::Reputation;
use std::time::Duration;

Expand Down

0 comments on commit 6ad53a0

Please sign in to comment.