fix: gwei wei wrong u256 constant (#1992)
This commit is contained in:
parent
10310ce3ad
commit
fcef7c70ad
|
@ -37,7 +37,7 @@ use std::{error::Error, fmt::Debug};
|
|||
use thiserror::Error;
|
||||
|
||||
pub(crate) const GWEI_TO_WEI: u64 = 1_000_000_000;
|
||||
pub(crate) const GWEI_TO_WEI_U256: U256 = U256([0, 0, 0, GWEI_TO_WEI]);
|
||||
pub(crate) const GWEI_TO_WEI_U256: U256 = U256([GWEI_TO_WEI, 0, 0, 0]);
|
||||
|
||||
pub type Result<T, E = GasOracleError> = std::result::Result<T, E>;
|
||||
|
||||
|
@ -153,3 +153,15 @@ pub trait GasOracle: Send + Sync + Debug {
|
|||
pub(crate) fn from_gwei_f64(gwei: f64) -> U256 {
|
||||
ethers_core::types::u256_from_f64_saturating(gwei) * GWEI_TO_WEI_U256
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_gwei_wei_constants() {
|
||||
let as_u256: U256 = GWEI_TO_WEI.into();
|
||||
assert_eq!(as_u256, GWEI_TO_WEI_U256);
|
||||
assert_eq!(GWEI_TO_WEI_U256.as_u64(), GWEI_TO_WEI);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct Polygon {
|
|||
|
||||
/// The response from the Polygon gas station API.
|
||||
///
|
||||
/// Gas prices are in Gwei.
|
||||
/// Gas prices are in __Gwei__.
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Response {
|
||||
|
@ -103,3 +103,14 @@ impl Polygon {
|
|||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_polygon_gas_station_response() {
|
||||
let s = r#"{"safeLow":{"maxPriorityFee":2.1267086610666666,"maxFee":2.1267086760666665},"standard":{"maxPriorityFee":2.3482958369333335,"maxFee":2.3482958519333335},"fast":{"maxPriorityFee":2.793454819,"maxFee":2.793454834},"estimatedBaseFee":1.5e-8,"blockTime":2,"blockNumber":30328888}"#;
|
||||
let _resp: Response = serde_json::from_str(s).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue