From 956a87a9248e02c4695723cfb95df052d7b595fc Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Sat, 16 Oct 2021 18:47:17 +0300 Subject: [PATCH] test(middleware): fix flapping gas oracle (#514) * test(middleware): fix flapping gas oracle * into > from --- ethers-middleware/tests/gas_oracle.rs | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/ethers-middleware/tests/gas_oracle.rs b/ethers-middleware/tests/gas_oracle.rs index bdceb3a6..42f64a41 100644 --- a/ethers-middleware/tests/gas_oracle.rs +++ b/ethers-middleware/tests/gas_oracle.rs @@ -1,10 +1,32 @@ #![cfg(not(target_arch = "wasm32"))] + +use std::convert::TryFrom; + +use async_trait::async_trait; + use ethers_core::{types::*, utils::Ganache}; use ethers_middleware::gas_oracle::{ - EthGasStation, Etherchain, Etherscan, GasCategory, GasOracle, GasOracleMiddleware, + EthGasStation, Etherchain, Etherscan, GasCategory, GasOracle, GasOracleError, + GasOracleMiddleware, }; use ethers_providers::{Http, Middleware, Provider}; -use std::convert::TryFrom; + +#[derive(Debug)] +struct FakeGasOracle { + gas_price: U256, +} + +#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait)] +impl GasOracle for FakeGasOracle { + async fn fetch(&self) -> Result { + Ok(self.gas_price) + } + + async fn estimate_eip1559_fees(&self) -> Result<(U256, U256), GasOracleError> { + Err(GasOracleError::Eip1559EstimationNotSupported) + } +} #[tokio::test] async fn using_gas_oracle() { @@ -16,7 +38,9 @@ async fn using_gas_oracle() { let provider = Provider::::try_from(ganache.endpoint()).unwrap(); // assign a gas oracle to use - let gas_oracle = EthGasStation::new(None); + let gas_oracle = FakeGasOracle { + gas_price: 1337.into(), + }; let expected_gas_price = gas_oracle.fetch().await.unwrap(); let provider = GasOracleMiddleware::new(provider, gas_oracle);