pub struct MockRelayPool { /* private fields */ }Expand description
In-memory relay pool for deterministic, network-free testing.
Create one with MockRelayPool::new and pass it (wrapped in Arc) wherever
an Arc<dyn RelayPoolTrait> is expected.
Implementations§
Source§impl MockRelayPool
impl MockRelayPool
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new mock relay pool with a freshly generated ephemeral signing key.
Sourcepub fn mock_public_key(&self) -> PublicKey
pub fn mock_public_key(&self) -> PublicKey
The ephemeral public key used by this mock for signing.
Sourcepub fn mock_keys(&self) -> Keys
pub fn mock_keys(&self) -> Keys
The ephemeral signing keys (for manual event injection in tests).
Sourcepub fn create_pair() -> (Self, Self)
pub fn create_pair() -> (Self, Self)
Create a pair of linked mock relay pools with different signing keys.
Both pools share the same event store and notification channel; events
published by one are visible to the other’s notifications() receivers.
Sourcepub fn create_linked_group(n: usize) -> Vec<Self>
pub fn create_linked_group(n: usize) -> Vec<Self>
Create n linked mock relay pools with different signing keys.
All pools share the same event store and notification channel so events
published by any one pool are visible to all others’ notifications()
receivers. Useful for multi-client integration tests.
Sourcepub async fn stored_events(&self) -> Vec<Event>
pub async fn stored_events(&self) -> Vec<Event>
Clone of all events published so far (useful for assertions in tests).
Trait Implementations§
Source§impl Default for MockRelayPool
impl Default for MockRelayPool
Source§impl RelayPoolTrait for MockRelayPool
impl RelayPoolTrait for MockRelayPool
Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
_relay_urls: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
_relay_urls: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
No-op: the mock has no sockets to open.
Source§fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
No-op: the mock has no sockets to close.
Source§fn publish_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<EventId>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn publish_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<EventId>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store the event and broadcast it to all current notifications() receivers.
Source§fn publish<'life0, 'async_trait>(
&'life0 self,
builder: EventBuilder,
) -> Pin<Box<dyn Future<Output = Result<EventId>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn publish<'life0, 'async_trait>(
&'life0 self,
builder: EventBuilder,
) -> Pin<Box<dyn Future<Output = Result<EventId>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sign builder with the ephemeral key, then call publish_event.
Source§fn sign<'life0, 'async_trait>(
&'life0 self,
builder: EventBuilder,
) -> Pin<Box<dyn Future<Output = Result<Event>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sign<'life0, 'async_trait>(
&'life0 self,
builder: EventBuilder,
) -> Pin<Box<dyn Future<Output = Result<Event>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sign builder with the ephemeral key and return the event without publishing.
Source§fn signer<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn NostrSigner>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn signer<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn NostrSigner>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Return the ephemeral key as a signer.
Source§fn notifications(&self) -> Receiver<RelayPoolNotification>
fn notifications(&self) -> Receiver<RelayPoolNotification>
Return a new broadcast receiver. Each call gets an independent receiver
that sees all events published after this call, plus any replayed by
a subsequent subscribe().
Source§fn public_key<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<PublicKey>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn public_key<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<PublicKey>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Return the ephemeral public key.
Source§fn subscribe<'life0, 'async_trait>(
&'life0 self,
filters: Vec<Filter>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn subscribe<'life0, 'async_trait>(
&'life0 self,
filters: Vec<Filter>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Register the filters and immediately replay any already-stored events that match them through the broadcast channel, mirroring the behaviour of a real relay that sends historical events before EOSE.
Auto Trait Implementations§
impl !Freeze for MockRelayPool
impl !RefUnwindSafe for MockRelayPool
impl Send for MockRelayPool
impl Sync for MockRelayPool
impl Unpin for MockRelayPool
impl UnsafeUnpin for MockRelayPool
impl !UnwindSafe for MockRelayPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more