fix: proper fantom api urls (#1170)
* fix: proper fantom api urls * Update ethers-etherscan/Cargo.toml Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> * chore: remove dbg Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
parent
f4eb4029b4
commit
2b2ec1101a
|
@ -1277,6 +1277,8 @@ dependencies = [
|
|||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -21,11 +21,13 @@ serde = { version = "1.0.124", default-features = false, features = ["derive"] }
|
|||
serde_json = { version = "1.0.64", default-features = false }
|
||||
serde-aux = { version = "3.0.1", default-features = false }
|
||||
thiserror = "1.0.29"
|
||||
tracing = "0.1.34"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.3.0"
|
||||
tokio = { version = "1.5", features = ["macros", "rt-multi-thread", "time"] }
|
||||
serial_test = "0.6.0"
|
||||
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
|
@ -364,14 +364,34 @@ impl Client {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError};
|
||||
use ethers_core::types::Chain;
|
||||
use ethers_solc::{Project, ProjectPathsConfig};
|
||||
use serial_test::serial;
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
|
||||
use crate::{contract::VerifyContract, tests::run_at_least_duration, Client, EtherscanError};
|
||||
#[allow(unused)]
|
||||
fn init_tracing() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.init();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
#[ignore]
|
||||
async fn can_fetch_ftm_contract_abi() {
|
||||
init_tracing();
|
||||
run_at_least_duration(Duration::from_millis(250), async {
|
||||
let client = Client::new_from_env(Chain::Fantom).unwrap();
|
||||
|
||||
let _abi = client
|
||||
.contract_abi("0x80AA7cb0006d5DDD91cce684229Ac6e398864606".parse().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::{
|
|||
use contract::ContractMetadata;
|
||||
use reqwest::{header, Url};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use tracing::trace;
|
||||
|
||||
use errors::EtherscanError;
|
||||
use ethers_core::{
|
||||
|
@ -166,10 +167,10 @@ impl Client {
|
|||
Url::parse("https://kovan-optimistic.etherscan.io"),
|
||||
),
|
||||
Chain::Fantom => {
|
||||
(Url::parse("https://api.ftmscan.com"), Url::parse("https://ftmscan.com"))
|
||||
(Url::parse("https://api.ftmscan.com/api"), Url::parse("https://ftmscan.com"))
|
||||
}
|
||||
Chain::FantomTestnet => (
|
||||
Url::parse("https://api-testnet.ftmscan.com"),
|
||||
Url::parse("https://api-testnet.ftmscan.com/api"),
|
||||
Url::parse("https://testnet.ftmscan.com"),
|
||||
),
|
||||
Chain::BinanceSmartChain => {
|
||||
|
@ -215,19 +216,20 @@ impl Client {
|
|||
Chain::Goerli |
|
||||
Chain::Optimism |
|
||||
Chain::OptimismKovan |
|
||||
Chain::Fantom |
|
||||
Chain::FantomTestnet |
|
||||
Chain::BinanceSmartChain |
|
||||
Chain::BinanceSmartChainTestnet |
|
||||
Chain::Arbitrum |
|
||||
Chain::ArbitrumTestnet |
|
||||
Chain::Cronos => std::env::var("ETHERSCAN_API_KEY")?,
|
||||
Chain::Fantom | Chain::FantomTestnet => {
|
||||
std::env::var("FTMSCAN_API_KEY").or_else(|_| std::env::var("FANTOMSCAN_API_KEY"))?
|
||||
}
|
||||
|
||||
Chain::XDai | Chain::Sepolia | Chain::CronosTestnet => String::default(),
|
||||
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
|
||||
std::env::var("MOONSCAN_API_KEY")?
|
||||
}
|
||||
Chain::Dev => return Err(errors::EtherscanError::LocalNetworksNotSupported),
|
||||
Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported),
|
||||
};
|
||||
Self::new(chain, api_key)
|
||||
}
|
||||
|
@ -265,6 +267,7 @@ impl Client {
|
|||
&self,
|
||||
form: &Form,
|
||||
) -> Result<Response<T>> {
|
||||
trace!(target: "etherscan", "POST FORM {}", self.etherscan_api_url);
|
||||
Ok(self
|
||||
.client
|
||||
.post(self.etherscan_api_url.clone())
|
||||
|
@ -278,6 +281,7 @@ impl Client {
|
|||
|
||||
/// Execute an API GET request with parameters
|
||||
async fn get_json<T: DeserializeOwned, Q: Serialize>(&self, query: &Q) -> Result<Response<T>> {
|
||||
trace!(target: "etherscan", "GET JSON {}", self.etherscan_api_url);
|
||||
let res: ResponseData<T> = self
|
||||
.client
|
||||
.get(self.etherscan_api_url.clone())
|
||||
|
@ -342,15 +346,13 @@ struct Query<'a, T: Serialize> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Client, EtherscanError};
|
||||
use ethers_core::types::{Address, Chain, H256};
|
||||
use std::{
|
||||
future::Future,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use ethers_core::types::{Address, Chain, H256};
|
||||
|
||||
use crate::{Client, EtherscanError};
|
||||
|
||||
#[test]
|
||||
fn chain_not_supported() {
|
||||
let err = Client::new_from_env(Chain::XDai).unwrap_err();
|
||||
|
|
Loading…
Reference in New Issue