Skip to content

Commit

Permalink
split exchange tests, cleanup names and includes
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Oct 5, 2023
1 parent 63b4b65 commit 5ddcd67
Show file tree
Hide file tree
Showing 3 changed files with 553 additions and 541 deletions.
44 changes: 43 additions & 1 deletion node/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use celestia_types::test_utils::ExtendedHeaderGenerator;

use crate::store::InMemoryStore;
use libp2p::{
core::{muxing::StreamMuxerBox, transport::Boxed, upgrade::Version},
identity::{self, Keypair},
noise, tcp, yamux, PeerId, Transport,
};

use crate::{node::NodeConfig, store::InMemoryStore};

pub fn gen_filled_store(amount: u64) -> (InMemoryStore, ExtendedHeaderGenerator) {
let s = InMemoryStore::new();
Expand All @@ -15,3 +21,39 @@ pub fn gen_filled_store(amount: u64) -> (InMemoryStore, ExtendedHeaderGenerator)

(s, gen)
}

fn tcp_transport(local_keypair: &Keypair) -> Boxed<(PeerId, StreamMuxerBox)> {
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(local_keypair).unwrap())
.multiplex(yamux::Config::default())
.boxed()
}

// helpers to use with struct update syntax to avoid spelling out all the details
pub fn test_node_config() -> NodeConfig<InMemoryStore> {
let node_keypair = identity::Keypair::generate_ed25519();
NodeConfig {
network_id: "private".to_string(),
p2p_transport: tcp_transport(&node_keypair),
p2p_local_keypair: node_keypair,
p2p_bootstrap_peers: vec![],
p2p_listen_on: vec![],
store: InMemoryStore::new(),
}
}

pub fn listening_test_node_config() -> NodeConfig<InMemoryStore> {
NodeConfig {
p2p_listen_on: vec!["/ip4/0.0.0.0/tcp/0".parse().unwrap()],
..test_node_config()
}
}

pub fn test_node_config_with_keypair(keypair: Keypair) -> NodeConfig<InMemoryStore> {
NodeConfig {
p2p_transport: tcp_transport(&keypair),
p2p_local_keypair: keypair,
..test_node_config()
}
}
Loading

0 comments on commit 5ddcd67

Please sign in to comment.