Skip to main content

MockRelayPool

Struct MockRelayPool 

Source
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

Source

pub fn new() -> Self

Create a new mock relay pool with a freshly generated ephemeral signing key.

Source

pub fn mock_public_key(&self) -> PublicKey

The ephemeral public key used by this mock for signing.

Source

pub fn mock_keys(&self) -> Keys

The ephemeral signing keys (for manual event injection in tests).

Source

pub fn with_keys(keys: Keys) -> Self

Like new but with caller-provided signing keys.

Source

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.

Source

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.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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,

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,

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,

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,

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,

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,

Return the ephemeral key as a signer.

Source§

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,

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,

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more