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

test(middleware): fix flapping gas oracle #514

Merged
merged 2 commits into from
Oct 16, 2021
Merged
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
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