You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

use daemon::model::BitMexPriceEventId;
use daemon::oracle;
use mockall::*;
use std::sync::Arc;
use time::OffsetDateTime;
use tokio::sync::Mutex;
use xtra_productivity::xtra_productivity;
use crate::harness::maia::OliviaData;
/// Test Stub simulating the Oracle actor.
/// Serves as an entrypoint for injected mock handlers.
pub struct OracleActor {
pub mock: Arc<Mutex<dyn Oracle + Send>>,
}
impl xtra::Actor for OracleActor {}
impl Oracle for OracleActor {}
#[xtra_productivity(message_impl = false)]
impl OracleActor {
async fn handle(
&mut self,
msg: oracle::GetAnnouncement,
) -> Result<oracle::Announcement, oracle::NoAnnouncement> {
self.mock.lock().await.get_announcement(msg)
}
async fn handle(&mut self, msg: oracle::MonitorAttestation) {
self.mock.lock().await.monitor_attestation(msg)
}
async fn handle(&mut self, msg: oracle::Sync) {
self.mock.lock().await.sync(msg)
}
}
#[automock]
pub trait Oracle {
fn get_announcement(
&mut self,
_msg: oracle::GetAnnouncement,
) -> Result<oracle::Announcement, oracle::NoAnnouncement> {
unreachable!("mockall will reimplement this method")
}
fn monitor_attestation(&mut self, _msg: oracle::MonitorAttestation) {
unreachable!("mockall will reimplement this method")
}
fn sync(&mut self, _msg: oracle::Sync) {
unreachable!("mockall will reimplement this method")
}
}
/// We do *not* depend on the current time in our tests, the valid combination of
/// announcement/attestation is hard-coded in OliviaData struct (along with event id's).
/// Therefore, an attestation based on current utc time will always be wrong.
pub fn dummy_wrong_attestation() -> oracle::Attestation {
let oracle::Attestation {
id: _,
price,
scalars,
} = OliviaData::example_0().attestation();
oracle::Attestation {
id: BitMexPriceEventId::with_20_digits(OffsetDateTime::now_utc()),
price,
scalars,
}
}