Skip to content

Commit

Permalink
refactor: improve performance and result of the clarity coverage hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Oct 8, 2024
1 parent 3d3637a commit b836cb8
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 202 deletions.
14 changes: 6 additions & 8 deletions components/clarinet-sdk-wasm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clarinet_deployments::{
};
use clarinet_files::chainhook_types::StacksNetwork;
use clarinet_files::{FileAccessor, FileLocation, ProjectManifest, WASMFileSystemAccessor};
use clarity_repl::analysis::coverage::{CoverageHook, CoverageReports};
use clarity_repl::analysis::coverage::{build_lcov_content, CoverageHook, CoverageReport};
use clarity_repl::clarity::analysis::contract_interface_builder::{
ContractInterface, ContractInterfaceFunction, ContractInterfaceFunctionAccess,
};
Expand Down Expand Up @@ -287,7 +287,7 @@ pub struct SDK {
options: SDKOptions,
current_test_name: String,

coverage_reports: CoverageReports,
coverage_reports: Vec<CoverageReport>,
costs_reports: Vec<CostsReport>,
}

Expand Down Expand Up @@ -318,7 +318,7 @@ impl SDK {
},
current_test_name: String::new(),

coverage_reports: CoverageReports::new(),
coverage_reports: vec![],
costs_reports: vec![],
}
}
Expand Down Expand Up @@ -786,8 +786,8 @@ impl SDK {
});
}
}
if let Some(coverage_hook) = coverage_hook {
self.coverage_reports.merge(coverage_hook.reports);
if let Some(mut coverage_hook) = coverage_hook {
self.coverage_reports.append(&mut coverage_hook.reports);
}

Ok(execution_result_to_transaction_res(&execution))
Expand Down Expand Up @@ -1088,9 +1088,7 @@ impl SDK {
}
}

let coverage = self
.coverage_reports
.build_lcov_content(&asts, &contract_paths);
let coverage = build_lcov_content(&self.coverage_reports, &asts, &contract_paths);

let mut costs_reports = Vec::new();
costs_reports.append(&mut self.costs_reports);
Expand Down
4 changes: 1 addition & 3 deletions components/clarinet-sdk/node/tests/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ describe("simnet can get code coverage", () => {

simnet.callPublicFn("counter", "increment", [], address1);
simnet.callPublicFn("counter", "increment", [], address1);
// simnet.callPrivateFn("counter", "inner-increment", [], address1);
simnet.callPrivateFn("counter", "inner-increment", [], address1);

const reports = simnet.collectReport(false, "");

// increment is called twice
console.log("reports.coverage", reports.coverage);
expect(reports.coverage.includes("FNDA:2,increment")).toBe(true);
// inner-increment is called one time directly and twice by `increment`
expect(reports.coverage.includes("FNDA:3,inner-increment")).toBe(true);
Expand Down Expand Up @@ -86,7 +85,6 @@ describe("simnet can get costs reports", () => {
expect(parsedReports).toHaveLength(1);

const report = parsedReports[0];
console.log("report", report);
expect(report.contract_id).toBe(`${simnet.deployer}.counter`);
expect(report.method).toBe("increment");
expect(report.cost_result.total.write_count).toBe(3);
Expand Down
Loading

0 comments on commit b836cb8

Please sign in to comment.