mithril_era/adapters/
bootstrap.rs

1use async_trait::async_trait;
2
3use mithril_common::StdResult;
4use mithril_common::entities::{Epoch, SupportedEra};
5
6use crate::{EraMarker, EraReaderAdapter};
7
8/// The goal of the bootstrap adapter is to advertise for the first existing Era
9/// while it does not exist yet on any backend. This adapter is intended to be
10/// removed once Eras are effectively written in a backend.
11pub struct BootstrapAdapter;
12
13#[async_trait]
14impl EraReaderAdapter for BootstrapAdapter {
15    async fn read(&self) -> StdResult<Vec<EraMarker>> {
16        Ok(vec![EraMarker::new(
17            &SupportedEra::eras().first().unwrap().to_string(),
18            Some(Epoch(0)),
19        )])
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use mithril_common::test::double::Dummy;
26
27    use super::*;
28
29    #[tokio::test]
30    async fn bootstrap_adapter() {
31        let adapter = BootstrapAdapter;
32
33        assert_eq!(
34            vec![EraMarker::new(&SupportedEra::dummy().to_string(), Some(Epoch(0)))],
35            adapter.read().await.expect("bootstrap adapter shall never fail")
36        );
37    }
38}