Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(middleware): no need to multiply again with GWEI_TO_WEI_U256 #2326

Merged
merged 4 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ethers-middleware/src/gas_oracle/etherscan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{GasCategory, GasOracle, GasOracleError, Result, GWEI_TO_WEI_U256};
use super::{GasCategory, GasOracle, GasOracleError, Result};
use async_trait::async_trait;
use ethers_core::{types::U256, utils::parse_units};
use ethers_core::types::U256;
use ethers_etherscan::Client;
use std::ops::{Deref, DerefMut};

Expand Down Expand Up @@ -45,8 +45,8 @@ impl GasOracle for Etherscan {
_ => unreachable!(),
};
// returned gas prices are f64 value in gwei
let gas_price = parse_units(gas_price, "gwei")?;
Ok(U256::from(gas_price) * GWEI_TO_WEI_U256)
let gas_price = super::from_gwei_f64(gas_price);
Ok(gas_price)
}

async fn estimate_eip1559_fees(&self) -> Result<(U256, U256)> {
Expand Down
7 changes: 6 additions & 1 deletion ethers-middleware/tests/it/gas_oracle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use async_trait::async_trait;
use ethers_core::{types::*, utils::Anvil};
use ethers_core::{
types::*,
utils::{parse_ether, Anvil},
};
use ethers_etherscan::Client;
use ethers_middleware::gas_oracle::{
BlockNative, Etherchain, Etherscan, GasCategory, GasNow, GasOracle, GasOracleError,
Expand Down Expand Up @@ -102,6 +105,8 @@ async fn etherscan() {

let gas_price = etherscan_oracle.fetch().await.unwrap();
assert!(gas_price > U256::zero());
let ten_ethers = parse_ether(10).unwrap();
assert!(gas_price < ten_ethers, "gas calculation is wrong (too high)");
}

#[tokio::test]
Expand Down