tests: use sepolia (#1989)

* tests: use sepolia

* update ci

* update sleep duration

* deprecate ropsten

* use goerli

* fmt

* keys
This commit is contained in:
DaniPopes 2022-12-31 11:47:53 +01:00 committed by GitHub
parent 228f9607fe
commit fd4da49121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 14 deletions

View File

@ -13,6 +13,7 @@ use std::time::Duration;
#[ignore] #[ignore]
async fn gas_escalator_live() { async fn gas_escalator_live() {
// connect to ropsten for getting bad block times // connect to ropsten for getting bad block times
#[allow(deprecated)]
let provider = ethers_providers::ROPSTEN.ws().await; let provider = ethers_providers::ROPSTEN.ws().await;
let provider = provider.interval(Duration::from_millis(2000u64)); let provider = provider.interval(Duration::from_millis(2000u64));
let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169" let wallet = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"
@ -34,7 +35,7 @@ async fn gas_escalator_live() {
provider.send_transaction(tx.clone().nonce(nonce + 2), 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 // 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 // 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 // bumped then the tx hash will be different

View File

@ -8,7 +8,7 @@ use std::time::Duration;
#[tokio::test] #[tokio::test]
async fn nonce_manager() { 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 chain_id = provider.get_chainid().await.unwrap().as_u64();
let wallet = std::env::var("GOERLI_PRIVATE_KEY") let wallet = std::env::var("GOERLI_PRIVATE_KEY")
@ -44,12 +44,12 @@ async fn nonce_manager() {
} }
// sleep a bit to ensure there's no flakiness in the test // 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); let mut nonces = Vec::with_capacity(num_tx);
for tx_hash in tx_hashes { for tx_hash in tx_hashes {
nonces.push(provider.get_transaction(tx_hash).await.unwrap().unwrap().nonce.as_u64()); 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<_>>())
} }

View File

@ -294,7 +294,7 @@ impl TestWallets {
#[allow(unused)] #[allow(unused)]
pub async fn fund<T: JsonRpcClient, U: Into<u32>>(&self, provider: &Provider<T>, n: U) { 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<_>>(); 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" let signer = "39aa18eeb5d12c071e5f19d8e9375a872e90cb1f2fa640384ffd8800a2f3e8f1"
.parse::<LocalWallet>() .parse::<LocalWallet>()
.unwrap() .unwrap()

View File

@ -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 /// Pre-instantiated Infura HTTP clients which rotate through multiple API keys
/// to prevent rate limits /// to prevent rate limits
@ -743,9 +744,13 @@ pub mod test_provider {
"5c812e02193c4ba793f8c214317582bd", "5c812e02193c4ba793f8c214317582bd",
]; ];
pub static GOERLI: Lazy<TestProvider> = Lazy::new(|| TestProvider::new(INFURA_KEYS, "goerli"));
pub static MAINNET: Lazy<TestProvider> = pub static MAINNET: Lazy<TestProvider> =
Lazy::new(|| TestProvider::new(INFURA_KEYS, "mainnet")); 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> = pub static ROPSTEN: Lazy<TestProvider> =
Lazy::new(|| TestProvider::new(INFURA_KEYS, "ropsten")); Lazy::new(|| TestProvider::new(INFURA_KEYS, "ropsten"));
@ -756,16 +761,14 @@ pub mod test_provider {
} }
impl TestProvider { impl TestProvider {
pub fn new(keys: &'static [&'static str], network: &str) -> Self { pub fn new(keys: &'static [&'static str], network: impl Into<String>) -> Self {
Self { keys: Mutex::new(keys.iter().cycle()), network: network.to_owned() } Self { keys: keys.iter().cycle().into(), network: network.into() }
} }
pub fn url(&self) -> String { pub fn url(&self) -> String {
format!( let Self { network, keys } = self;
"https://{}.infura.io/v3/{}", let key = keys.lock().unwrap().next().unwrap();
self.network, format!("https://{network}.infura.io/v3/{key}")
self.keys.lock().unwrap().next().unwrap()
)
} }
pub fn provider(&self) -> Provider<Http> { pub fn provider(&self) -> Provider<Http> {