Compare commits

...

2 Commits

Author SHA1 Message Date
Omar Abdulla 1d5d4d14bf Edit how CLI reporter prints 2025-08-25 20:18:48 +03:00
Omar Abdulla f94faa2de2 Fix the logic for finding the ABI in resolc 2025-08-25 19:55:57 +03:00
2 changed files with 49 additions and 23 deletions
+32 -14
View File
@@ -181,23 +181,41 @@ impl SolidityCompiler for Resolc {
.evm .evm
.and_then(|evm| evm.bytecode.clone()) .and_then(|evm| evm.bytecode.clone())
.context("Unexpected - Contract compiled with resolc has no bytecode")?; .context("Unexpected - Contract compiled with resolc has no bytecode")?;
let abi = contract_information let abi = {
let metadata = contract_information
.metadata .metadata
.as_ref() .as_ref()
.and_then(|metadata| metadata.as_object()) .context("No metadata found for the contract")?;
.and_then(|metadata| metadata.get("solc_metadata")) let solc_metadata_str = match metadata {
.and_then(|solc_metadata| solc_metadata.as_str()) serde_json::Value::String(solc_metadata_str) => solc_metadata_str.as_str(),
.and_then(|metadata| serde_json::from_str::<serde_json::Value>(metadata).ok()) serde_json::Value::Object(metadata_object) => {
.and_then(|metadata| { let solc_metadata_value = metadata_object
metadata.get("output").and_then(|output| { .get("solc_metadata")
output .context("Contract doesn't have a 'solc_metadata' field")?;
.get("abi") solc_metadata_value
.and_then(|abi| serde_json::from_value::<JsonAbi>(abi.clone()).ok()) .as_str()
}) .context("The 'solc_metadata' field is not a string")?
}) }
.context( serde_json::Value::Null
"Unexpected - Failed to get the ABI for a contract compiled with resolc", | serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::Array(_) => {
anyhow::bail!("Unsupported type of metadata {metadata:?}")
}
};
let solc_metadata =
serde_json::from_str::<serde_json::Value>(solc_metadata_str).context(
"Failed to deserialize the solc_metadata as a serde_json generic value",
)?; )?;
let output_value = solc_metadata
.get("output")
.context("solc_metadata doesn't have an output field")?;
let abi_value = output_value
.get("abi")
.context("solc_metadata output doesn't contain an abi field")?;
serde_json::from_value::<JsonAbi>(abi_value.clone())
.context("ABI found in solc_metadata output is not valid ABI")?
};
map.insert(contract_name, (bytecode.object, abi)); map.insert(contract_name, (bytecode.object, abi));
} }
} }
+14 -6
View File
@@ -546,22 +546,30 @@ async fn start_cli_reporting_task(reporter: Reporter) {
number_of_successes += 1; number_of_successes += 1;
writeln!( writeln!(
buf, buf,
"{}{}Case Succeeded{}{} - Steps Executed: {}", "{}{}Case Succeeded{} - Steps Executed: {}{}",
GREEN, BOLD, BOLD_RESET, COLOR_RESET, steps_executed GREEN, BOLD, BOLD_RESET, steps_executed, COLOR_RESET
) )
} }
TestCaseStatus::Failed { reason } => { TestCaseStatus::Failed { reason } => {
number_of_failures += 1; number_of_failures += 1;
writeln!( writeln!(
buf, buf,
"{}{}Case Failed{}{} - Reason: {}", "{}{}Case Failed{} - Reason: {}{}",
RED, BOLD, BOLD_RESET, COLOR_RESET, reason RED,
BOLD,
BOLD_RESET,
reason.trim(),
COLOR_RESET,
) )
} }
TestCaseStatus::Ignored { reason, .. } => writeln!( TestCaseStatus::Ignored { reason, .. } => writeln!(
buf, buf,
"{}{}Case Ignored{}{} - Reason: {}", "{}{}Case Ignored{} - Reason: {}{}",
GREY, BOLD, BOLD_RESET, COLOR_RESET, reason GREY,
BOLD,
BOLD_RESET,
reason.trim(),
COLOR_RESET,
), ),
}; };
} }