mirror of
https://github.com/waku-org/waku-rust-bindings.git
synced 2025-02-19 18:08:34 +00:00
chore: use rust node address instead of fleet node in tests
This commit is contained in:
parent
79b8428bb5
commit
ac96b834a0
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
// std
|
// std
|
||||||
// crates
|
// crates
|
||||||
use multiaddr::Multiaddr;
|
|
||||||
use secp256k1::SecretKey;
|
use secp256k1::SecretKey;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use smart_default::SmartDefault;
|
use smart_default::SmartDefault;
|
||||||
|
@ -34,7 +34,7 @@ pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<*mut c_void> {
|
|||||||
out
|
out
|
||||||
};
|
};
|
||||||
|
|
||||||
return if !error.is_empty() {
|
if !error.is_empty() {
|
||||||
Err(error)
|
Err(error)
|
||||||
} else {
|
} else {
|
||||||
Ok(node_ptr)
|
Ok(node_ptr)
|
||||||
@ -100,7 +100,7 @@ pub fn waku_listen_addresses(ctx: *mut c_void) -> Result<Vec<Multiaddr>> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::waku_new;
|
use super::waku_new;
|
||||||
use crate::node::management::{waku_start, waku_stop, waku_listen_addresses, waku_version};
|
use crate::node::management::{waku_listen_addresses, waku_start, waku_stop, waku_version};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -8,7 +8,7 @@ use libc::*;
|
|||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
// internal
|
// internal
|
||||||
use crate::general::Result;
|
use crate::general::Result;
|
||||||
use crate::utils::{get_trampoline, handle_json_response, handle_no_response, handle_response};
|
use crate::utils::{get_trampoline, handle_no_response};
|
||||||
|
|
||||||
/// Dial peer using a multiaddress
|
/// Dial peer using a multiaddress
|
||||||
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
|
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
|
||||||
|
@ -7,7 +7,7 @@ use std::time::Duration;
|
|||||||
use libc::*;
|
use libc::*;
|
||||||
// internal
|
// internal
|
||||||
use crate::general::{Encoding, MessageId, Result, WakuContentTopic, WakuMessage};
|
use crate::general::{Encoding, MessageId, Result, WakuContentTopic, WakuMessage};
|
||||||
use crate::utils::{get_trampoline, handle_json_response, handle_no_response, handle_response};
|
use crate::utils::{get_trampoline, handle_no_response, handle_response};
|
||||||
|
|
||||||
/// Create a content topic according to [RFC 23](https://rfc.vac.dev/spec/23/)
|
/// Create a content topic according to [RFC 23](https://rfc.vac.dev/spec/23/)
|
||||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding)
|
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use multiaddr::Multiaddr;
|
|
||||||
use secp256k1::SecretKey;
|
use secp256k1::SecretKey;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -6,25 +5,20 @@ use std::time::{Duration, SystemTime};
|
|||||||
use std::{collections::HashSet, str::from_utf8};
|
use std::{collections::HashSet, str::from_utf8};
|
||||||
use tokio::sync::broadcast::{self, Sender};
|
use tokio::sync::broadcast::{self, Sender};
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
|
use tokio::time::sleep;
|
||||||
use waku_bindings::{
|
use waku_bindings::{
|
||||||
waku_new, Encoding, Event, MessageId, WakuContentTopic, WakuMessage, WakuNodeConfig,
|
waku_new, Encoding, Event, MessageId, WakuContentTopic, WakuMessage, WakuNodeConfig,
|
||||||
WakuNodeHandle,
|
WakuNodeHandle,
|
||||||
};
|
};
|
||||||
const ECHO_TIMEOUT: u64 = 10;
|
const ECHO_TIMEOUT: u64 = 10;
|
||||||
const ECHO_MESSAGE: &str = "Hi from 🦀!";
|
const ECHO_MESSAGE: &str = "Hi from 🦀!";
|
||||||
|
|
||||||
const TEST_PUBSUBTOPIC: &str = "test";
|
const TEST_PUBSUBTOPIC: &str = "test";
|
||||||
const NODES: &[&str] =
|
|
||||||
&["/dns4/node-01.do-ams3.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D"];
|
|
||||||
|
|
||||||
fn try_publish_relay_messages(
|
fn try_publish_relay_messages(
|
||||||
node: &WakuNodeHandle,
|
node: &WakuNodeHandle,
|
||||||
msg: &WakuMessage,
|
msg: &WakuMessage,
|
||||||
) -> Result<HashSet<MessageId>, String> {
|
) -> Result<HashSet<MessageId>, String> {
|
||||||
let topic = TEST_PUBSUBTOPIC.to_string();
|
let topic = TEST_PUBSUBTOPIC.to_string();
|
||||||
node.relay_publish_message(msg, &topic, None)?;
|
|
||||||
node.relay_publish_message(msg, &topic, None)?;
|
|
||||||
|
|
||||||
Ok(HashSet::from([
|
Ok(HashSet::from([
|
||||||
node.relay_publish_message(msg, &topic, None)?
|
node.relay_publish_message(msg, &topic, None)?
|
||||||
]))
|
]))
|
||||||
@ -53,7 +47,8 @@ fn set_callback(node: &WakuNodeHandle, tx: Sender<Response>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn test_echo_messages(
|
async fn test_echo_messages(
|
||||||
node: &WakuNodeHandle,
|
node1: &WakuNodeHandle,
|
||||||
|
node2: &WakuNodeHandle,
|
||||||
content: &'static str,
|
content: &'static str,
|
||||||
content_topic: WakuContentTopic,
|
content_topic: WakuContentTopic,
|
||||||
) {
|
) {
|
||||||
@ -71,10 +66,12 @@ async fn test_echo_messages(
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (tx, mut rx) = broadcast::channel(1);
|
node1.set_event_callback(move |_event| {});
|
||||||
set_callback(node, tx);
|
|
||||||
|
|
||||||
let mut ids = try_publish_relay_messages(node, &message).expect("send relay messages");
|
let (tx, mut rx) = broadcast::channel(1);
|
||||||
|
set_callback(node2, tx);
|
||||||
|
|
||||||
|
let mut ids = try_publish_relay_messages(node1, &message).expect("send relay messages");
|
||||||
|
|
||||||
while let Ok(res) = rx.recv().await {
|
while let Ok(res) = rx.recv().await {
|
||||||
if ids.take(&res.id).is_some() {
|
if ids.take(&res.id).is_some() {
|
||||||
@ -91,27 +88,28 @@ async fn test_echo_messages(
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn default_echo() -> Result<(), String> {
|
async fn default_echo() -> Result<(), String> {
|
||||||
let config = WakuNodeConfig {
|
let node1 = waku_new(Some(WakuNodeConfig {
|
||||||
node_key: Some(
|
port: Some(60010),
|
||||||
SecretKey::from_str("05f381866cc21f6c1e2e80e07fa732008e36d942dce3206ad6dcd6793c98d609")
|
|
||||||
.unwrap(),
|
|
||||||
),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
}))?;
|
||||||
|
let node2 = waku_new(Some(WakuNodeConfig {
|
||||||
|
port: Some(60020),
|
||||||
|
..Default::default()
|
||||||
|
}))?;
|
||||||
|
|
||||||
let node = waku_new(Some(config))?;
|
node1.start()?;
|
||||||
|
node2.start()?;
|
||||||
|
|
||||||
node.start()?;
|
let addresses1 = node1.listen_addresses()?;
|
||||||
|
node2.connect(&addresses1[0], None)?;
|
||||||
|
|
||||||
for node_address in NODES {
|
|
||||||
let address: Multiaddr = node_address.parse().unwrap();
|
|
||||||
node.connect(&address, None)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// subscribe to default channel
|
|
||||||
let topic = TEST_PUBSUBTOPIC.to_string();
|
let topic = TEST_PUBSUBTOPIC.to_string();
|
||||||
|
|
||||||
node.relay_subscribe(&topic)?;
|
node1.relay_subscribe(&topic)?;
|
||||||
|
node2.relay_subscribe(&topic)?;
|
||||||
|
|
||||||
|
// Wait for mesh to form
|
||||||
|
sleep(Duration::from_secs(5)).await;
|
||||||
|
|
||||||
let content_topic = WakuContentTopic::new("toychat", "2", "huilong", Encoding::Proto);
|
let content_topic = WakuContentTopic::new("toychat", "2", "huilong", Encoding::Proto);
|
||||||
|
|
||||||
@ -121,12 +119,15 @@ async fn default_echo() -> Result<(), String> {
|
|||||||
// Send and receive messages. Waits until all messages received.
|
// Send and receive messages. Waits until all messages received.
|
||||||
let got_all = tokio::select! {
|
let got_all = tokio::select! {
|
||||||
_ = sleep => false,
|
_ = sleep => false,
|
||||||
_ = test_echo_messages(&node, ECHO_MESSAGE, content_topic) => true,
|
_ = test_echo_messages(&node1, &node2, ECHO_MESSAGE, content_topic) => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(got_all);
|
assert!(got_all);
|
||||||
|
|
||||||
node.stop()?;
|
|
||||||
|
node2.stop()?;
|
||||||
|
node1.stop()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user