use crate::{
models::{OraclePrediction, OraclePrice},
*,
};
pub mod prices {
use super::*;
pub fn all(client: &Client) -> Stream<OraclePrice> {
client.fetch_stream("/oracle/prices", NO_QUERY)
}
pub async fn current(client: &Client) -> Result<OraclePrice> {
client.fetch("/oracle/prices/current", NO_QUERY).await
}
pub async fn at_block(client: &Client, block: u64) -> Result<OraclePrice> {
client
.fetch(&format!("/oracle/prices/{}", block), NO_QUERY)
.await
}
}
pub async fn predictions(client: &Client) -> Result<Vec<OraclePrediction>> {
client.fetch("/oracle/predictions", NO_QUERY).await
}
#[cfg(test)]
mod test {
use super::*;
use models::Usd;
use tokio::test;
#[test]
async fn all() {
let client = get_test_client();
let prices = oracle::prices::all(&client)
.take(10)
.into_vec()
.await
.expect("oracle prices");
assert_eq!(prices.len(), 10);
}
#[test]
async fn current() {
let client = get_test_client();
let price = oracle::prices::current(&client).await.expect("price");
assert!(price.block > 0);
}
#[test]
async fn at_block() {
let client = get_test_client();
let price = oracle::prices::at_block(&client, 763816)
.await
.expect("price");
assert_eq!(price.price, Usd::from(733973329));
}
#[test]
async fn predictions() {
let client = get_test_client();
let predictions = oracle::predictions(&client).await;
assert!(predictions.is_ok());
}
}