Skip to content

Commit

Permalink
feat: improve clarity wasm results comparison (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard authored Feb 21, 2024
1 parent abc3458 commit 0f9e612
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
34 changes: 21 additions & 13 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,20 +1429,28 @@ fn compare_wasm_artifacts(
artifacts: &DeploymentGenerationArtifacts,
wasm_artifacts: &DeploymentGenerationArtifacts,
) {
if artifacts.success != wasm_artifacts.success {
for contract in deployment.contracts.keys() {
let empty_diag = vec![];
let diag = artifacts.diags.get(contract).unwrap_or(empty_diag.as_ref());
let diag_wasm = wasm_artifacts
.diags
.get(contract)
.unwrap_or(empty_diag.as_ref());

if diag.len() != diag_wasm.len() {
dbg!(&diag);
dbg!(&diag_wasm);
}
let mut print_warning = false;
for contract in deployment.contracts.keys() {
let diags = artifacts.diags.get(contract);
let wasm_diags = wasm_artifacts.diags.get(contract);
if diags != wasm_diags {
print_warning = true;
println!("Diagnostics of contract {contract} differs between clarity and clarity-wasm");
dbg!(diags);
dbg!(wasm_diags);
}
let value = artifacts.results_values.get(contract);
let wasm_value = wasm_artifacts.results_values.get(contract);
if (diags.is_some() && wasm_diags.is_some()) && (value != wasm_value) {
print_warning = true;
println!(
"Evaluation value of contract {contract} differs between clarity and clarity-wasm"
);
dbg!(value);
dbg!(wasm_value);
};
}
if print_warning {
print_clarity_wasm_warning();
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn setup_session_with_deployment(

let deps = BTreeMap::new();
let mut diags = HashMap::new();
let mut results_values = HashMap::new();
let mut asts = BTreeMap::new();
let mut contracts_analysis = HashMap::new();
let mut success = true;
Expand All @@ -62,6 +63,7 @@ pub fn setup_session_with_deployment(
Ok(execution_result) => {
diags.insert(contract_id.clone(), execution_result.diagnostics);
if let EvaluationResult::Contract(contract_result) = execution_result.result {
results_values.insert(contract_id.clone(), contract_result.result);
asts.insert(contract_id.clone(), contract_result.contract.ast);
contracts_analysis.insert(contract_id, contract_result.contract.analysis);
}
Expand All @@ -77,6 +79,7 @@ pub fn setup_session_with_deployment(
asts,
deps,
diags,
results_values,
success,
session,
analysis: contracts_analysis,
Expand Down Expand Up @@ -787,6 +790,7 @@ pub async fn generate_default_deployment(
deps: dependencies,
diags: contract_diags,
success: asts_success,
results_values: HashMap::new(),
analysis: HashMap::new(),
session,
};
Expand Down
3 changes: 2 additions & 1 deletion components/clarinet-deployments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clarity_repl::clarity::vm::types::{
};

use clarity_repl::analysis::ast_dependency_detector::DependencySet;
use clarity_repl::clarity::{ClarityName, ClarityVersion, ContractName, StacksEpochId};
use clarity_repl::clarity::{ClarityName, ClarityVersion, ContractName, StacksEpochId, Value};
use clarity_repl::repl::{Session, DEFAULT_CLARITY_VERSION};
use serde::{Deserialize, Serialize};
use serde_yaml;
Expand Down Expand Up @@ -73,6 +73,7 @@ pub struct DeploymentGenerationArtifacts {
pub deps: BTreeMap<QualifiedContractIdentifier, DependencySet>,
pub diags: HashMap<QualifiedContractIdentifier, Vec<Diagnostic>>,
pub analysis: HashMap<QualifiedContractIdentifier, ContractAnalysis>,
pub results_values: HashMap<QualifiedContractIdentifier, Option<Value>>,
pub session: Session,
pub success: bool,
}
Expand Down

0 comments on commit 0f9e612

Please sign in to comment.