mithril_aggregator/services/signature_consumer/
noop.rs

1use std::future;
2
3use async_trait::async_trait;
4
5use super::SignatureConsumer;
6
7/// A no-op implementation of the [SignatureConsumer] trait that will never return signatures.
8pub struct SignatureConsumerNoop;
9
10#[async_trait]
11impl SignatureConsumer for SignatureConsumerNoop {
12    async fn get_signatures(
13        &self,
14    ) -> mithril_common::StdResult<
15        Vec<(
16            mithril_common::entities::SingleSignature,
17            mithril_common::entities::SignedEntityType,
18        )>,
19    > {
20        future::pending().await
21    }
22
23    fn get_origin_tag(&self) -> String {
24        "NOOP".to_string()
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use anyhow::anyhow;
31    use tokio::time::{sleep, Duration};
32
33    use super::*;
34
35    #[tokio::test]
36    async fn signature_consumer_noop_never_returns() {
37        let consumer = SignatureConsumerNoop;
38
39        let result = tokio::select!(
40            _res = sleep(Duration::from_millis(100)) => {Err(anyhow!("Timeout"))},
41            _res =  consumer.get_signatures()  => {Ok(())},
42        );
43
44        result.expect_err("Should have timed out");
45    }
46}