Skip to content

Commit e573199

Browse files
committed
fix test by mocking coingecko datasource api call
1 parent 3a22293 commit e573199

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/src/datapoint_source/coingecko.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::assets_exchange_rate::Btc;
77
use super::assets_exchange_rate::Usd;
88
use super::erg_xau::KgAu;
99

10+
#[cfg(not(test))]
1011
pub async fn get_kgau_nanoerg() -> Result<AssetsExchangeRate<KgAu, NanoErg>, DataPointSourceError> {
1112
let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=XAU";
1213
let resp = reqwest::get(url).await?;
@@ -29,6 +30,18 @@ pub async fn get_kgau_nanoerg() -> Result<AssetsExchangeRate<KgAu, NanoErg>, Dat
2930
}
3031
}
3132

33+
#[cfg(test)]
34+
pub async fn get_kgau_nanoerg() -> Result<AssetsExchangeRate<KgAu, NanoErg>, DataPointSourceError> {
35+
let nanoerg_per_troy_ounce = NanoErg::from_erg(1.0 / 0.0008162);
36+
let nanoerg_per_kg = KgAu::from_troy_ounce(nanoerg_per_troy_ounce);
37+
let rate = AssetsExchangeRate {
38+
per1: KgAu {},
39+
get: NanoErg {},
40+
rate: nanoerg_per_kg,
41+
};
42+
Ok(rate)
43+
}
44+
3245
#[cfg(not(test))]
3346
pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataPointSourceError> {
3447
let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=USD";

0 commit comments

Comments
 (0)