cofhe-hardhat-plugin
Version:
Hardhat TypeScript plugin boilerplate
62 lines • 2.99 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mock_withLogs = exports.mock_setLoggingEnabled = void 0;
const addresses_1 = require("./addresses");
const chalk_1 = __importDefault(require("chalk"));
const getDeployedMockTaskManager = async (hre) => {
// Fetch the deployed MockTaskManager
const taskManager = await hre.ethers.getContractAt("TaskManager", addresses_1.TASK_MANAGER_ADDRESS);
return taskManager;
};
const getLoggingEnabled = async (hre) => {
const taskManager = await getDeployedMockTaskManager(hre);
return await taskManager.logOps();
};
const setLoggingEnabled = async (hre, enabled) => {
const taskManager = await getDeployedMockTaskManager(hre);
await taskManager.setLogOps(enabled);
};
// prettier-ignore
const printLogsEnabledMessage = (closureMessage) => {
console.log("┌──────────────────┬──────────────────────────────────────────────────");
console.log(`│ [COFHE-MOCKS] │ ${closureMessage}`);
console.log("├──────────────────┴──────────────────────────────────────────────────");
};
// prettier-ignore
const printLogsBlockEnd = () => {
console.log("└─────────────────────────────────────────────────────────────────────");
};
const mock_setLoggingEnabled = async (hre, enabled, closureName) => {
try {
const initiallyEnabled = await getLoggingEnabled(hre);
await setLoggingEnabled(hre, enabled);
// Only print if enabling logs
if (enabled) {
printLogsEnabledMessage(`${closureName ? `"${chalk_1.default.bold(closureName)}" logs:` : "Logs:"}`);
}
// Only print if disabling logs AND logs currently enabled
if (!enabled && initiallyEnabled) {
printLogsBlockEnd();
}
}
catch (error) {
console.log(chalk_1.default.red("mock_setLoggingEnabled error"), error);
}
};
exports.mock_setLoggingEnabled = mock_setLoggingEnabled;
const mock_withLogs = async (hre, closureName, closure) => {
const initiallyEnabled = await getLoggingEnabled(hre);
await setLoggingEnabled(hre, true);
printLogsEnabledMessage(`"${chalk_1.default.bold(closureName)}" logs:`);
await closure();
printLogsBlockEnd();
// If logs were disabled, disable them again
if (!initiallyEnabled) {
await setLoggingEnabled(hre, false);
}
};
exports.mock_withLogs = mock_withLogs;
//# sourceMappingURL=mock-logs.js.map