mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-13 01:41:00 +00:00
resolc: fix the Yul test utils (#413)
- Fixes multiple bugs in the Yul test util helpers. - The simple Yul builder utility helper now returns the contract builds. Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
@@ -241,47 +241,52 @@ pub fn build_solidity_and_detect_missing_libraries<T: ToString>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the Yul project can be built without errors.
|
/// Checks if the Yul project can be built without errors.
|
||||||
pub fn build_yul<T: ToString + Display>(sources: &[(T, T)]) -> anyhow::Result<()> {
|
pub fn build_yul<T: ToString + Display>(
|
||||||
|
sources: &[(T, T)],
|
||||||
|
) -> anyhow::Result<BTreeMap<String, Vec<u8>>> {
|
||||||
check_dependencies();
|
check_dependencies();
|
||||||
|
|
||||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||||
initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]);
|
initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]);
|
||||||
let optimizer_settings = OptimizerSettings::none();
|
|
||||||
|
|
||||||
let sources = sources
|
let _ = crate::process::native_process::EXECUTABLE
|
||||||
.iter()
|
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||||
.map(|(path, source)| {
|
|
||||||
(
|
|
||||||
path.to_string(),
|
|
||||||
SolcStandardJsonInputSource::from(source.to_string()),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let mut output = SolcStandardJsonOutput::new(&sources, &mut vec![]);
|
|
||||||
|
|
||||||
let project = Project::try_from_yul_sources(
|
let mut build = Project::try_from_yul_sources(
|
||||||
sources,
|
sources
|
||||||
|
.iter()
|
||||||
|
.map(|(path, source)| {
|
||||||
|
(
|
||||||
|
path.to_string(),
|
||||||
|
SolcStandardJsonInputSource::from(source.to_string()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Some(&mut output),
|
None,
|
||||||
&Default::default(),
|
&DEBUG_CONFIG,
|
||||||
)?;
|
)?
|
||||||
let build = project.compile(
|
.compile(
|
||||||
&mut vec![],
|
&mut vec![],
|
||||||
optimizer_settings,
|
OptimizerSettings::size(),
|
||||||
MetadataHash::None,
|
MetadataHash::Keccak256,
|
||||||
&DEBUG_CONFIG,
|
&DEBUG_CONFIG,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
)?;
|
)?;
|
||||||
|
build.take_and_write_warnings();
|
||||||
build.check_errors()?;
|
build.check_errors()?;
|
||||||
|
|
||||||
let build = build.link(BTreeMap::new(), &DEBUG_CONFIG);
|
let mut build = build.link(Default::default(), &DEBUG_CONFIG);
|
||||||
|
build.take_and_write_warnings();
|
||||||
build.check_errors()?;
|
build.check_errors()?;
|
||||||
|
|
||||||
let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
Ok(build
|
||||||
build.write_to_standard_json(&mut output, &solc.version()?)?;
|
.results
|
||||||
output.check_errors()?;
|
.into_iter()
|
||||||
Ok(())
|
.fold(BTreeMap::new(), |mut init, (path, result)| {
|
||||||
|
init.insert(path.to_string(), result.unwrap().build.bytecode);
|
||||||
|
init
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the Yul standard JSON and returns the standard JSON output.
|
/// Builds the Yul standard JSON and returns the standard JSON output.
|
||||||
@@ -292,13 +297,19 @@ pub fn build_yul_standard_json(
|
|||||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||||
initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]);
|
initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]);
|
||||||
|
|
||||||
|
let _ = crate::process::native_process::EXECUTABLE
|
||||||
|
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||||
|
|
||||||
let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let mut output = solc.validate_yul_standard_json(&mut solc_input, &mut vec![])?;
|
let mut output = solc.validate_yul_standard_json(&mut solc_input, &mut vec![])?;
|
||||||
|
if output.has_errors() {
|
||||||
|
return Ok(output);
|
||||||
|
}
|
||||||
let build = Project::try_from_yul_sources(
|
let build = Project::try_from_yul_sources(
|
||||||
solc_input.sources,
|
solc_input.sources,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Some(&mut output),
|
Some(&mut output),
|
||||||
&Default::default(),
|
&DEBUG_CONFIG,
|
||||||
)?
|
)?
|
||||||
.compile(
|
.compile(
|
||||||
&mut vec![],
|
&mut vec![],
|
||||||
@@ -314,7 +325,6 @@ pub fn build_yul_standard_json(
|
|||||||
build.check_errors()?;
|
build.check_errors()?;
|
||||||
build.write_to_standard_json(&mut output, &solc.version()?)?;
|
build.write_to_standard_json(&mut output, &solc.version()?)?;
|
||||||
|
|
||||||
output.check_errors()?;
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user