|
@@ -1,5 +1,5 @@
|
|
use crate::{Connection, Error, Subscription};
|
|
use crate::{Connection, Error, Subscription};
|
|
-use nostr_rs_storage::Storage;
|
|
|
|
|
|
+use nostr_rs_storage_base::Storage;
|
|
use nostr_rs_types::{
|
|
use nostr_rs_types::{
|
|
relayer,
|
|
relayer,
|
|
types::{Event, SubscriptionId},
|
|
types::{Event, SubscriptionId},
|
|
@@ -229,20 +229,15 @@ impl<T: Storage> Relayer<T> {
|
|
mod test {
|
|
mod test {
|
|
use super::*;
|
|
use super::*;
|
|
use crate::get_id;
|
|
use crate::get_id;
|
|
- use nostr_rs_storage::RocksDb;
|
|
|
|
|
|
+ use nostr_rs_rocksdb::RocksDb;
|
|
use nostr_rs_types::Request;
|
|
use nostr_rs_types::Request;
|
|
- use std::{
|
|
|
|
- fs::File,
|
|
|
|
- io::{BufRead, BufReader},
|
|
|
|
- };
|
|
|
|
|
|
|
|
fn get_db(prefill: bool) -> RocksDb {
|
|
fn get_db(prefill: bool) -> RocksDb {
|
|
- let db = RocksDb::new(format!("tests/db/{}", get_id())).expect("db");
|
|
|
|
|
|
+ let db = RocksDb::new(format!("/tmp/db/{}", get_id())).expect("db");
|
|
if prefill {
|
|
if prefill {
|
|
- let file = File::open("./tests/events.json").expect("file");
|
|
|
|
- let events = BufReader::new(file)
|
|
|
|
|
|
+ let events = include_str!("../tests/events.json")
|
|
.lines()
|
|
.lines()
|
|
- .map(|line| serde_json::from_str(&line.expect("line")).expect("valid"))
|
|
|
|
|
|
+ .map(|line| serde_json::from_str(&line).expect("valid"))
|
|
.collect::<Vec<Event>>();
|
|
.collect::<Vec<Event>>();
|
|
|
|
|
|
for event in events {
|
|
for event in events {
|
|
@@ -254,7 +249,14 @@ mod test {
|
|
|
|
|
|
#[tokio::test]
|
|
#[tokio::test]
|
|
async fn serve_listener_from_local_db() {
|
|
async fn serve_listener_from_local_db() {
|
|
- let request: Request = serde_json::from_str("[\"REQ\",\"1298169700973717\",{\"authors\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"since\":1681939304},{\"#p\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[1,3,6,7,9735],\"since\":1681939304},{\"#p\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[4]},{\"authors\":[\"39a7d06e824c0c2523bedb93f0cef84245e4401fee03b6257a1c6dfd18b57efb\"],\"kinds\":[4]},{\"#e\":[\"2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a\",\"a5e3369c43daf2675ecbce18831e5f4e07db0d4dde0ef4f5698e645e4c46eed1\"],\"kinds\":[1,6,7,9735]}]").expect("valid object");
|
|
|
|
|
|
+ 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 (relayer, _) = Relayer::new(Some(get_db(true)));
|
|
let (relayer, _) = Relayer::new(Some(get_db(true)));
|
|
let (connection, mut recv) = Connection::new_for_test();
|
|
let (connection, mut recv) = Connection::new_for_test();
|
|
let _ = relayer.recv_request_from_client(&connection, request);
|
|
let _ = relayer.recv_request_from_client(&connection, request);
|
|
@@ -269,9 +271,9 @@ mod test {
|
|
.id
|
|
.id
|
|
.to_string()
|
|
.to_string()
|
|
);
|
|
);
|
|
- // ev2
|
|
|
|
|
|
+ // ev3
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- "2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a",
|
|
|
|
|
|
+ "e862fe23daf52ab09b36a37fa91ca3743e0c323e630e8627891212ca147c2da9",
|
|
recv.try_recv()
|
|
recv.try_recv()
|
|
.expect("valid")
|
|
.expect("valid")
|
|
.as_event()
|
|
.as_event()
|
|
@@ -280,9 +282,9 @@ mod test {
|
|
.id
|
|
.id
|
|
.to_string()
|
|
.to_string()
|
|
);
|
|
);
|
|
- // ev3
|
|
|
|
|
|
+ // ev2
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- "e862fe23daf52ab09b36a37fa91ca3743e0c323e630e8627891212ca147c2da9",
|
|
|
|
|
|
+ "2e72250d80e9b3fd30230b3db3ed7d22f15d266ed345c36700b01ec153c9e28a",
|
|
recv.try_recv()
|
|
recv.try_recv()
|
|
.expect("valid")
|
|
.expect("valid")
|
|
.as_event()
|
|
.as_event()
|