Skip to content

Commit

Permalink
fix: use join for check-by-address path (#7062)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 9, 2024
1 parent 0840762 commit 6be2e77
Showing 1 changed file with 22 additions and 4 deletions.
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"
);
}
}

0 comments on commit 6be2e77

Please sign in to comment.