mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-19 14:31:06 +00:00
Tidyup
This commit is contained in:
@@ -50,7 +50,6 @@ pub trait SolidityCompiler {
|
|||||||
/// The generic compilation input configuration.
|
/// The generic compilation input configuration.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct CompilerInput {
|
pub struct CompilerInput {
|
||||||
pub wasm: bool,
|
|
||||||
pub pipeline: Option<ModePipeline>,
|
pub pipeline: Option<ModePipeline>,
|
||||||
pub optimization: Option<ModeOptimizerSetting>,
|
pub optimization: Option<ModeOptimizerSetting>,
|
||||||
pub solc_version: Option<VersionReq>,
|
pub solc_version: Option<VersionReq>,
|
||||||
@@ -76,6 +75,12 @@ pub struct Compiler<T: SolidityCompiler> {
|
|||||||
additional_options: T::Options,
|
additional_options: T::Options,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Compiler<solc::Solc> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Compiler<T>
|
impl<T> Compiler<T>
|
||||||
where
|
where
|
||||||
T: SolidityCompiler,
|
T: SolidityCompiler,
|
||||||
@@ -83,7 +88,6 @@ where
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
input: CompilerInput {
|
input: CompilerInput {
|
||||||
wasm: Default::default(),
|
|
||||||
pipeline: Default::default(),
|
pipeline: Default::default(),
|
||||||
optimization: Default::default(),
|
optimization: Default::default(),
|
||||||
solc_version: Default::default(),
|
solc_version: Default::default(),
|
||||||
@@ -98,11 +102,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_wasm(mut self, value: bool) -> Self {
|
|
||||||
self.input.wasm = value;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_solc_version_req(mut self, value: impl Into<Option<VersionReq>>) -> Self {
|
pub fn with_solc_version_req(mut self, value: impl Into<Option<VersionReq>>) -> Self {
|
||||||
self.input.solc_version = value.into();
|
self.input.solc_version = value.into();
|
||||||
self
|
self
|
||||||
@@ -186,15 +185,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Default for Compiler<T>
|
|
||||||
where
|
|
||||||
T: SolidityCompiler,
|
|
||||||
{
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines how the compiler should handle revert strings.
|
/// Defines how the compiler should handle revert strings.
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
|||||||
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
|
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Resolc {
|
pub struct Resolc {
|
||||||
|
// Enable wasm compilation.
|
||||||
|
wasm: bool,
|
||||||
// Where to cache artifacts.
|
// Where to cache artifacts.
|
||||||
cache_directory: PathBuf,
|
cache_directory: PathBuf,
|
||||||
// We'll use this version when no explicit version
|
// We'll use this version when no explicit version
|
||||||
@@ -39,7 +41,6 @@ impl SolidityCompiler for Resolc {
|
|||||||
async fn build(
|
async fn build(
|
||||||
&self,
|
&self,
|
||||||
CompilerInput {
|
CompilerInput {
|
||||||
wasm,
|
|
||||||
pipeline,
|
pipeline,
|
||||||
optimization,
|
optimization,
|
||||||
solc_version,
|
solc_version,
|
||||||
@@ -62,9 +63,12 @@ impl SolidityCompiler for Resolc {
|
|||||||
|
|
||||||
let solc_version_req = solc_version
|
let solc_version_req = solc_version
|
||||||
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
|
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
|
||||||
let solc_path =
|
let solc_path = revive_dt_solc_binaries::download_solc(
|
||||||
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version_req, wasm)
|
&self.cache_directory,
|
||||||
.await?;
|
solc_version_req,
|
||||||
|
self.wasm,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
let solc_version = utils::solc_version(&solc_path).await?;
|
let solc_version = utils::solc_version(&solc_path).await?;
|
||||||
|
|
||||||
if solc_version < SOLC_VERSION_SUPPORTING_VIA_YUL_IR {
|
if solc_version < SOLC_VERSION_SUPPORTING_VIA_YUL_IR {
|
||||||
@@ -222,6 +226,7 @@ impl SolidityCompiler for Resolc {
|
|||||||
|
|
||||||
fn new(config: &Arguments) -> Self {
|
fn new(config: &Arguments) -> Self {
|
||||||
Resolc {
|
Resolc {
|
||||||
|
wasm: config.wasm,
|
||||||
cache_directory: config.directory().to_path_buf(),
|
cache_directory: config.directory().to_path_buf(),
|
||||||
solc_version: config.solc.clone(),
|
solc_version: config.solc.clone(),
|
||||||
resolc_path: config.resolc.clone(),
|
resolc_path: config.resolc.clone(),
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Solc {
|
pub struct Solc {
|
||||||
|
// Enable wasm compilation.
|
||||||
|
wasm: bool,
|
||||||
// Where to cache artifacts.
|
// Where to cache artifacts.
|
||||||
cache_directory: PathBuf,
|
cache_directory: PathBuf,
|
||||||
// We'll use this version when no explicit version requirement
|
// We'll use this version when no explicit version requirement
|
||||||
@@ -37,7 +39,6 @@ impl SolidityCompiler for Solc {
|
|||||||
async fn build(
|
async fn build(
|
||||||
&self,
|
&self,
|
||||||
CompilerInput {
|
CompilerInput {
|
||||||
wasm,
|
|
||||||
pipeline,
|
pipeline,
|
||||||
optimization,
|
optimization,
|
||||||
solc_version,
|
solc_version,
|
||||||
@@ -53,7 +54,7 @@ impl SolidityCompiler for Solc {
|
|||||||
let solc_version = solc_version
|
let solc_version = solc_version
|
||||||
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
|
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
|
||||||
let solc_path =
|
let solc_path =
|
||||||
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version, wasm)
|
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version, self.wasm)
|
||||||
.await?;
|
.await?;
|
||||||
let compiler_supports_via_ir =
|
let compiler_supports_via_ir =
|
||||||
utils::solc_version(&solc_path).await? >= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
|
utils::solc_version(&solc_path).await? >= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
|
||||||
@@ -208,6 +209,7 @@ impl SolidityCompiler for Solc {
|
|||||||
|
|
||||||
fn new(config: &Arguments) -> Self {
|
fn new(config: &Arguments) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
wasm: config.wasm,
|
||||||
cache_directory: config.directory().to_path_buf(),
|
cache_directory: config.directory().to_path_buf(),
|
||||||
solc_version: config.solc.clone(),
|
solc_version: config.solc.clone(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,24 +52,42 @@ pub async fn solc_version(solc_path: &Path) -> anyhow::Result<semver::Version> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn compiler_version_can_be_obtained() {
|
async fn compiler_version_can_be_obtained() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||||
let solc_path = revive_dt_solc_binaries::download_solc(
|
let solc_path =
|
||||||
temp_dir.path(),
|
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 7, 6), false)
|
||||||
VersionOrRequirement::default(),
|
.await
|
||||||
false,
|
.expect("can download solc");
|
||||||
)
|
|
||||||
.await
|
|
||||||
.expect("can download solc");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let version = solc_version(&solc_path).await;
|
let version = solc_version(&solc_path).await;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let _ = version.expect("Failed to get version");
|
assert_eq!(
|
||||||
|
version.expect("Failed to get version"),
|
||||||
|
Version::new(0, 7, 6)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn compiler_version_can_be_obtained1() {
|
||||||
|
// Arrange
|
||||||
|
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||||
|
let solc_path =
|
||||||
|
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 4, 21), false)
|
||||||
|
.await
|
||||||
|
.expect("can download solc");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let version = solc_version(&solc_path).await;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assert_eq!(
|
||||||
|
version.expect("Failed to get version"),
|
||||||
|
Version::new(0, 4, 21)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user