mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-13 04:41:11 +00:00
the solc download per target helper
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -4,10 +4,12 @@ use alloy::primitives::{Address, map::HashMap};
|
||||
use revive_dt_compiler::{Compiler, CompilerInput, SolidityCompiler};
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_format::{
|
||||
case::Case,
|
||||
metadata::Metadata,
|
||||
mode::{Mode, SolcMode},
|
||||
};
|
||||
use revive_dt_node::Node;
|
||||
use revive_dt_solc_binaries::download_solc;
|
||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||
use semver::Version;
|
||||
|
||||
@@ -18,54 +20,48 @@ type Contracts<T> = HashMap<
|
||||
SolcStandardJsonOutput,
|
||||
>;
|
||||
|
||||
pub struct State<T: Platform> {
|
||||
pub struct State<'a, T: Platform> {
|
||||
config: &'a Arguments,
|
||||
contracts: Contracts<T>,
|
||||
deployed_contracts: HashMap<String, Address>,
|
||||
node: T::Blockchain,
|
||||
}
|
||||
|
||||
impl<T> State<T>
|
||||
impl<'a, T> State<'a, T>
|
||||
where
|
||||
T: Platform,
|
||||
{
|
||||
fn new(config: &Arguments) -> Self {
|
||||
fn new(config: &'a Arguments) -> Self {
|
||||
Self {
|
||||
config,
|
||||
contracts: Default::default(),
|
||||
deployed_contracts: Default::default(),
|
||||
node: <T::Blockchain as Node>::new(config),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_contracts(&mut self, metadata: &Metadata) -> anyhow::Result<()> {
|
||||
pub fn build_contracts(&mut self, mode: &SolcMode, metadata: &Metadata) -> anyhow::Result<()> {
|
||||
let sources = metadata.contract_sources()?;
|
||||
let base_path = metadata.directory()?.display().to_string();
|
||||
let modes = metadata
|
||||
.modes
|
||||
.to_owned()
|
||||
.unwrap_or_else(|| vec![Mode::Solidity(Default::default())]);
|
||||
|
||||
let mut result = HashMap::new();
|
||||
for mode in modes {
|
||||
let mut compiler = Compiler::<T::Compiler>::new().base_path(base_path.clone());
|
||||
for (file, _contract) in sources.values() {
|
||||
compiler = compiler.with_source(file)?;
|
||||
}
|
||||
|
||||
match mode {
|
||||
Mode::Solidity(SolcMode {
|
||||
solc_version: _,
|
||||
solc_optimize,
|
||||
llvm_optimizer_settings: _,
|
||||
}) => {
|
||||
let optimizer = solc_optimize.unwrap_or(true);
|
||||
let version = Version::new(0, 8, 29);
|
||||
let output = compiler.solc_optimizer(optimizer).try_build(&version)?;
|
||||
result.insert(output.input, output.output);
|
||||
}
|
||||
Mode::Unknown(mode) => log::debug!("compiler: ignoring unknown mode '{mode}'"),
|
||||
}
|
||||
let mut compiler = Compiler::<T::Compiler>::new().base_path(base_path.clone());
|
||||
for (file, _contract) in sources.values() {
|
||||
compiler = compiler.with_source(file)?;
|
||||
}
|
||||
|
||||
let version = Version::new(0, 8, 29);
|
||||
let solc_path = download_solc(self.config.directory(), version, self.config.wasm)?;
|
||||
let output = compiler
|
||||
.solc_optimizer(mode.solc_optimize())
|
||||
.try_build(solc_path)?;
|
||||
self.contracts.insert(output.input, output.output);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn execute_case(&mut self, case: &Case) -> anyhow::Result<()> {
|
||||
for input in &case.inputs {}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -73,8 +69,8 @@ where
|
||||
pub struct Driver<'a, Leader: Platform, Follower: Platform> {
|
||||
metadata: &'a Metadata,
|
||||
config: &'a Arguments,
|
||||
leader: State<Leader>,
|
||||
follower: State<Follower>,
|
||||
leader: State<'a, Leader>,
|
||||
follower: State<'a, Follower>,
|
||||
}
|
||||
|
||||
impl<'a, L, F> Driver<'a, L, F>
|
||||
@@ -92,13 +88,36 @@ where
|
||||
}
|
||||
|
||||
pub fn execute(&mut self) -> anyhow::Result<()> {
|
||||
self.leader.build_contracts(self.metadata)?;
|
||||
self.follower.build_contracts(self.metadata)?;
|
||||
for mode in self.modes() {
|
||||
self.leader.build_contracts(&mode, self.metadata)?;
|
||||
self.follower.build_contracts(&mode, self.metadata)?;
|
||||
|
||||
if self.config.compile_only {
|
||||
return Ok(());
|
||||
if self.config.compile_only {
|
||||
continue;
|
||||
}
|
||||
|
||||
for case in &self.metadata.cases {
|
||||
self.leader.execute_case(case)?;
|
||||
}
|
||||
|
||||
*self = Self::new(self.metadata, self.config);
|
||||
}
|
||||
|
||||
todo!()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn modes(&self) -> Vec<SolcMode> {
|
||||
self.metadata
|
||||
.modes()
|
||||
.iter()
|
||||
.filter_map(|mode| match mode {
|
||||
Mode::Solidity(solc_mode) => Some(solc_mode),
|
||||
Mode::Unknown(mode) => {
|
||||
log::debug!("compiler: ignoring unknown mode '{mode}'");
|
||||
None
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ fn main() -> anyhow::Result<()> {
|
||||
if args.corpus.is_empty() {
|
||||
anyhow::bail!("no test corpus specified");
|
||||
}
|
||||
let temp_dir = TempDir::new()?;
|
||||
args.working_directory.get_or_insert(temp_dir.path().into());
|
||||
if args.working_directory.is_none() {
|
||||
args.temp_dir = TempDir::new()?.into()
|
||||
}
|
||||
|
||||
for path in args.corpus.iter().collect::<BTreeSet<_>>() {
|
||||
log::trace!("attempting corpus {path:?}");
|
||||
@@ -38,7 +39,7 @@ fn main() -> anyhow::Result<()> {
|
||||
Ok(build) => {
|
||||
log::info!(
|
||||
"metadata {} success",
|
||||
metadata.file_path.as_ref().unwrap().display()
|
||||
metadata.directory().as_ref().unwrap().display()
|
||||
);
|
||||
build
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user