1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Test-only mocks for [`ChainSyncStatus`].

use std::sync::{
    atomic::{AtomicBool, Ordering},
    Arc,
};

use super::ChainSyncStatus;

/// A mock [`ChainSyncStatus`] implementation that allows setting the status externally.
#[derive(Clone, Default)]
pub struct MockSyncStatus {
    is_close_to_tip: Arc<AtomicBool>,
}

impl MockSyncStatus {
    /// Sets mock sync status determining the return value of `is_close_to_tip()`
    pub fn set_is_close_to_tip(&mut self, is_close_to_tip: bool) {
        self.is_close_to_tip
            .store(is_close_to_tip, Ordering::SeqCst);
    }
}

impl ChainSyncStatus for MockSyncStatus {
    fn is_close_to_tip(&self) -> bool {
        self.is_close_to_tip.load(Ordering::SeqCst)
    }
}