chore: use rust node address instead of fleet node in tests

This commit is contained in:
Richard Ramos 2024-02-21 14:07:42 -04:00
parent 79b8428bb5
commit ac96b834a0
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
5 changed files with 37 additions and 37 deletions

View File

@ -2,7 +2,6 @@
// std
// crates
use multiaddr::Multiaddr;
use secp256k1::SecretKey;
use serde::{Deserialize, Serialize};
use smart_default::SmartDefault;

View File

@ -34,7 +34,7 @@ pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<*mut c_void> {
out
};
return if !error.is_empty() {
if !error.is_empty() {
Err(error)
} else {
Ok(node_ptr)
@ -100,7 +100,7 @@ pub fn waku_listen_addresses(ctx: *mut c_void) -> Result<Vec<Multiaddr>> {
#[cfg(test)]
mod test {
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;
#[test]
@ -110,10 +110,10 @@ mod test {
waku_start(node).unwrap();
// test addresses
let addresses = waku_listen_addresses(node).unwrap();
dbg!(&addresses);
assert!(!addresses.is_empty());
// test addresses
let addresses = waku_listen_addresses(node).unwrap();
dbg!(&addresses);
assert!(!addresses.is_empty());
waku_stop(node).unwrap();
}

View File

@ -8,7 +8,7 @@ use libc::*;
use multiaddr::Multiaddr;
// internal
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
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]

View File

@ -7,7 +7,7 @@ use std::time::Duration;
use libc::*;
// internal
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/)
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding)

View File

@ -1,4 +1,3 @@
use multiaddr::Multiaddr;
use secp256k1::SecretKey;
use serial_test::serial;
use std::str::FromStr;
@ -6,25 +5,20 @@ use std::time::{Duration, SystemTime};
use std::{collections::HashSet, str::from_utf8};
use tokio::sync::broadcast::{self, Sender};
use tokio::time;
use tokio::time::sleep;
use waku_bindings::{
waku_new, Encoding, Event, MessageId, WakuContentTopic, WakuMessage, WakuNodeConfig,
WakuNodeHandle,
};
const ECHO_TIMEOUT: u64 = 10;
const ECHO_MESSAGE: &str = "Hi from 🦀!";
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(
node: &WakuNodeHandle,
msg: &WakuMessage,
) -> Result<HashSet<MessageId>, String> {
let topic = TEST_PUBSUBTOPIC.to_string();
node.relay_publish_message(msg, &topic, None)?;
node.relay_publish_message(msg, &topic, None)?;
Ok(HashSet::from([
node.relay_publish_message(msg, &topic, None)?
]))
@ -53,7 +47,8 @@ fn set_callback(node: &WakuNodeHandle, tx: Sender<Response>) {
}
async fn test_echo_messages(
node: &WakuNodeHandle,
node1: &WakuNodeHandle,
node2: &WakuNodeHandle,
content: &'static str,
content_topic: WakuContentTopic,
) {
@ -71,10 +66,12 @@ async fn test_echo_messages(
false,
);
let (tx, mut rx) = broadcast::channel(1);
set_callback(node, tx);
node1.set_event_callback(move |_event| {});
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 {
if ids.take(&res.id).is_some() {
@ -91,27 +88,28 @@ async fn test_echo_messages(
#[tokio::test]
#[serial]
async fn default_echo() -> Result<(), String> {
let config = WakuNodeConfig {
node_key: Some(
SecretKey::from_str("05f381866cc21f6c1e2e80e07fa732008e36d942dce3206ad6dcd6793c98d609")
.unwrap(),
),
let node1 = waku_new(Some(WakuNodeConfig {
port: Some(60010),
..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();
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);
@ -121,12 +119,15 @@ async fn default_echo() -> Result<(), String> {
// Send and receive messages. Waits until all messages received.
let got_all = tokio::select! {
_ = sleep => false,
_ = test_echo_messages(&node, ECHO_MESSAGE, content_topic) => true,
_ = test_echo_messages(&node1, &node2, ECHO_MESSAGE, content_topic) => true,
};
assert!(got_all);
node.stop()?;
node2.stop()?;
node1.stop()?;
Ok(())
}