ethers-rs/ethers-middleware/tests/gas_escalator.rs

41 lines
1.6 KiB
Rust
Raw Permalink Normal View History

#![cfg(not(target_arch = "wasm32"))]
use ethers_core::types::*;
use ethers_middleware::{
gas_escalator::{Frequency, GasEscalatorMiddleware, GeometricGasPrice},
signer::SignerMiddleware,
};
2022-03-13 17:11:27 +00:00
use ethers_providers::Middleware;
use ethers_signers::{LocalWallet, Signer};
use std::time::Duration;
#[tokio::test]
#[ignore]
async fn gas_escalator_live() {
// connect to ropsten for getting bad block times
2022-03-13 17:11:27 +00:00
let provider = ethers_providers::ROPSTEN.ws().await;
let provider = provider.interval(Duration::from_millis(2000u64));
let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"
.parse::<LocalWallet>()
.unwrap();
let address = wallet.address();
let provider = SignerMiddleware::new(provider, wallet);
2021-07-05 11:03:38 +00:00
let escalator = GeometricGasPrice::new(5.0, 10u64, Some(2_000_000_000_000u64));
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::Duration(3000));
let nonce = provider.get_transaction_count(address, None).await.unwrap();
let tx = TransactionRequest::pay(Address::zero(), 1u64).gas_price(10_000_000);
// broadcast 3 txs
provider.send_transaction(tx.clone().nonce(nonce), None).await.unwrap();
provider.send_transaction(tx.clone().nonce(nonce + 1), None).await.unwrap();
provider.send_transaction(tx.clone().nonce(nonce + 2), None).await.unwrap();
// Wait a bunch of seconds and refresh etherscan to see the transactions get bumped
tokio::time::sleep(std::time::Duration::from_secs(100)).await;
// TODO: Figure out how to test this behavior properly in a local network. If the gas price was
// bumped then the tx hash will be different
}