Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing onPreCompile stage hook #851

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion test/integration/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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'),

Expand Down
13 changes: 13 additions & 0 deletions test/sources/projects/task-hooks/.solcover.js
Original file line number Diff line number Diff line change
@@ -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')
}
17 changes: 17 additions & 0 deletions test/sources/projects/task-hooks/contracts/Hooks.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 9 additions & 0 deletions test/sources/projects/task-hooks/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -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,
};
15 changes: 15 additions & 0 deletions test/sources/projects/task-hooks/test/hooks.js
Original file line number Diff line number Diff line change
@@ -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();
})
});
12 changes: 2 additions & 10 deletions test/sources/projects/test-files/.solcover.js
Original file line number Diff line number Diff line change
@@ -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']
}