Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use join for check-by-address path #7062

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions crates/forge/bin/cmd/verify/sourcify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use foundry_cli::utils::{get_cached_entry_by_name, LoadConfig};
use foundry_common::{fs, retry::Retry};
use foundry_compilers::ConfigurableContractArtifact;
use futures::FutureExt;
use reqwest::Url;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf, str::FromStr};

pub static SOURCIFY_URL: &str = "https://sourcify.dev/server/";

Expand Down Expand Up @@ -69,13 +70,15 @@ impl VerificationProvider for SourcifyVerificationProvider {
let resp = retry
.run_async(|| {
async {
let url = format!(
"{}check-by-addresses?addresses={}&chainIds={}",
let url = Url::from_str(
args.verifier.verifier_url.as_deref().unwrap_or(SOURCIFY_URL),
)?;
let query = format!(
"check-by-addresses?addresses={}&chainIds={}",
args.id,
args.etherscan.chain.unwrap_or_default().id(),
);

let url = url.join(&query)?;
let response = reqwest::get(url).await?;
if !response.status().is_success() {
eyre::bail!(
Expand Down Expand Up @@ -201,3 +204,18 @@ pub struct SourcifyResponseElement {
#[serde(rename = "storageTimestamp")]
storage_timestamp: Option<String>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_check_addresses_url() {
let url = Url::from_str("https://server-verify.hashscan.io").unwrap();
let url = url.join("check-by-addresses?addresses=0x1234&chainIds=1").unwrap();
assert_eq!(
url.as_str(),
"https://server-verify.hashscan.io/check-by-addresses?addresses=0x1234&chainIds=1"
);
}
}
Loading