Skip to content

Commit

Permalink
feat: enable clarity-wasm in clarity check (#1355)
Browse files Browse the repository at this point in the history
* feat: enable clarity-wasm in clarity check

* chore: revert version change
  • Loading branch information
hugocaillard committed Feb 20, 2024
1 parent afbf1f1 commit abc3458
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 71 deletions.
80 changes: 51 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 45 additions & 24 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ struct Check {
conflicts_with = "use_on_disk_deployment_plan"
)]
pub use_computed_deployment_plan: bool,
/// Allow the Clarity Wasm preview to run in parallel with the Clarity interpreter (beta)
#[clap(long = "enable-clarity-wasm")]
pub enable_clarity_wasm: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -944,33 +947,16 @@ pub fn main() {
if cmd.enable_clarity_wasm {
let mut manifest_wasm = manifest.clone();
manifest_wasm.repl_settings.clarity_wasm_mode = true;
let (_, _, artifacts_wasm) = load_deployment_and_artifacts_or_exit(
let (_, _, wasm_artifacts) = load_deployment_and_artifacts_or_exit(
&manifest_wasm,
&cmd.deployment_plan_path,
cmd.use_on_disk_deployment_plan,
cmd.use_computed_deployment_plan,
);
if artifacts.success != artifacts_wasm.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 = artifacts_wasm
.diags
.get(contract)
.unwrap_or(empty_diag.as_ref());

if diag.len() != diag_wasm.len() {
dbg!(&diag);
dbg!(&diag_wasm);
}
}
print_clarity_wasm_warning();
}

Terminal::load(artifacts.session, Some(artifacts_wasm.session))
compare_wasm_artifacts(&deployment, &artifacts, &wasm_artifacts);

Terminal::load(artifacts.session, Some(wasm_artifacts.session))
} else {
Terminal::load(artifacts.session, None)
}
Expand Down Expand Up @@ -1093,14 +1079,26 @@ pub fn main() {
}
Command::Check(cmd) => {
let manifest = load_manifest_or_exit(cmd.manifest_path);
let (deployment, _, results) = load_deployment_and_artifacts_or_exit(
let (deployment, _, artifacts) = load_deployment_and_artifacts_or_exit(
&manifest,
&cmd.deployment_plan_path,
cmd.use_on_disk_deployment_plan,
cmd.use_computed_deployment_plan,
);

let diags_digest = DiagnosticsDigest::new(&results.diags, &deployment);
if cmd.enable_clarity_wasm {
let mut manifest_wasm = manifest.clone();
manifest_wasm.repl_settings.clarity_wasm_mode = true;
let (_, _, wasm_artifacts) = load_deployment_and_artifacts_or_exit(
&manifest_wasm,
&cmd.deployment_plan_path,
cmd.use_on_disk_deployment_plan,
cmd.use_computed_deployment_plan,
);
compare_wasm_artifacts(&deployment, &artifacts, &wasm_artifacts);
}

let diags_digest = DiagnosticsDigest::new(&artifacts.diags, &deployment);
if diags_digest.has_feedbacks() {
println!("{}", diags_digest.message);
}
Expand All @@ -1125,7 +1123,7 @@ pub fn main() {
pluralize!(diags_digest.contracts_checked, "contract"),
);
}
let exit_code = match results.success {
let exit_code = match artifacts.success {
true => 0,
false => 1,
};
Expand Down Expand Up @@ -1426,6 +1424,29 @@ pub fn load_deployment_if_exists(
}
}

fn compare_wasm_artifacts(
deployment: &DeploymentSpecification,
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);
}
}
print_clarity_wasm_warning();
}
}

fn execute_changes(changes: Vec<Changes>) -> bool {
let mut shared_config = None;

Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn update_session_with_contracts_executions(
for (_, (boot_contract, ast)) in boot_contracts_data {
session
.interpreter
.run_interpreter(&boot_contract, &mut Some(ast), false, None)
.run(&boot_contract, &mut Some(ast), false, None)
.expect("failed to interprete boot contract");
}

Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
serde = "1"
serde_derive = "1"
# chainhook-types = "1.2"
chainhook-types = { version = "1.2", git = "https://github.com/hirosystems/chainhook.git", rev="6c8a834" }
chainhook-types = { version = "1.2", git = "https://github.com/hirosystems/chainhook.git", rev="570ceb7" }
bip39 = { version = "1.0.1", default-features = false }
libsecp256k1 = "0.7.0"
toml = { version = "0.5.6", features = ["preserve_order"] }
Expand Down
4 changes: 2 additions & 2 deletions components/clarity-repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ integer-sqrt = "0.1.3"
getrandom = { version = "0.2.3", features = ["js"] }
atty = "0.2.14"
# clarity-vm = "2"
clarity = { version = "2", default-features = false, optional = true, git = "https://github.com/stacks-network/stacks-core.git", rev ="45843513a", package = "clarity" }
clarity = { version = "2", default-features = false, optional = true, git = "https://github.com/stacks-network/stacks-core.git", rev ="345553357be556fe53474071d09cd453549ed02e", package = "clarity" }
# clarity = { version = "2", default-features = false, optional = true, path ="../../../clarity-wasm/stacks-core/clarity" }
clar2wasm = { git = "https://github.com/stacks-network/clarity-wasm.git", rev = "2a28698", optional = true }
clar2wasm = { git = "https://github.com/stacks-network/clarity-wasm.git", rev = "e7f63c2", optional = true }
# clar2wasm = { path="../../../clarity-wasm/clar2wasm", optional = true }

# DAP Debugger
Expand Down
26 changes: 23 additions & 3 deletions components/clarity-repl/src/repl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ClarityInterpreter {
self.run_interpreter(&contract.clone(), &mut ast.clone(), cost_track, eval_hooks)
}

pub fn run_interpreter(
fn run_interpreter(
&mut self,
contract: &ClarityContract,
ast: &mut Option<ContractAST>,
Expand Down Expand Up @@ -182,7 +182,7 @@ impl ClarityInterpreter {
}

#[cfg(feature = "cli")]
pub fn run_wasm(
fn run_wasm(
&mut self,
contract: &ClarityContract,
ast: &mut Option<ContractAST>,
Expand Down Expand Up @@ -1134,7 +1134,9 @@ impl ClarityInterpreter {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_fixtures::clarity_contract::ClarityContractBuilder;
use crate::{
repl::session::BOOT_CONTRACTS_DATA, test_fixtures::clarity_contract::ClarityContractBuilder,
};
use clarity::{
types::{chainstate::StacksAddress, Address},
vm::{self},
Expand Down Expand Up @@ -1593,4 +1595,22 @@ mod tests {
StacksTransactionEvent::NFTEvent(NFTEventType::NFTTransferEvent(_))
));
}

#[test]
fn can_run_boot_contracts() {
let mut repl_settings = Settings::default();
repl_settings.clarity_wasm_mode = true;
let mut interpreter =
ClarityInterpreter::new(StandardPrincipalData::transient(), repl_settings);

let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();

for (_, (boot_contract, ast)) in boot_contracts_data {
let res = interpreter
.run(&boot_contract, &mut Some(ast), false, None)
.expect("failed to interprete boot contract");

assert!(res.diagnostics.is_empty());
}
}
}
Loading

0 comments on commit abc3458

Please sign in to comment.