feat: rotate infura keys for ws

This commit is contained in:
Georgios Konstantopoulos 2022-03-13 10:11:27 -07:00
parent ae125bcfc7
commit 4f37287859
4 changed files with 15 additions and 16 deletions

View File

@ -4,7 +4,7 @@ use ethers_middleware::{
gas_escalator::{Frequency, GasEscalatorMiddleware, GeometricGasPrice},
signer::SignerMiddleware,
};
use ethers_providers::{Middleware, Provider, Ws};
use ethers_providers::Middleware;
use ethers_signers::{LocalWallet, Signer};
use std::time::Duration;
@ -12,10 +12,8 @@ use std::time::Duration;
#[ignore]
async fn gas_escalator_live() {
// connect to ropsten for getting bad block times
let ws = Ws::connect("wss://ropsten.infura.io/ws/v3/fd8b88b56aa84f6da87b60f5441d6778")
.await
.unwrap();
let provider = Provider::new(ws).interval(Duration::from_millis(2000u64));
let provider = ethers_providers::ROPSTEN.ws().await;
let provider = provider.interval(Duration::from_millis(2000u64));
let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"
.parse::<LocalWallet>()
.unwrap();

View File

@ -69,11 +69,7 @@ use ethers_core::types::{Address, Eip1559TransactionRequest};
#[tokio::test]
#[cfg(not(feature = "celo"))]
async fn websocket_pending_txs_with_confirmations_testnet() {
let provider =
Provider::connect("wss://rinkeby.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await
.unwrap()
.interval(Duration::from_millis(3000));
let provider = RINKEBY.ws().await.interval(Duration::from_millis(3000));
let chain_id = provider.get_chainid().await.unwrap();
let wallet = WALLETS.next().with_chain_id(chain_id.as_u64());
let address = wallet.address();

View File

@ -664,7 +664,7 @@ pub use test_provider::{GOERLI, MAINNET, RINKEBY, ROPSTEN};
/// to prevent rate limits
pub mod test_provider {
use super::*;
use crate::Http;
use crate::{Http, Ws};
use once_cell::sync::Lazy;
use std::{convert::TryFrom, iter::Cycle, slice::Iter, sync::Mutex};
@ -705,5 +705,14 @@ pub mod test_provider {
);
Provider::try_from(url.as_str()).unwrap()
}
pub async fn ws(&self) -> Provider<Ws> {
let url = format!(
"wss://{}.infura.io/ws/v3/{}",
self.network,
self.keys.lock().unwrap().next().unwrap()
);
Provider::connect(url.as_str()).await.unwrap()
}
}
}

View File

@ -35,11 +35,7 @@ mod eth_tests {
// Without TLS this would error with "TLS Support not compiled in"
#[tokio::test]
async fn ssl_websocket() {
use ethers_providers::Ws;
let ws = Ws::connect("wss://rinkeby.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27")
.await
.unwrap();
let provider = Provider::new(ws);
let provider = RINKEBY.ws().await;
let _number = provider.get_block_number().await.unwrap();
}