Merge f213e27f478170b438f508034143ca8970c8ca82 into 57505a1c06e933b912dc657ada94965395ca30e7

This commit is contained in:
Daniel Sanchez 2025-05-06 23:21:14 +00:00 committed by GitHub
commit e1d0e544cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,3 +35,64 @@ impl Chat2Message {
Utc.timestamp_opt(self.timestamp as i64, 0)
}
}
mod tests {
use crate::{Chat2Message, Multiaddr, NODES};
use prost::Message;
use std::str::FromStr;
use waku::{
waku_new, waku_set_event_callback, ContentFilter, Encoding, Event, PagingOptions,
ProtocolId, Result, StoreQuery, WakuContentTopic, WakuMessage, WakuNodeConfig,
};
#[ignore]
#[test]
fn main() -> Result<()> {
let chat2_content_topic = WakuContentTopic {
application_name: "toy-chat".into(),
version: 2,
content_topic_name: "huilong".into(),
encoding: Encoding::Proto,
};
let handle = waku_new(None)?.start()?;
let mut peer_id = None;
for address in NODES {
peer_id =
Some(handle.add_peer(&Multiaddr::from_str(*address).unwrap(), ProtocolId::Store)?);
handle.connect_peer_with_id(peer_id.as_ref().unwrap().clone(), None)?;
}
let peer_id = peer_id.unwrap();
let response = handle.store_query(
&StoreQuery {
pubsub_topic: None,
content_filters: vec![ContentFilter::new(chat2_content_topic)],
start_time: None,
end_time: None,
paging_options: Some(PagingOptions {
page_size: 100,
cursor: None,
forward: true,
}),
},
&peer_id,
None,
)?;
for message in response
.messages()
.iter()
.map(|message| Chat2Message::decode(message.payload()).unwrap())
{
println!(
"[{} - {}]: {}",
message.timestamp(),
message.nick(),
message.message(),
)
}
Ok(())
}
}