feat(etherscan): add invalid api key error type (#1600)

This commit is contained in:
Matthias Seitz 2022-08-15 19:30:30 +02:00 committed by GitHub
parent bda5a7657f
commit 1af17deeb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -35,4 +35,6 @@ pub enum EtherscanError {
Builder(String), Builder(String),
#[error("Missing solc version: {0}")] #[error("Missing solc version: {0}")]
MissingSolcVersion(String), MissingSolcVersion(String),
#[error("Invalid API Key")]
InvalidApiKey,
} }

View File

@ -185,6 +185,8 @@ impl Client {
ResponseData::Error { result, .. } => { ResponseData::Error { result, .. } => {
if result.starts_with("Max rate limit reached") { if result.starts_with("Max rate limit reached") {
Err(EtherscanError::RateLimitExceeded) Err(EtherscanError::RateLimitExceeded)
} else if result.to_lowercase() == "invalid api key" {
Err(EtherscanError::InvalidApiKey)
} else { } else {
Err(EtherscanError::Unknown(result)) Err(EtherscanError::Unknown(result))
} }
@ -461,6 +463,17 @@ mod tests {
assert!(matches!(err, EtherscanError::LocalNetworksNotSupported)); assert!(matches!(err, EtherscanError::LocalNetworksNotSupported));
} }
#[tokio::test]
async fn check_wrong_etherscan_api_key() {
let client = Client::new(Chain::Mainnet, "ABCDEFG").unwrap();
let resp = client
.contract_source_code("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413".parse().unwrap())
.await
.unwrap_err();
assert!(matches!(resp, EtherscanError::InvalidApiKey));
}
pub async fn run_at_least_duration(duration: Duration, block: impl Future) { pub async fn run_at_least_duration(duration: Duration, block: impl Future) {
let start = SystemTime::now(); let start = SystemTime::now();
block.await; block.await;