Added tiny manual check history retrieval

This commit is contained in:
Daniel Sanchez Quiros 2022-10-20 16:32:13 +02:00
parent 9993d2d991
commit f213e27f47
1 changed files with 61 additions and 0 deletions

View File

@ -40,3 +40,64 @@ impl Chat2Message {
Utc.timestamp(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(())
}
}