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

Commit

Permalink
tests: use sepolia (#1989)
Browse files Browse the repository at this point in the history
* tests: use sepolia

* update ci

* update sleep duration

* deprecate ropsten

* use goerli

* fmt

* keys
  • Loading branch information
DaniPopes authored Dec 31, 2022
1 parent 228f960 commit fd4da49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion ethers-middleware/tests/gas_escalator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::time::Duration;
#[ignore]
async fn gas_escalator_live() {
// connect to ropsten for getting bad block times
#[allow(deprecated)]
let provider = ethers_providers::ROPSTEN.ws().await;
let provider = provider.interval(Duration::from_millis(2000u64));
let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"
Expand All @@ -34,7 +35,7 @@ async fn gas_escalator_live() {
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;
tokio::time::sleep(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
Expand Down
6 changes: 3 additions & 3 deletions ethers-middleware/tests/nonce_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::Duration;

#[tokio::test]
async fn nonce_manager() {
let provider = ethers_providers::GOERLI.provider().interval(Duration::from_millis(2000u64));
let provider = ethers_providers::GOERLI.provider().interval(Duration::from_millis(2000));
let chain_id = provider.get_chainid().await.unwrap().as_u64();

let wallet = std::env::var("GOERLI_PRIVATE_KEY")
Expand Down Expand Up @@ -44,12 +44,12 @@ async fn nonce_manager() {
}

// sleep a bit to ensure there's no flakiness in the test
std::thread::sleep(std::time::Duration::new(5, 0));
tokio::time::sleep(Duration::from_secs(10)).await;

let mut nonces = Vec::with_capacity(num_tx);
for tx_hash in tx_hashes {
nonces.push(provider.get_transaction(tx_hash).await.unwrap().unwrap().nonce.as_u64());
}

assert_eq!(nonces, (nonce..nonce + (num_tx as u64)).collect::<Vec<_>>())
assert_eq!(nonces, (nonce..nonce + num_tx as u64).collect::<Vec<_>>())
}
2 changes: 1 addition & 1 deletion ethers-middleware/tests/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl TestWallets {
#[allow(unused)]
pub async fn fund<T: JsonRpcClient, U: Into<u32>>(&self, provider: &Provider<T>, n: U) {
let addrs = (0..n.into()).map(|i| self.get(i).address()).collect::<Vec<_>>();
// hardcoded funder address private key, goerli
// hardcoded funder address private key, GOERLI
let signer = "39aa18eeb5d12c071e5f19d8e9375a872e90cb1f2fa640384ffd8800a2f3e8f1"
.parse::<LocalWallet>()
.unwrap()
Expand Down
21 changes: 12 additions & 9 deletions ethers-providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ pub trait CeloMiddleware: Middleware {
}
}

pub use test_provider::{GOERLI, MAINNET, ROPSTEN};
#[allow(deprecated)]
pub use test_provider::{GOERLI, MAINNET, ROPSTEN, SEPOLIA};

/// Pre-instantiated Infura HTTP clients which rotate through multiple API keys
/// to prevent rate limits
Expand All @@ -743,9 +744,13 @@ pub mod test_provider {
"5c812e02193c4ba793f8c214317582bd",
];

pub static GOERLI: Lazy<TestProvider> = Lazy::new(|| TestProvider::new(INFURA_KEYS, "goerli"));
pub static MAINNET: Lazy<TestProvider> =
Lazy::new(|| TestProvider::new(INFURA_KEYS, "mainnet"));
pub static GOERLI: Lazy<TestProvider> = Lazy::new(|| TestProvider::new(INFURA_KEYS, "goerli"));
pub static SEPOLIA: Lazy<TestProvider> =
Lazy::new(|| TestProvider::new(INFURA_KEYS, "sepolia"));

#[deprecated = "Ropsten testnet has been deprecated in favor of Goerli or Sepolia."]
pub static ROPSTEN: Lazy<TestProvider> =
Lazy::new(|| TestProvider::new(INFURA_KEYS, "ropsten"));

Expand All @@ -756,16 +761,14 @@ pub mod test_provider {
}

impl TestProvider {
pub fn new(keys: &'static [&'static str], network: &str) -> Self {
Self { keys: Mutex::new(keys.iter().cycle()), network: network.to_owned() }
pub fn new(keys: &'static [&'static str], network: impl Into<String>) -> Self {
Self { keys: keys.iter().cycle().into(), network: network.into() }
}

pub fn url(&self) -> String {
format!(
"https://{}.infura.io/v3/{}",
self.network,
self.keys.lock().unwrap().next().unwrap()
)
let Self { network, keys } = self;
let key = keys.lock().unwrap().next().unwrap();
format!("https://{network}.infura.io/v3/{key}")
}

pub fn provider(&self) -> Provider<Http> {
Expand Down

0 comments on commit fd4da49

Please sign in to comment.