From ca695f0223da41c3fc5efe6d7341f381ca05168e Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 4 Feb 2024 23:49:26 -0800 Subject: [PATCH] Add missing onPreCompile stage hook (#851) --- plugins/hardhat.plugin.js | 2 ++ test/integration/standard.js | 3 ++- test/sources/projects/task-hooks/.solcover.js | 13 +++++++++++++ .../projects/task-hooks/contracts/Hooks.sol | 17 +++++++++++++++++ .../projects/task-hooks/hardhat.config.js | 9 +++++++++ test/sources/projects/task-hooks/test/hooks.js | 15 +++++++++++++++ test/sources/projects/test-files/.solcover.js | 12 ++---------- 7 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 test/sources/projects/task-hooks/.solcover.js create mode 100644 test/sources/projects/task-hooks/contracts/Hooks.sol create mode 100644 test/sources/projects/task-hooks/hardhat.config.js create mode 100644 test/sources/projects/task-hooks/test/hooks.js diff --git a/plugins/hardhat.plugin.js b/plugins/hardhat.plugin.js index 0185321..e11a58a 100644 --- a/plugins/hardhat.plugin.js +++ b/plugins/hardhat.plugin.js @@ -196,6 +196,8 @@ task("coverage", "Generates a code coverage report for tests") config.paths.cache = nomiclabsUtils.tempCacheDir(config); } + await api.onPreCompile(config); + await env.run(TASK_COMPILE); await api.onCompileComplete(config); diff --git a/test/integration/standard.js b/test/integration/standard.js index 60676e7..fd4275f 100644 --- a/test/integration/standard.js +++ b/test/integration/standard.js @@ -223,7 +223,7 @@ describe('Hardhat Plugin: standard use cases', function() { }); it('config: "onServerReady", "onTestsComplete", ...', async function() { - mock.installFullProject('test-files'); + mock.installFullProject('task-hooks'); mock.hardhatSetupEnv(this); @@ -232,6 +232,7 @@ describe('Hardhat Plugin: standard use cases', function() { assert( mock.loggerOutput.val.includes('running onServerReady') && mock.loggerOutput.val.includes('running onTestsComplete') && + mock.loggerOutput.val.includes('running onPreCompile') && mock.loggerOutput.val.includes('running onCompileComplete') && mock.loggerOutput.val.includes('running onIstanbulComplete'), diff --git a/test/sources/projects/task-hooks/.solcover.js b/test/sources/projects/task-hooks/.solcover.js new file mode 100644 index 0000000..857ac3e --- /dev/null +++ b/test/sources/projects/task-hooks/.solcover.js @@ -0,0 +1,13 @@ +// Testing hooks +const fn = (msg, config) => config.logger.log(msg); + +module.exports = { + skipFiles: [], + silent: process.env.SILENT ? true : false, + istanbulReporter: ['json-summary', 'text'], + onPreCompile: fn.bind(null, 'running onPreCompile'), + onServerReady: fn.bind(null, 'running onServerReady'), + onTestsComplete: fn.bind(null, 'running onTestsComplete'), + onCompileComplete: fn.bind(null, 'running onCompileComplete'), + onIstanbulComplete: fn.bind(null, 'running onIstanbulComplete') +} diff --git a/test/sources/projects/task-hooks/contracts/Hooks.sol b/test/sources/projects/task-hooks/contracts/Hooks.sol new file mode 100644 index 0000000..ad19d2c --- /dev/null +++ b/test/sources/projects/task-hooks/contracts/Hooks.sol @@ -0,0 +1,17 @@ +pragma solidity >=0.8.0 <0.9.0; + + +contract ContractA { + uint x; + constructor() public { + } + + function sendFn() public { + x = 5; + } + + function callFn() public pure returns (uint){ + uint y = 5; + return y; + } +} diff --git a/test/sources/projects/task-hooks/hardhat.config.js b/test/sources/projects/task-hooks/hardhat.config.js new file mode 100644 index 0000000..c417cf8 --- /dev/null +++ b/test/sources/projects/task-hooks/hardhat.config.js @@ -0,0 +1,9 @@ +require("@nomiclabs/hardhat-truffle5"); +require(__dirname + "/../plugins/nomiclabs.plugin"); + +module.exports = { + solidity: { + version: "0.8.17" + }, + logger: process.env.SILENT ? { log: () => {} } : console, +}; diff --git a/test/sources/projects/task-hooks/test/hooks.js b/test/sources/projects/task-hooks/test/hooks.js new file mode 100644 index 0000000..7cab74b --- /dev/null +++ b/test/sources/projects/task-hooks/test/hooks.js @@ -0,0 +1,15 @@ +const ContractA = artifacts.require("ContractA"); + +contract("contracta", function(accounts) { + let instance; + + before(async () => instance = await ContractA.new()) + + it('sends', async function(){ + await instance.sendFn(); + }); + + it('calls', async function(){ + await instance.callFn(); + }) +}); diff --git a/test/sources/projects/test-files/.solcover.js b/test/sources/projects/test-files/.solcover.js index 7d813ad..c324e94 100644 --- a/test/sources/projects/test-files/.solcover.js +++ b/test/sources/projects/test-files/.solcover.js @@ -1,13 +1,5 @@ -// Testing hooks -const fn = (msg, config) => config.logger.log(msg); - module.exports = { - skipFiles: ['Migrations.sol'], + skipFiles: [], silent: process.env.SILENT ? true : false, - istanbulReporter: ['json-summary', 'text'], - onPreCompile: fn.bind(null, 'running onPreCompile'), - onServerReady: fn.bind(null, 'running onServerReady'), - onTestsComplete: fn.bind(null, 'running onTestsComplete'), - onCompileComplete: fn.bind(null, 'running onCompileComplete'), - onIstanbulComplete: fn.bind(null, 'running onIstanbulComplete') + istanbulReporter: ['json-summary', 'text'] }