mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-12 20:31:10 +00:00
the solc github releases downloader
Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
Generated
+2
@@ -2877,10 +2877,12 @@ name = "revive-dt-solc-binaries"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"hex",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"semver 1.0.26",
|
"semver 1.0.26",
|
||||||
"serde",
|
"serde",
|
||||||
|
"sha2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ once_cell = "1.21"
|
|||||||
semver = {version = "1.0", features = ["serde"] }
|
semver = {version = "1.0", features = ["serde"] }
|
||||||
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
||||||
serde_json = { version = "1.0", default-features = false, features = ["arbitrary_precision", "std"] }
|
serde_json = { version = "1.0", default-features = false, features = ["arbitrary_precision", "std"] }
|
||||||
|
sha2 = { version = "0.10.8" }
|
||||||
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
||||||
|
|
||||||
# revive compiler
|
# revive compiler
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
//! Implements the [SolidityCompiler] trait with revive Wasm for
|
//! Implements the [crate::SolidityCompiler] trait with revive Wasm for
|
||||||
//! compiling contracts to PVM bytecode (via Wasm).
|
//! compiling contracts to PVM bytecode (via Wasm).
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
//! Implements the [SolidityCompiler] trait with resolc for
|
//! Implements the [crate::SolidityCompiler] trait with resolc for
|
||||||
//! compiling contracts to PVM bytecode.
|
//! compiling contracts to PVM bytecode.
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ download = ["reqwest"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
hex = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
once_cell = { workspace = true }
|
||||||
reqwest = { workspace = true, optional = true }
|
reqwest = { workspace = true, optional = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
sha2 = { workspace = true }
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
use std::{collections::HashMap, sync::Mutex};
|
use std::{collections::HashMap, sync::Mutex};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use semver::Version;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
use crate::list::List;
|
use crate::list::List;
|
||||||
|
|
||||||
@@ -31,31 +33,113 @@ impl List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
/// Download solc binaries from GitHub releases (IPFS links aren't reliable).
|
||||||
mod tests {
|
pub struct GHDownloader {
|
||||||
use crate::list::List;
|
version: Version,
|
||||||
|
target: &'static str,
|
||||||
|
list: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
impl GHDownloader {
|
||||||
fn try_get_windows_list() {
|
pub const BASE_URL: &str = "https://github.com/ethereum/solidity/releases/download";
|
||||||
List::download(List::WINDOWS_URL).unwrap();
|
|
||||||
List::download(List::WINDOWS_URL).unwrap();
|
pub const LINUX_NAME: &str = "solc-static-linux";
|
||||||
|
pub const MACOSX_NAME: &str = "solc-macos";
|
||||||
|
pub const WINDOWS_NAME: &str = "solc-windows.exe";
|
||||||
|
pub const WASM_NAME: &str = "soljson.js";
|
||||||
|
|
||||||
|
pub fn linux(version: Version) -> Self {
|
||||||
|
Self {
|
||||||
|
version,
|
||||||
|
target: Self::LINUX_NAME,
|
||||||
|
list: List::LINUX_URL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
pub fn macosx(version: Version) -> Self {
|
||||||
fn try_get_macosx_list() {
|
Self {
|
||||||
List::download(List::MACOSX_URL).unwrap();
|
version,
|
||||||
List::download(List::MACOSX_URL).unwrap();
|
target: Self::MACOSX_NAME,
|
||||||
|
list: List::MACOSX_URL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
pub fn windows(version: Version) -> Self {
|
||||||
fn try_get_linux_list() {
|
Self {
|
||||||
List::download(List::LINUX_URL).unwrap();
|
version,
|
||||||
List::download(List::LINUX_URL).unwrap();
|
target: Self::WINDOWS_NAME,
|
||||||
|
list: List::WINDOWS_URL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
pub fn wasm(version: Version) -> Self {
|
||||||
fn try_get_wasm_list() {
|
Self {
|
||||||
List::download(List::WASM_URL).unwrap();
|
version,
|
||||||
List::download(List::WASM_URL).unwrap();
|
target: Self::WASM_NAME,
|
||||||
|
list: List::WASM_URL,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download the solc binary.
|
||||||
|
///
|
||||||
|
/// Errors out if the download fails or the digest of the downloaded file
|
||||||
|
/// mismatches the expected digest from the release [List].
|
||||||
|
pub fn download(&self) -> anyhow::Result<Vec<u8>> {
|
||||||
|
let expected_digest = List::download(self.list)?
|
||||||
|
.builds
|
||||||
|
.iter()
|
||||||
|
.find(|build| build.version == 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 url = format!("{}/v{}/{}", Self::BASE_URL, self.version, self.target);
|
||||||
|
let file = reqwest::blocking::get(&url)?.bytes()?.to_vec();
|
||||||
|
|
||||||
|
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
||||||
|
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{download::GHDownloader, list::List};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn try_get_windows() {
|
||||||
|
let version = List::download(List::WINDOWS_URL)
|
||||||
|
.unwrap()
|
||||||
|
.latest_release
|
||||||
|
.into();
|
||||||
|
GHDownloader::windows(version).download().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn try_get_macosx() {
|
||||||
|
let version = List::download(List::MACOSX_URL)
|
||||||
|
.unwrap()
|
||||||
|
.latest_release
|
||||||
|
.into();
|
||||||
|
GHDownloader::macosx(version).download().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn try_get_linux() {
|
||||||
|
let version = List::download(List::LINUX_URL)
|
||||||
|
.unwrap()
|
||||||
|
.latest_release
|
||||||
|
.into();
|
||||||
|
GHDownloader::linux(version).download().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn try_get_wasm() {
|
||||||
|
let version = List::download(List::WASM_URL)
|
||||||
|
.unwrap()
|
||||||
|
.latest_release
|
||||||
|
.into();
|
||||||
|
GHDownloader::wasm(version).download().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub struct Build {
|
|||||||
pub build: String,
|
pub build: String,
|
||||||
#[serde(rename = "longVersion")]
|
#[serde(rename = "longVersion")]
|
||||||
pub long_version: String,
|
pub long_version: String,
|
||||||
keccak256: String,
|
pub keccak256: String,
|
||||||
sha256: String,
|
pub sha256: String,
|
||||||
urls: Vec<String>,
|
pub urls: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user