mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-22 21:57:58 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa1b5621dd |
@@ -238,4 +238,25 @@ mod test {
|
|||||||
Version::new(0, 7, 6)
|
Version::new(0, 7, 6)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn compiler_version_can_be_obtained1() {
|
||||||
|
// Arrange
|
||||||
|
let args = Arguments::default();
|
||||||
|
println!("Getting compiler path");
|
||||||
|
let path = Solc::get_compiler_executable(&args, Version::new(0, 4, 21))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
println!("Got compiler path");
|
||||||
|
let compiler = Solc::new(path);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let version = compiler.version();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assert_eq!(
|
||||||
|
version.expect("Failed to get version"),
|
||||||
|
Version::new(0, 4, 21)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ use std::{
|
|||||||
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::download::GHDownloader;
|
use crate::download::SolcDownloader;
|
||||||
|
|
||||||
pub const SOLC_CACHE_DIRECTORY: &str = "solc";
|
pub const SOLC_CACHE_DIRECTORY: &str = "solc";
|
||||||
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
|
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
|
||||||
|
|
||||||
pub(crate) async fn get_or_download(
|
pub(crate) async fn get_or_download(
|
||||||
working_directory: &Path,
|
working_directory: &Path,
|
||||||
downloader: &GHDownloader,
|
downloader: &SolcDownloader,
|
||||||
) -> anyhow::Result<PathBuf> {
|
) -> anyhow::Result<PathBuf> {
|
||||||
let target_directory = working_directory
|
let target_directory = working_directory
|
||||||
.join(SOLC_CACHE_DIRECTORY)
|
.join(SOLC_CACHE_DIRECTORY)
|
||||||
@@ -38,7 +38,7 @@ pub(crate) async fn get_or_download(
|
|||||||
Ok(target_file)
|
Ok(target_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_to_file(path: &Path, downloader: &GHDownloader) -> anyhow::Result<()> {
|
async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::Result<()> {
|
||||||
tracing::info!("caching file: {}", path.display());
|
tracing::info!("caching file: {}", path.display());
|
||||||
|
|
||||||
let Ok(file) = File::create_new(path) else {
|
let Ok(file) = File::create_new(path) else {
|
||||||
|
|||||||
@@ -38,21 +38,21 @@ impl List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Download solc binaries from GitHub releases (IPFS links aren't reliable).
|
/// Download solc binaries from the official SolidityLang site
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct GHDownloader {
|
pub struct SolcDownloader {
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
pub target: &'static str,
|
pub target: &'static str,
|
||||||
pub list: &'static str,
|
pub list: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GHDownloader {
|
impl SolcDownloader {
|
||||||
pub const BASE_URL: &str = "https://github.com/ethereum/solidity/releases/download";
|
pub const BASE_URL: &str = "https://binaries.soliditylang.org";
|
||||||
|
|
||||||
pub const LINUX_NAME: &str = "solc-static-linux";
|
pub const LINUX_NAME: &str = "linux-amd64";
|
||||||
pub const MACOSX_NAME: &str = "solc-macos";
|
pub const MACOSX_NAME: &str = "macosx-amd64";
|
||||||
pub const WINDOWS_NAME: &str = "solc-windows.exe";
|
pub const WINDOWS_NAME: &str = "windows-amd64";
|
||||||
pub const WASM_NAME: &str = "soljson.js";
|
pub const WASM_NAME: &str = "wasm";
|
||||||
|
|
||||||
async fn new(
|
async fn new(
|
||||||
version: impl Into<VersionOrRequirement>,
|
version: impl Into<VersionOrRequirement>,
|
||||||
@@ -102,26 +102,27 @@ impl GHDownloader {
|
|||||||
Self::new(version, Self::WASM_NAME, List::WASM_URL).await
|
Self::new(version, Self::WASM_NAME, List::WASM_URL).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the download link.
|
|
||||||
pub fn url(&self) -> String {
|
|
||||||
format!("{}/v{}/{}", Self::BASE_URL, &self.version, &self.target)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Download the solc binary.
|
/// Download the solc binary.
|
||||||
///
|
///
|
||||||
/// Errors out if the download fails or the digest of the downloaded file
|
/// Errors out if the download fails or the digest of the downloaded file
|
||||||
/// mismatches the expected digest from the release [List].
|
/// mismatches the expected digest from the release [List].
|
||||||
pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
|
pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
|
||||||
tracing::info!("downloading solc: {self:?}");
|
tracing::info!("downloading solc: {self:?}");
|
||||||
let expected_digest = List::download(self.list)
|
let builds = List::download(self.list).await?.builds;
|
||||||
.await?
|
let build = builds
|
||||||
.builds
|
|
||||||
.iter()
|
.iter()
|
||||||
.find(|build| build.version == self.version)
|
.find(|build| build.version == self.version)
|
||||||
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))
|
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))?;
|
||||||
.map(|b| b.sha256.strip_prefix("0x").unwrap_or(&b.sha256).to_string())?;
|
|
||||||
|
|
||||||
let file = reqwest::get(self.url()).await?.bytes().await?.to_vec();
|
let path = build.path.clone();
|
||||||
|
let expected_digest = build
|
||||||
|
.sha256
|
||||||
|
.strip_prefix("0x")
|
||||||
|
.unwrap_or(&build.sha256)
|
||||||
|
.to_string();
|
||||||
|
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
|
||||||
|
|
||||||
|
let file = reqwest::get(url).await?.bytes().await?.to_vec();
|
||||||
|
|
||||||
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
||||||
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
||||||
@@ -133,7 +134,7 @@ impl GHDownloader {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{download::GHDownloader, list::List};
|
use crate::{download::SolcDownloader, list::List};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn try_get_windows() {
|
async fn try_get_windows() {
|
||||||
@@ -141,7 +142,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
GHDownloader::windows(version)
|
SolcDownloader::windows(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -155,7 +156,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
GHDownloader::macosx(version)
|
SolcDownloader::macosx(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -169,7 +170,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
GHDownloader::linux(version)
|
SolcDownloader::linux(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -180,7 +181,7 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn try_get_wasm() {
|
async fn try_get_wasm() {
|
||||||
let version = List::download(List::WASM_URL).await.unwrap().latest_release;
|
let version = List::download(List::WASM_URL).await.unwrap().latest_release;
|
||||||
GHDownloader::wasm(version)
|
SolcDownloader::wasm(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use cache::get_or_download;
|
use cache::get_or_download;
|
||||||
use download::GHDownloader;
|
use download::SolcDownloader;
|
||||||
|
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
use revive_dt_common::types::VersionOrRequirement;
|
||||||
|
|
||||||
@@ -25,13 +25,13 @@ pub async fn download_solc(
|
|||||||
wasm: bool,
|
wasm: bool,
|
||||||
) -> anyhow::Result<PathBuf> {
|
) -> anyhow::Result<PathBuf> {
|
||||||
let downloader = if wasm {
|
let downloader = if wasm {
|
||||||
GHDownloader::wasm(version).await
|
SolcDownloader::wasm(version).await
|
||||||
} else if cfg!(target_os = "linux") {
|
} else if cfg!(target_os = "linux") {
|
||||||
GHDownloader::linux(version).await
|
SolcDownloader::linux(version).await
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
GHDownloader::macosx(version).await
|
SolcDownloader::macosx(version).await
|
||||||
} else if cfg!(target_os = "windows") {
|
} else if cfg!(target_os = "windows") {
|
||||||
GHDownloader::windows(version).await
|
SolcDownloader::windows(version).await
|
||||||
} else {
|
} else {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}?;
|
}?;
|
||||||
|
|||||||
Reference in New Issue
Block a user