From 2171f6c69ecb222a649afc4b088dbcbfe7eef5b1 Mon Sep 17 00:00:00 2001 From: al8n Date: Thu, 22 Dec 2022 01:57:05 +1300 Subject: [PATCH] add discv5 stuff in test --- waku-bindings/src/node/mod.rs | 5 +++++ waku-bindings/tests/node.rs | 19 ++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/waku-bindings/src/node/mod.rs b/waku-bindings/src/node/mod.rs index 3559a6f..1af00fc 100644 --- a/waku-bindings/src/node/mod.rs +++ b/waku-bindings/src/node/mod.rs @@ -119,6 +119,11 @@ impl WakuNodeHandle { stop_node() } + /// Stops the DiscoveryV5 service + pub fn discv5_stop(&self) -> Result { + discv5::waku_discv5_stop() + } + /// Dial peer using a multiaddress /// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`] /// If the function execution takes longer than `timeout` value, the execution will be canceled and an error returned. diff --git a/waku-bindings/tests/node.rs b/waku-bindings/tests/node.rs index cc664cc..9b8c816 100644 --- a/waku-bindings/tests/node.rs +++ b/waku-bindings/tests/node.rs @@ -34,6 +34,9 @@ pub fn main() -> Result<(), String> { discv5_bootstrap_nodes: Vec::new(), }; let node = waku_new(Some(config))?; + let result = node.discv5_start()?; + println!("Discv5 started: {}", result); + let node = node.start()?; println!("Node peer id: {}", node.peer_id()?); @@ -52,7 +55,7 @@ pub fn main() -> Result<(), String> { let ssk = Aes256Gcm::generate_key(&mut thread_rng()); let content = "Hi from 🦀!"; - let content_callback = content.clone(); + let content_callback = content; waku_set_event_callback(move |signal| match signal.event() { Event::WakuMessage(message) => { @@ -111,8 +114,7 @@ pub fn main() -> Result<(), String> { .unwrap() .iter() .map(|peer| peer.peer_id()) - .filter(|id| id.as_str() != node.peer_id().unwrap().as_str()) - .next() + .find(|id| id.as_str() != node.peer_id().unwrap().as_str()) .unwrap() .clone(); @@ -127,14 +129,7 @@ pub fn main() -> Result<(), String> { None, )?; node.lightpush_publish_encrypt_symmetric(&message, None, peer_id.clone(), &ssk, None, None)?; - node.lightpush_publish_encrypt_symmetric( - &message, - None, - peer_id.clone(), - &ssk, - Some(&sk), - None, - )?; + node.lightpush_publish_encrypt_symmetric(&message, None, peer_id, &ssk, Some(&sk), None)?; for node_data in node.peers()? { if node_data.peer_id() != &node.peer_id()? { @@ -143,6 +138,8 @@ pub fn main() -> Result<(), String> { } std::thread::sleep(Duration::from_secs(2)); + let result = node.discv5_stop()?; + assert!(result, "Discv5 should be stopped"); node.stop()?; Ok(()) }