|
@@ -272,12 +272,12 @@ impl<T: Storage> Relayer<T> {
|
|
|
#[cfg(test)]
|
|
|
mod test {
|
|
|
use super::*;
|
|
|
- use crate::get_id;
|
|
|
- use nostr_rs_rocksdb::RocksDb;
|
|
|
+ use nostr_rs_memory::Memory;
|
|
|
use nostr_rs_types::Request;
|
|
|
+ use serde_json::json;
|
|
|
|
|
|
- async fn get_db(prefill: bool) -> RocksDb {
|
|
|
- let db = RocksDb::new(format!("/tmp/db/{}", get_id())).expect("db");
|
|
|
+ async fn get_db(prefill: bool) -> Memory {
|
|
|
+ let db = Memory::default();
|
|
|
if prefill {
|
|
|
let events = include_str!("../tests/events.json")
|
|
|
.lines()
|
|
@@ -287,20 +287,68 @@ mod test {
|
|
|
for event in events {
|
|
|
assert!(db.store(&event).await.expect("valid"));
|
|
|
}
|
|
|
+
|
|
|
+ while db.is_flushing() {
|
|
|
+ tokio::time::sleep(tokio::time::Duration::from_millis(1)).await;
|
|
|
+ }
|
|
|
}
|
|
|
db
|
|
|
}
|
|
|
|
|
|
#[tokio::test]
|
|
|
async fn serve_listener_from_local_db() {
|
|
|
- let request: Request = serde_json::from_str("[
|
|
|
- \"REQ\",\"1298169700973717\",
|
|
|
- {\"authors\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"since\":1681928304},
|
|
|
- {\"#p\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[1,3,6,7,9735],\"since\":1681928304},
|
|
|
- {\"#p\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[4]},
|
|
|
- {\"authors\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[4]},
|
|
|
- {\"#e\":[\"2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a\",\"a5e3369c43daf2675ecbce18831e5f4e07db0d4dde0ef4f5698e645e4c46eed1\"],\"kinds\":[1,6,7,9735]}
|
|
|
- ]").expect("valid object");
|
|
|
+ let request = serde_json::from_value(json!([
|
|
|
+ "REQ",
|
|
|
+ "1298169700973717",
|
|
|
+ {
|
|
|
+ "authors": [
|
|
|
+ "39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb"
|
|
|
+ ],
|
|
|
+ "since": 1681928304
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "#p": [
|
|
|
+ "39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb"
|
|
|
+ ],
|
|
|
+ "kinds": [
|
|
|
+ 1,
|
|
|
+ 3,
|
|
|
+ 6,
|
|
|
+ 7,
|
|
|
+ 9735
|
|
|
+ ],
|
|
|
+ "since": 1681928304
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "#p": [
|
|
|
+ "39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb"
|
|
|
+ ],
|
|
|
+ "kinds": [
|
|
|
+ 4
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "authors": [
|
|
|
+ "39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb"
|
|
|
+ ],
|
|
|
+ "kinds": [
|
|
|
+ 4
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "#e": [
|
|
|
+ "2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a",
|
|
|
+ "a5e3369c43daf2675ecbce18831e5f4e07db0d4dde0ef4f5698e645e4c46eed1"
|
|
|
+ ],
|
|
|
+ "kinds": [
|
|
|
+ 1,
|
|
|
+ 6,
|
|
|
+ 7,
|
|
|
+ 9735
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]))
|
|
|
+ .expect("valid object");
|
|
|
let (relayer, _) = Relayer::new(Some(get_db(true).await), None).expect("valid relayer");
|
|
|
let (connection, mut recv) = Connection::new_for_test();
|
|
|
let _ = relayer.recv_request_from_client(&connection, request).await;
|
|
@@ -337,6 +385,30 @@ mod test {
|
|
|
.id
|
|
|
.to_string()
|
|
|
);
|
|
|
+
|
|
|
+ // ev3 (again)
|
|
|
+ assert_eq!(
|
|
|
+ "e862fe23daf52ab09b36a37fa91ca3743e0c323e630e8627891212ca147c2da9",
|
|
|
+ recv.try_recv()
|
|
|
+ .expect("valid")
|
|
|
+ .as_event()
|
|
|
+ .expect("event")
|
|
|
+ .event
|
|
|
+ .id
|
|
|
+ .to_string()
|
|
|
+ );
|
|
|
+ // ev2 (again)
|
|
|
+ assert_eq!(
|
|
|
+ "2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a",
|
|
|
+ recv.try_recv()
|
|
|
+ .expect("valid")
|
|
|
+ .as_event()
|
|
|
+ .expect("event")
|
|
|
+ .event
|
|
|
+ .id
|
|
|
+ .to_string()
|
|
|
+ );
|
|
|
+
|
|
|
// eod
|
|
|
assert!(recv
|
|
|
.try_recv()
|