feat(etherscan): add invalid api key error type (#1600)
This commit is contained in:
parent
bda5a7657f
commit
1af17deeb5
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue