run each etherscan test at least 200ms
This commit is contained in:
parent
20948d9fe5
commit
7e453722db
|
@ -22,7 +22,7 @@ serde-aux = { version = "3.0.1", default-features = false }
|
|||
thiserror = "1.0.29"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] }
|
||||
tokio = { version = "1.5", features = ["macros", "rt-multi-thread", "time"] }
|
||||
serial_test = "0.5.1"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use crate::{Client, Response, Result};
|
||||
use ethers_core::abi::{Abi, Address};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use ethers_core::abi::{Abi, Address};
|
||||
|
||||
use crate::{Client, Response, Result};
|
||||
|
||||
/// Arguments for verifying contracts
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct VerifyContract {
|
||||
|
@ -251,39 +254,49 @@ impl Client {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{contract::VerifyContract, Client};
|
||||
use ethers_core::types::Chain;
|
||||
use std::time::Duration;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use ethers_core::types::Chain;
|
||||
|
||||
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client};
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
#[ignore]
|
||||
async fn can_fetch_contract_abi() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let _abi = client
|
||||
.contract_abi("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".parse().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
#[ignore]
|
||||
async fn can_fetch_contract_source_code() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let _meta = client
|
||||
.contract_source_code("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".parse().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
#[ignore]
|
||||
async fn can_verify_contract() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
// TODO this needs further investigation
|
||||
|
||||
// https://etherscan.io/address/0x9e744c9115b74834c0f33f4097f40c02a9ac5c33#code
|
||||
|
@ -301,5 +314,6 @@ mod tests {
|
|||
.runs(200);
|
||||
|
||||
let _resp = client.submit_contract_verification(&contract).await;
|
||||
}).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,35 +70,46 @@ impl Client {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use ethers_core::types::Chain;
|
||||
|
||||
use crate::tests::run_at_least_duration;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn gas_estimate_success() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let result = client.gas_estimate(2000000000u32.into()).await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn gas_estimate_error() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let err = client.gas_estimate(7123189371829732819379218u128.into()).await.unwrap_err();
|
||||
|
||||
assert!(matches!(err, EtherscanError::GasEstimationFailed));
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn gas_oracle_success() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let result = client.gas_oracle().await;
|
||||
|
@ -113,5 +124,7 @@ mod tests {
|
|||
assert!(oracle.last_block > 0);
|
||||
assert!(oracle.suggested_base_fee > 0.0);
|
||||
assert!(oracle.gas_used_ratio.len() > 0);
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,7 @@ impl Client {
|
|||
Chain::Mainnet | Chain::Ropsten | Chain::Kovan | Chain::Rinkeby | Chain::Goerli => {
|
||||
std::env::var("ETHERSCAN_API_KEY")?
|
||||
}
|
||||
Chain::XDai => String::default(),
|
||||
chain => return Err(EtherscanError::ChainNotSupported(chain)),
|
||||
_ => String::default(),
|
||||
};
|
||||
Self::new(chain, api_key)
|
||||
}
|
||||
|
@ -176,6 +175,11 @@ struct Query<'a, T: Serialize> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{
|
||||
future::Future,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use ethers_core::types::Chain;
|
||||
|
||||
use crate::{Client, EtherscanError};
|
||||
|
@ -187,4 +191,12 @@ mod tests {
|
|||
assert!(matches!(err, EtherscanError::ChainNotSupported(_)));
|
||||
assert_eq!(err.to_string(), "chain XDai not supported");
|
||||
}
|
||||
|
||||
pub async fn run_at_least_duration(duration: Duration, block: impl Future) {
|
||||
let start = SystemTime::now();
|
||||
block.await;
|
||||
if let Some(sleep) = duration.checked_sub(start.elapsed().unwrap()) {
|
||||
tokio::time::sleep(sleep).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,15 +52,18 @@ impl Client {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use crate::Chain;
|
||||
use crate::{tests::run_at_least_duration, Chain};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn check_contract_execution_status_success() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let status = client
|
||||
|
@ -70,11 +73,14 @@ mod tests {
|
|||
.await;
|
||||
|
||||
assert!(status.is_ok());
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn check_contract_execution_status_error() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let err = client
|
||||
|
@ -86,11 +92,14 @@ mod tests {
|
|||
|
||||
assert!(matches!(err, EtherscanError::ExecutionFailed(_)));
|
||||
assert_eq!(err.to_string(), "contract execution call failed: Bad jump destination");
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn check_transaction_receipt_status_success() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let success = client
|
||||
|
@ -100,11 +109,14 @@ mod tests {
|
|||
.await;
|
||||
|
||||
assert!(success.is_ok());
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn check_transaction_receipt_status_failed() {
|
||||
run_at_least_duration(Duration::from_millis(200), async {
|
||||
let client = Client::new_from_env(Chain::Mainnet).unwrap();
|
||||
|
||||
let err = client
|
||||
|
@ -115,5 +127,7 @@ mod tests {
|
|||
.unwrap_err();
|
||||
|
||||
assert!(matches!(err, EtherscanError::TransactionReceiptFailed));
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue