use om_rest_types::responses::EpochResponse;
use crate::{
client::{
Client,
config::{
api_path,
endpoints::governance::{CURRENT_EPOCH, EPOCH_BY_ID},
},
},
error::Result,
};
impl Client {
pub async fn get_current_epoch(&self) -> Result<EpochResponse> {
let path = api_path(CURRENT_EPOCH);
self.get(&path).await
}
pub async fn get_epoch_by_id(&self, epoch_id: u64) -> Result<EpochResponse> {
let path = api_path(&format!("{EPOCH_BY_ID}?id={epoch_id}"));
self.get(&path).await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::config::api_path;
#[test]
fn test_current_epoch_endpoint_path() {
let path = api_path(CURRENT_EPOCH);
assert_eq!(path, "/v1/governances/epoch");
assert!(path.contains("/governances/epoch"));
}
#[test]
fn test_epoch_by_id_endpoint_path() {
let id = 42;
let path = api_path(&format!("{EPOCH_BY_ID}?id={id}"));
assert_eq!(path, "/v1/governances/epoch/by_id?id=42");
assert!(path.contains("id=42"));
}
}