UNPKG

hardhat-log-remover

Version:

Remove Hardhat console.log imports and calls from Solidity source files

43 lines (42 loc) 2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const fs_1 = __importDefault(require("fs")); const hardhat_1 = __importDefault(require("hardhat")); const task_names_1 = require("hardhat/builtin-tasks/task-names"); const TASK_REMOVE_LOGS = 'remove-logs'; const readContractSource = async (name) => { const artifact = await hardhat_1.default.artifacts.readArtifact(name); return fs_1.default.readFileSync(artifact.sourceName).toString(); }; describe(TASK_REMOVE_LOGS, () => { const cache = {}; before(async () => { const sourcePaths = await hardhat_1.default.run(task_names_1.TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS); for (const sourcePath of sourcePaths) { cache[sourcePath] = fs_1.default.readFileSync(sourcePath).toString(); } }); afterEach(async () => { for (const sourcePath in cache) { fs_1.default.writeFileSync(sourcePath, cache[sourcePath]); } }); it('removes console.log calls from source file', async () => { const contentsBefore = await readContractSource('ContractWithLogs'); (0, chai_1.expect)(contentsBefore).to.include('console.log'); await hardhat_1.default.run(TASK_REMOVE_LOGS); const contentsAfter = await readContractSource('ContractWithLogs'); (0, chai_1.expect)(contentsAfter).not.to.include('console.sol'); }); it('removes console.sol imports from souce file', async () => { const contentsBefore = await readContractSource('ContractWithLogs'); (0, chai_1.expect)(contentsBefore).to.include('console.sol'); await hardhat_1.default.run(TASK_REMOVE_LOGS); const contentsAfter = await readContractSource('ContractWithLogs'); (0, chai_1.expect)(contentsAfter).not.to.include('console.sol'); }); });