//! Mock sender implementations for testing. use bytes::Bytes; use commonware_cryptography::PublicKey; use commonware_p2p::{CheckedSender, LimitedSender, Recipients}; use std::time::SystemTime; use thiserror::Error; /// Errors that can be returned by [Failing]. #[derive(Debug, Error)] pub enum Error { #[error("send failed")] Failed, } /// A sender that always fails with [Error::Canceled]. #[derive(Clone, Debug)] pub struct Failing { _phantom: std::marker::PhantomData

, } impl Failing

{ /// Creates a new failing sender. pub fn new() -> Self { Self { _phantom: std::marker::PhantomData, } } } impl LimitedSender for Failing

{ type PublicKey = P; type Checked<'a> = CheckedFailing

; async fn check(&mut self, _recipients: Recipients

) -> Result, SystemTime> { Ok(CheckedFailing { _phantom: std::marker::PhantomData, }) } } pub struct CheckedFailing { _phantom: std::marker::PhantomData

, } impl CheckedSender for CheckedFailing

{ type PublicKey = P; type Error = Error; async fn send(self, _message: Bytes, _priority: bool) -> Result, Self::Error> { Err(Error::Failed) } }