ton-assembly
Version:
TON assembler and disassembler
93 lines ⢠4.08 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@ton/core");
const node_fs_1 = require("node:fs");
const html_1 = require("../html");
const path = __importStar(require("node:path"));
const fs = __importStar(require("node:fs"));
const index_1 = require("../index");
const USAGE = "Usage: coverage <boc-file-path> <log-file-path> [<func-source-path> <func-mapping-path>]";
const main = () => {
const args = process.argv.slice(2);
const bocFilePath = args.at(0);
const logPath = args.at(1);
const funcSources = args.at(2);
const funcMappingPath = args.at(3);
const outputDir = "./";
if (bocFilePath === undefined || logPath === undefined) {
console.log(USAGE);
process.exit(1);
}
console.log("ā Generating coverage reports...");
const cell = core_1.Cell.fromBoc((0, node_fs_1.readFileSync)(bocFilePath))[0];
if (!cell) {
console.error("Cannot parse BoC");
process.exit(1);
}
const logs = (0, node_fs_1.readFileSync)(logPath, "utf8");
if (funcSources !== undefined && funcMappingPath !== undefined) {
const { lines, summary } = (0, index_1.collectFuncCoverage)(cell, logs, funcSources, funcMappingPath);
printSummary("func", summary);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const combinedReportPath = path.join(outputDir, "coverage-func.html");
(0, node_fs_1.writeFileSync)(combinedReportPath, (0, html_1.generateHtml)(lines));
console.log(`\nā
Report generated: ${combinedReportPath}`);
}
{
const { lines, summary } = (0, index_1.collectAsmCoverage)(cell, logs);
printSummary("asm", summary);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const combinedReportPath = path.join(outputDir, "coverage-asm.html");
(0, node_fs_1.writeFileSync)(combinedReportPath, (0, html_1.generateHtml)(lines));
console.log(`\nā
Report generated: ${combinedReportPath}`);
}
};
const printSummary = (kind, summary) => {
const forKind = kind === "func" ? "FUNC CODE" : "ASSEMBLY CODE";
const linesKind = kind === "func" ? "Lines" : "Instructions";
console.log(`\nš COVERAGE SUMMARY FOR ${forKind}`);
console.log("==================");
console.log(`Coverage: ${summary.coveragePercentage.toFixed(2)}%`);
console.log(`${linesKind}: ${summary.coveredLines}/${summary.totalLines}`);
console.log(`Total Gas Used: ${summary.totalGas}`);
console.log(`Executed ${linesKind}: ${summary.totalHits}`);
};
main();
//# sourceMappingURL=index.js.map