mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-24 22:48:04 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7ddb2da92 | |||
| 17b56a8155 | |||
| 8578862537 |
Generated
-1
@@ -4030,7 +4030,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"semver 1.0.26",
|
"semver 1.0.26",
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -11,4 +11,3 @@ rust-version.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
tokio = { workspace = true, default-features = false, features = ["time"] }
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
mod poll;
|
|
||||||
|
|
||||||
pub use poll::*;
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
use std::ops::ControlFlow;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
|
||||||
|
|
||||||
const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60);
|
|
||||||
|
|
||||||
/// A function that polls for a fallible future for some period of time and errors if it fails to
|
|
||||||
/// get a result after polling.
|
|
||||||
///
|
|
||||||
/// Given a future that returns a [`Result<ControlFlow<O, ()>>`], this function calls the future
|
|
||||||
/// repeatedly (with some wait period) until the future returns a [`ControlFlow::Break`] or until it
|
|
||||||
/// returns an [`Err`] in which case the function stops polling and returns the error.
|
|
||||||
///
|
|
||||||
/// If the future keeps returning [`ControlFlow::Continue`] and fails to return a [`Break`] within
|
|
||||||
/// the permitted polling duration then this function returns an [`Err`]
|
|
||||||
///
|
|
||||||
/// [`Break`]: ControlFlow::Break
|
|
||||||
/// [`Continue`]: ControlFlow::Continue
|
|
||||||
pub async fn poll<F, O>(
|
|
||||||
polling_duration: Duration,
|
|
||||||
polling_wait_behavior: PollingWaitBehavior,
|
|
||||||
mut future: impl FnMut() -> F,
|
|
||||||
) -> Result<O>
|
|
||||||
where
|
|
||||||
F: Future<Output = Result<ControlFlow<O, ()>>>,
|
|
||||||
{
|
|
||||||
let mut retries = 0;
|
|
||||||
let mut total_wait_duration = Duration::ZERO;
|
|
||||||
let max_allowed_wait_duration = polling_duration;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if total_wait_duration >= max_allowed_wait_duration {
|
|
||||||
break Err(anyhow!(
|
|
||||||
"Polling failed after {} retries and a total of {:?} of wait time",
|
|
||||||
retries,
|
|
||||||
total_wait_duration
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
match future().await? {
|
|
||||||
ControlFlow::Continue(()) => {
|
|
||||||
let next_wait_duration = match polling_wait_behavior {
|
|
||||||
PollingWaitBehavior::Constant(duration) => duration,
|
|
||||||
PollingWaitBehavior::ExponentialBackoff => {
|
|
||||||
Duration::from_secs(2u64.pow(retries))
|
|
||||||
.min(EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let next_wait_duration =
|
|
||||||
next_wait_duration.min(max_allowed_wait_duration - total_wait_duration);
|
|
||||||
total_wait_duration += next_wait_duration;
|
|
||||||
retries += 1;
|
|
||||||
|
|
||||||
tokio::time::sleep(next_wait_duration).await;
|
|
||||||
}
|
|
||||||
ControlFlow::Break(output) => {
|
|
||||||
break Ok(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
|
||||||
pub enum PollingWaitBehavior {
|
|
||||||
Constant(Duration),
|
|
||||||
#[default]
|
|
||||||
ExponentialBackoff,
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
//! the workspace can benefit from.
|
//! the workspace can benefit from.
|
||||||
|
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod futures;
|
|
||||||
pub mod iterators;
|
pub mod iterators;
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|||||||
@@ -238,25 +238,4 @@ 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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::marker::PhantomData;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use alloy::eips::BlockNumberOrTag;
|
use alloy::eips::BlockNumberOrTag;
|
||||||
use alloy::hex;
|
|
||||||
use alloy::json_abi::JsonAbi;
|
use alloy::json_abi::JsonAbi;
|
||||||
use alloy::network::{Ethereum, TransactionBuilder};
|
use alloy::network::{Ethereum, TransactionBuilder};
|
||||||
use alloy::primitives::{BlockNumber, U256};
|
use alloy::primitives::{BlockNumber, U256};
|
||||||
@@ -243,11 +242,6 @@ where
|
|||||||
) {
|
) {
|
||||||
let value = U256::from_be_slice(output_word);
|
let value = U256::from_be_slice(output_word);
|
||||||
self.variables.insert(variable_name.clone(), value);
|
self.variables.insert(variable_name.clone(), value);
|
||||||
tracing::info!(
|
|
||||||
variable_name,
|
|
||||||
variable_value = hex::encode(value.to_be_bytes::<32>()),
|
|
||||||
"Assigned variable"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+3
-28
@@ -162,20 +162,6 @@ where
|
|||||||
Some(false) | None => true,
|
Some(false) | None => true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.filter(
|
|
||||||
|(metadata_file_path, _, case_idx, case, _)| match case.ignore {
|
|
||||||
Some(true) => {
|
|
||||||
tracing::warn!(
|
|
||||||
metadata_file_path = %metadata_file_path.display(),
|
|
||||||
case_idx,
|
|
||||||
case_name = ?case.name,
|
|
||||||
"Ignoring case"
|
|
||||||
);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
Some(false) | None => true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let metadata_case_status = Arc::new(RwLock::new(test_cases.iter().fold(
|
let metadata_case_status = Arc::new(RwLock::new(test_cases.iter().fold(
|
||||||
@@ -248,10 +234,10 @@ where
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
case_status.sort_by(|a, b| a.0.cmp(&b.0));
|
case_status.sort_by(|a, b| a.0.cmp(&b.0));
|
||||||
for (case_idx, case_name, case_status) in case_status.into_iter() {
|
for (_, case_name, case_status) in case_status.into_iter() {
|
||||||
if case_status {
|
if case_status {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
" {GREEN}Case Succeeded:{RESET} {} - Case Idx: {case_idx}",
|
"{GREEN} Case Succeeded:{RESET} {}",
|
||||||
case_name
|
case_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|string| string.as_str())
|
.map(|string| string.as_str())
|
||||||
@@ -259,7 +245,7 @@ where
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
" {RED}Case Failed:{RESET} {} - Case Idx: {case_idx}",
|
"{RED} Case Failed:{RESET} {}",
|
||||||
case_name
|
case_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|string| string.as_str())
|
.map(|string| string.as_str())
|
||||||
@@ -477,17 +463,6 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::info!(
|
|
||||||
?library_instance,
|
|
||||||
library_address = ?leader_receipt.contract_address,
|
|
||||||
"Deployed library to leader"
|
|
||||||
);
|
|
||||||
tracing::info!(
|
|
||||||
?library_instance,
|
|
||||||
library_address = ?follower_receipt.contract_address,
|
|
||||||
"Deployed library to follower"
|
|
||||||
);
|
|
||||||
|
|
||||||
let Some(leader_library_address) = leader_receipt.contract_address else {
|
let Some(leader_library_address) = leader_receipt.contract_address else {
|
||||||
tracing::error!("Contract deployment transaction didn't return an address");
|
tracing::error!("Contract deployment transaction didn't return an address");
|
||||||
anyhow::bail!("Contract deployment didn't return an address");
|
anyhow::bail!("Contract deployment didn't return an address");
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ pub struct Case {
|
|||||||
pub inputs: Vec<Input>,
|
pub inputs: Vec<Input>,
|
||||||
pub group: Option<String>,
|
pub group: Option<String>,
|
||||||
pub expected: Option<Expected>,
|
pub expected: Option<Expected>,
|
||||||
pub ignore: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Case {
|
impl Case {
|
||||||
|
|||||||
+55
-74
@@ -3,13 +3,9 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{File, OpenOptions, create_dir_all, remove_dir_all},
|
fs::{File, OpenOptions, create_dir_all, remove_dir_all},
|
||||||
io::{BufRead, BufReader, Read, Write},
|
io::{BufRead, BufReader, Read, Write},
|
||||||
ops::ControlFlow,
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::{Child, Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
sync::{
|
sync::atomic::{AtomicU32, Ordering},
|
||||||
Arc,
|
|
||||||
atomic::{AtomicU32, Ordering},
|
|
||||||
},
|
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,12 +25,11 @@ use alloy::{
|
|||||||
},
|
},
|
||||||
signers::local::PrivateKeySigner,
|
signers::local::PrivateKeySigner,
|
||||||
};
|
};
|
||||||
use tracing::{Instrument, Level};
|
use revive_dt_common::fs::clear_directory;
|
||||||
|
|
||||||
use revive_dt_common::{fs::clear_directory, futures::poll};
|
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_dt_format::traits::ResolverApi;
|
use revive_dt_format::traits::ResolverApi;
|
||||||
use revive_dt_node_interaction::EthereumNode;
|
use revive_dt_node_interaction::EthereumNode;
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE};
|
use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE};
|
||||||
|
|
||||||
@@ -82,10 +77,6 @@ impl GethNode {
|
|||||||
const GETH_STDERR_LOG_FILE_NAME: &str = "node_stderr.log";
|
const GETH_STDERR_LOG_FILE_NAME: &str = "node_stderr.log";
|
||||||
|
|
||||||
const TRANSACTION_INDEXING_ERROR: &str = "transaction indexing is in progress";
|
const TRANSACTION_INDEXING_ERROR: &str = "transaction indexing is in progress";
|
||||||
const TRANSACTION_TRACING_ERROR: &str = "historical state not available in path scheme yet";
|
|
||||||
|
|
||||||
const RECEIPT_POLLING_DURATION: Duration = Duration::from_secs(5 * 60);
|
|
||||||
const TRACE_POLLING_DURATION: Duration = Duration::from_secs(60);
|
|
||||||
|
|
||||||
/// Create the node directory and call `geth init` to configure the genesis.
|
/// Create the node directory and call `geth init` to configure the genesis.
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
@@ -111,8 +102,6 @@ impl GethNode {
|
|||||||
serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
|
serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
|
||||||
|
|
||||||
let mut child = Command::new(&self.geth)
|
let mut child = Command::new(&self.geth)
|
||||||
.arg("--state.scheme")
|
|
||||||
.arg("hash")
|
|
||||||
.arg("init")
|
.arg("init")
|
||||||
.arg("--datadir")
|
.arg("--datadir")
|
||||||
.arg(&self.data_directory)
|
.arg(&self.data_directory)
|
||||||
@@ -170,12 +159,6 @@ impl GethNode {
|
|||||||
.arg("0")
|
.arg("0")
|
||||||
.arg("--cache.blocklogs")
|
.arg("--cache.blocklogs")
|
||||||
.arg("512")
|
.arg("512")
|
||||||
.arg("--state.scheme")
|
|
||||||
.arg("hash")
|
|
||||||
.arg("--syncmode")
|
|
||||||
.arg("full")
|
|
||||||
.arg("--gcmode")
|
|
||||||
.arg("archive")
|
|
||||||
.stderr(stderr_logs_file.try_clone()?)
|
.stderr(stderr_logs_file.try_clone()?)
|
||||||
.stdout(stdout_logs_file.try_clone()?)
|
.stdout(stdout_logs_file.try_clone()?)
|
||||||
.spawn()?
|
.spawn()?
|
||||||
@@ -265,16 +248,21 @@ impl GethNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EthereumNode for GethNode {
|
impl EthereumNode for GethNode {
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn execute_transaction(
|
async fn execute_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: TransactionRequest,
|
transaction: TransactionRequest,
|
||||||
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
|
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
|
||||||
let span = tracing::debug_span!("Submitting transaction", ?transaction);
|
let outer_span = tracing::debug_span!("Submitting transaction", ?transaction);
|
||||||
let _guard = span.enter();
|
let _outer_guard = outer_span.enter();
|
||||||
|
|
||||||
let provider = Arc::new(self.provider().await?);
|
let provider = self.provider().await?;
|
||||||
let transaction_hash = *provider.send_transaction(transaction).await?.tx_hash();
|
|
||||||
|
let pending_transaction = provider.send_transaction(transaction).await?;
|
||||||
|
let transaction_hash = pending_transaction.tx_hash();
|
||||||
|
|
||||||
|
let span = tracing::info_span!("Awaiting transaction receipt", ?transaction_hash);
|
||||||
|
let _guard = span.enter();
|
||||||
|
|
||||||
// The following is a fix for the "transaction indexing is in progress" error that we
|
// The following is a fix for the "transaction indexing is in progress" error that we
|
||||||
// used to get. You can find more information on this in the following GH issue in geth
|
// used to get. You can find more information on this in the following GH issue in geth
|
||||||
@@ -294,64 +282,57 @@ impl EthereumNode for GethNode {
|
|||||||
// allow for a larger wait time. Therefore, in here we allow for 5 minutes of waiting
|
// allow for a larger wait time. Therefore, in here we allow for 5 minutes of waiting
|
||||||
// with exponential backoff each time we attempt to get the receipt and find that it's
|
// with exponential backoff each time we attempt to get the receipt and find that it's
|
||||||
// not available.
|
// not available.
|
||||||
poll(
|
let mut retries = 0;
|
||||||
Self::RECEIPT_POLLING_DURATION,
|
let mut total_wait_duration = Duration::from_secs(0);
|
||||||
Default::default(),
|
let max_allowed_wait_duration = Duration::from_secs(5 * 60);
|
||||||
move || {
|
loop {
|
||||||
let provider = provider.clone();
|
if total_wait_duration >= max_allowed_wait_duration {
|
||||||
async move {
|
tracing::error!(
|
||||||
match provider.get_transaction_receipt(transaction_hash).await {
|
?total_wait_duration,
|
||||||
Ok(Some(receipt)) => Ok(ControlFlow::Break(receipt)),
|
?max_allowed_wait_duration,
|
||||||
Ok(None) => Ok(ControlFlow::Continue(())),
|
retry_count = retries,
|
||||||
Err(error) => {
|
"Failed to get receipt after polling for it"
|
||||||
let error_string = error.to_string();
|
);
|
||||||
match error_string.contains(Self::TRANSACTION_INDEXING_ERROR) {
|
anyhow::bail!(
|
||||||
true => Ok(ControlFlow::Continue(())),
|
"Polled for receipt for {total_wait_duration:?} but failed to get it"
|
||||||
false => Err(error.into()),
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
match provider.get_transaction_receipt(*transaction_hash).await {
|
||||||
|
Ok(Some(receipt)) => {
|
||||||
|
tracing::info!(?total_wait_duration, "Found receipt");
|
||||||
|
break Ok(receipt);
|
||||||
|
}
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(error) => {
|
||||||
|
let error_string = error.to_string();
|
||||||
|
if !error_string.contains(Self::TRANSACTION_INDEXING_ERROR) {
|
||||||
|
break Err(error.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
)
|
|
||||||
.instrument(tracing::info_span!(
|
let next_wait_duration = Duration::from_secs(2u64.pow(retries))
|
||||||
"Awaiting transaction receipt",
|
.min(max_allowed_wait_duration - total_wait_duration);
|
||||||
?transaction_hash
|
total_wait_duration += next_wait_duration;
|
||||||
))
|
retries += 1;
|
||||||
.await
|
|
||||||
|
tokio::time::sleep(next_wait_duration).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn trace_transaction(
|
async fn trace_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: &TransactionReceipt,
|
transaction: &TransactionReceipt,
|
||||||
trace_options: GethDebugTracingOptions,
|
trace_options: GethDebugTracingOptions,
|
||||||
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
||||||
let provider = Arc::new(self.provider().await?);
|
let tx_hash = transaction.transaction_hash;
|
||||||
poll(
|
Ok(self
|
||||||
Self::TRACE_POLLING_DURATION,
|
.provider()
|
||||||
Default::default(),
|
.await?
|
||||||
move || {
|
.debug_trace_transaction(tx_hash, trace_options)
|
||||||
let provider = provider.clone();
|
.await?)
|
||||||
let trace_options = trace_options.clone();
|
|
||||||
async move {
|
|
||||||
match provider
|
|
||||||
.debug_trace_transaction(transaction.transaction_hash, trace_options)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(trace) => Ok(ControlFlow::Break(trace)),
|
|
||||||
Err(error) => {
|
|
||||||
let error_string = error.to_string();
|
|
||||||
match error_string.contains(Self::TRANSACTION_TRACING_ERROR) {
|
|
||||||
true => Ok(ControlFlow::Continue(())),
|
|
||||||
false => Err(error.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ use std::{
|
|||||||
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::download::SolcDownloader;
|
use crate::download::GHDownloader;
|
||||||
|
|
||||||
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: &SolcDownloader,
|
downloader: &GHDownloader,
|
||||||
) -> 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: &SolcDownloader) -> anyhow::Result<()> {
|
async fn download_to_file(path: &Path, downloader: &GHDownloader) -> 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 the official SolidityLang site
|
/// Download solc binaries from GitHub releases (IPFS links aren't reliable).
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SolcDownloader {
|
pub struct GHDownloader {
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
pub target: &'static str,
|
pub target: &'static str,
|
||||||
pub list: &'static str,
|
pub list: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SolcDownloader {
|
impl GHDownloader {
|
||||||
pub const BASE_URL: &str = "https://binaries.soliditylang.org";
|
pub const BASE_URL: &str = "https://github.com/ethereum/solidity/releases/download";
|
||||||
|
|
||||||
pub const LINUX_NAME: &str = "linux-amd64";
|
pub const LINUX_NAME: &str = "solc-static-linux";
|
||||||
pub const MACOSX_NAME: &str = "macosx-amd64";
|
pub const MACOSX_NAME: &str = "solc-macos";
|
||||||
pub const WINDOWS_NAME: &str = "windows-amd64";
|
pub const WINDOWS_NAME: &str = "solc-windows.exe";
|
||||||
pub const WASM_NAME: &str = "wasm";
|
pub const WASM_NAME: &str = "soljson.js";
|
||||||
|
|
||||||
async fn new(
|
async fn new(
|
||||||
version: impl Into<VersionOrRequirement>,
|
version: impl Into<VersionOrRequirement>,
|
||||||
@@ -102,27 +102,26 @@ impl SolcDownloader {
|
|||||||
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 builds = List::download(self.list).await?.builds;
|
let expected_digest = List::download(self.list)
|
||||||
let build = builds
|
.await?
|
||||||
|
.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 path = build.path.clone();
|
let file = reqwest::get(self.url()).await?.bytes().await?.to_vec();
|
||||||
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);
|
||||||
@@ -134,7 +133,7 @@ impl SolcDownloader {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{download::SolcDownloader, list::List};
|
use crate::{download::GHDownloader, list::List};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn try_get_windows() {
|
async fn try_get_windows() {
|
||||||
@@ -142,7 +141,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
SolcDownloader::windows(version)
|
GHDownloader::windows(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -156,7 +155,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
SolcDownloader::macosx(version)
|
GHDownloader::macosx(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -170,7 +169,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.latest_release;
|
.latest_release;
|
||||||
SolcDownloader::linux(version)
|
GHDownloader::linux(version)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.download()
|
.download()
|
||||||
@@ -181,7 +180,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;
|
||||||
SolcDownloader::wasm(version)
|
GHDownloader::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::SolcDownloader;
|
use download::GHDownloader;
|
||||||
|
|
||||||
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 {
|
||||||
SolcDownloader::wasm(version).await
|
GHDownloader::wasm(version).await
|
||||||
} else if cfg!(target_os = "linux") {
|
} else if cfg!(target_os = "linux") {
|
||||||
SolcDownloader::linux(version).await
|
GHDownloader::linux(version).await
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
SolcDownloader::macosx(version).await
|
GHDownloader::macosx(version).await
|
||||||
} else if cfg!(target_os = "windows") {
|
} else if cfg!(target_os = "windows") {
|
||||||
SolcDownloader::windows(version).await
|
GHDownloader::windows(version).await
|
||||||
} else {
|
} else {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}?;
|
}?;
|
||||||
|
|||||||
Reference in New Issue
Block a user