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

Commit

Permalink
test(middleware): fix flapping gas oracle (#514)
Browse files Browse the repository at this point in the history
* test(middleware): fix flapping gas oracle

* into > from
  • Loading branch information
shekhirin authored Oct 16, 2021
1 parent bef7960 commit 956a87a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions ethers-middleware/tests/gas_oracle.rs
Original file line number Diff line number Diff line change
@@ -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<U256, GasOracleError> {
Ok(self.gas_price)
}

async fn estimate_eip1559_fees(&self) -> Result<(U256, U256), GasOracleError> {
Err(GasOracleError::Eip1559EstimationNotSupported)
}
}

#[tokio::test]
async fn using_gas_oracle() {
Expand All @@ -16,7 +38,9 @@ async fn using_gas_oracle() {
let provider = Provider::<Http>::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);
Expand Down

0 comments on commit 956a87a

Please sign in to comment.