2021-08-23 09:56:44 +00:00
|
|
|
#![cfg(not(target_arch = "wasm32"))]
|
2022-12-18 11:45:47 +00:00
|
|
|
|
2020-10-08 15:56:36 +00:00
|
|
|
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;
|
2021-07-29 20:22:25 +00:00
|
|
|
use ethers_signers::{LocalWallet, Signer};
|
2020-10-08 15:56:36 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[ignore]
|
|
|
|
async fn gas_escalator_live() {
|
|
|
|
// connect to ropsten for getting bad block times
|
2022-12-31 10:47:53 +00:00
|
|
|
#[allow(deprecated)]
|
2022-03-13 17:11:27 +00:00
|
|
|
let provider = ethers_providers::ROPSTEN.ws().await;
|
|
|
|
let provider = provider.interval(Duration::from_millis(2000u64));
|
2020-10-08 15:56:36 +00:00
|
|
|
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));
|
2020-10-08 15:56:36 +00:00
|
|
|
|
|
|
|
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
|
2021-10-29 12:29:35 +00:00
|
|
|
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();
|
2020-10-08 15:56:36 +00:00
|
|
|
|
|
|
|
// Wait a bunch of seconds and refresh etherscan to see the transactions get bumped
|
2022-12-31 10:47:53 +00:00
|
|
|
tokio::time::sleep(Duration::from_secs(100)).await;
|
2020-10-08 15:56:36 +00:00
|
|
|
|
2021-10-29 12:29:35 +00:00
|
|
|
// 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
|
2020-10-08 15:56:36 +00:00
|
|
|
}
|