diff --git a/.circleci/config.yml b/.circleci/config.yml index 7187712..b37a6eb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,20 +65,19 @@ jobs: executor: win/default steps: - checkout - - run: dotnet tool install --global PowerShell - run: name: Windows Metacoin E2E command: | bash ./scripts/run-metacoin.sh - e2e-buidler: + e2e-nomiclabs: machine: true steps: - checkout - <<: *step_install_nvm - run: - name: Buidler E2E + name: Buidler & Hardhat E2E command: | - ./scripts/run-buidler.sh + ./scripts/run-nomiclabs.sh workflows: version: 2 build: @@ -88,4 +87,4 @@ workflows: # - e2e-zeppelin - e2e-metacoin - e2e-metacoin-windows - - e2e-buidler + - e2e-nomiclabs diff --git a/hardhat.js b/hardhat.js deleted file mode 100644 index 9180f2d..0000000 --- a/hardhat.js +++ /dev/null @@ -1,13 +0,0 @@ -const plugin = require("./plugins/hardhat.plugin"); -const PluginUI = require('./plugins/resources/nomiclabs.ui'); - -// UI for the task flags... -const ui = new PluginUI(); - -task("coverage", "Generates a code coverage report for tests") - .addOptionalParam("testfiles", ui.flags.file, "", types.string) - .addOptionalParam("solcoverjs", ui.flags.solcoverjs, "", types.string) - .addOptionalParam('temp', ui.flags.temp, "", types.string) - .setAction(async function(args, env){ - await plugin(args, env) - }); diff --git a/package.json b/package.json index 30c4cfd..db76f4b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "solidity-coverage", "version": "0.7.11", "description": "", - "main": "plugins/buidler.plugin.js", + "main": "plugins/nomiclabs.plugin.js", "bin": { "solidity-coverage": "./plugins/bin.js" }, diff --git a/plugins/hardhat.plugin.js b/plugins/hardhat.plugin.js index cb7cb51..72841da 100644 --- a/plugins/hardhat.plugin.js +++ b/plugins/hardhat.plugin.js @@ -21,6 +21,9 @@ const { let measureCoverage = false; let instrumentedSources +// UI for the task flags... +const ui = new PluginUI(); + task(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, { config }, runSuper) => { const solcInput = await runSuper(); if (measureCoverage) { @@ -65,7 +68,12 @@ task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __, * @param {HardhatUserArgs} args * @param {HardhatEvn} env */ -async function plugin(args, env) { +task("coverage", "Generates a code coverage report for tests") + .addOptionalParam("testfiles", ui.flags.file, "", types.string) + .addOptionalParam("solcoverjs", ui.flags.solcoverjs, "", types.string) + .addOptionalParam('temp', ui.flags.temp, "", types.string) + .setAction(async function(args, env){ + let error; let ui; let api; @@ -200,6 +208,4 @@ async function plugin(args, env) { if (error !== undefined ) throw new HardhatPluginError(error); if (failedTests > 0) throw new HardhatPluginError(ui.generate('tests-fail', [failedTests])); -} - -module.exports = plugin; +}) diff --git a/plugins/nomiclabs.plugin.js b/plugins/nomiclabs.plugin.js new file mode 100644 index 0000000..f609ad5 --- /dev/null +++ b/plugins/nomiclabs.plugin.js @@ -0,0 +1,6 @@ +if (global && global.__hardhatContext){ + require("./hardhat.plugin"); + return; +} + +module.exports = require('./buidler.plugin') diff --git a/plugins/resources/nomiclabs.ui.js b/plugins/resources/nomiclabs.ui.js index d276efc..01ce0af 100644 --- a/plugins/resources/nomiclabs.ui.js +++ b/plugins/resources/nomiclabs.ui.js @@ -55,9 +55,8 @@ class PluginUI extends UI { 'ganache-network': `\n${c.bold('Network Info')}` + `\n${c.bold('============')}\n` + - `${ct} ${c.bold('ganache-core')}: ${args[0]}\n` + - `${ct} ${c.bold('port')}: ${args[2]}\n` + - `${ct} ${c.bold('network')}: ${args[1]}\n`, + `${ct} ${c.bold('port')}: ${args[1]}\n` + + `${ct} ${c.bold('network')}: ${args[0]}\n`, 'port-clash': `${w} ${c.red("The 'port' values in your config's network url ")}` + `${c.red("and .solcover.js are different. Using network's: ")} ${c.bold(args[0])}.\n`, diff --git a/scripts/run-buidler.sh b/scripts/run-nomiclabs.sh similarity index 73% rename from scripts/run-buidler.sh rename to scripts/run-nomiclabs.sh index d3418dd..3608709 100755 --- a/scripts/run-buidler.sh +++ b/scripts/run-nomiclabs.sh @@ -37,16 +37,35 @@ echo "" # Install buidler-e2e git clone https://github.com/sc-forks/buidler-e2e.git cd buidler-e2e -npm install +npm install --silent # Install and run solidity-coverage @ PR -npm install --save-dev $PR_PATH +npm install --save-dev --silent $PR_PATH cat package.json npx buidler coverage verifyCoverageExists +echo "" +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "Simple hardhat/hardhat-trufflev5 " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "" + +# Install hardhat-e2e (HardhatEVM) +git clone https://github.com/sc-forks/hardhat-e2e.git +cd hardhat-e2e +npm install --silent + +# Install and run solidity-coverage @ PR +npm install --save-dev --silent $PR_PATH +cat package.json + +npx hardhat coverage + +verifyCoverageExists + # Install buidler-ethers echo "" echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" @@ -56,10 +75,10 @@ echo "" cd .. git clone https://github.com/sc-forks/example-buidler-ethers.git cd example-buidler-ethers -npm install +npm install --silent # Install and run solidity-coverage @ PR -npm install --save-dev $PR_PATH +npm install --save-dev --silent $PR_PATH cat package.json npx buidler coverage @@ -76,12 +95,12 @@ echo "" cd .. git clone https://github.com/sc-forks/moloch.git cd moloch -npm install -npm uninstall --save-dev solidity-coverage +npm install --silent +npm uninstall --save-dev --silent solidity-coverage # Install and run solidity-coverage @ PR # Should run on network 'localhost' -npm install --save-dev $PR_PATH +npm install --save-dev --silent $PR_PATH npm run coverage verifyCoverageExists diff --git a/test/integration/projects/bad-solcoverjs/hardhat.config.js b/test/integration/projects/bad-solcoverjs/hardhat.config.js index cbdc2b4..74767fd 100644 --- a/test/integration/projects/bad-solcoverjs/hardhat.config.js +++ b/test/integration/projects/bad-solcoverjs/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports={ logger: process.env.SILENT ? { log: () => {} } : console, diff --git a/test/integration/projects/ganache-solcoverjs/hardhat.config.js b/test/integration/projects/ganache-solcoverjs/hardhat.config.js index 4fb861d..ef2201e 100644 --- a/test/integration/projects/ganache-solcoverjs/hardhat.config.js +++ b/test/integration/projects/ganache-solcoverjs/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/hardhat-compile-config/hardhat.config.js b/test/integration/projects/hardhat-compile-config/hardhat.config.js index 1461dbc..443e085 100644 --- a/test/integration/projects/hardhat-compile-config/hardhat.config.js +++ b/test/integration/projects/hardhat-compile-config/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports={ solidity: { diff --git a/test/integration/projects/hardhat-gas-reporter/hardhat.config.js b/test/integration/projects/hardhat-gas-reporter/hardhat.config.js index 0181663..9f3a6d2 100644 --- a/test/integration/projects/hardhat-gas-reporter/hardhat.config.js +++ b/test/integration/projects/hardhat-gas-reporter/hardhat.config.js @@ -1,6 +1,6 @@ require("hardhat-gas-reporter"); require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/import-paths/hardhat.config.js b/test/integration/projects/import-paths/hardhat.config.js index 87d1bd8..ff014c9 100644 --- a/test/integration/projects/import-paths/hardhat.config.js +++ b/test/integration/projects/import-paths/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/libraries/hardhat.config.js b/test/integration/projects/libraries/hardhat.config.js index 87d1bd8..ff014c9 100644 --- a/test/integration/projects/libraries/hardhat.config.js +++ b/test/integration/projects/libraries/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/multiple-suites/hardhat.config.js b/test/integration/projects/multiple-suites/hardhat.config.js index fbd6153..720d212 100644 --- a/test/integration/projects/multiple-suites/hardhat.config.js +++ b/test/integration/projects/multiple-suites/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports={ networks: { diff --git a/test/integration/projects/no-sources/hardhat.config.js b/test/integration/projects/no-sources/hardhat.config.js index 9c982d2..99b5f1c 100644 --- a/test/integration/projects/no-sources/hardhat.config.js +++ b/test/integration/projects/no-sources/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/skipping/hardhat.config.js b/test/integration/projects/skipping/hardhat.config.js index 9c982d2..99b5f1c 100644 --- a/test/integration/projects/skipping/hardhat.config.js +++ b/test/integration/projects/skipping/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/solc-6/hardhat.config.js b/test/integration/projects/solc-6/hardhat.config.js index 08fb1e3..448b09d 100644 --- a/test/integration/projects/solc-6/hardhat.config.js +++ b/test/integration/projects/solc-6/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/test-files/hardhat.config.js b/test/integration/projects/test-files/hardhat.config.js index 9c982d2..99b5f1c 100644 --- a/test/integration/projects/test-files/hardhat.config.js +++ b/test/integration/projects/test-files/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/integration/projects/tests-folder/hardhat.config.js b/test/integration/projects/tests-folder/hardhat.config.js index 9c982d2..99b5f1c 100644 --- a/test/integration/projects/tests-folder/hardhat.config.js +++ b/test/integration/projects/tests-folder/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../hardhat"); +require(__dirname + "/../plugins/nomiclabs.plugin"); module.exports = { solidity: { diff --git a/test/units/buidler/errors.js b/test/units/buidler/errors.js index ed68a29..23dc76b 100644 --- a/test/units/buidler/errors.js +++ b/test/units/buidler/errors.js @@ -7,7 +7,6 @@ const ganache = require('ganache-cli') const verify = require('../../util/verifiers') const mock = require('../../util/integration'); -const plugin = require('../../../plugins/buidler.plugin'); // ======= // Errors diff --git a/test/units/buidler/flags.js b/test/units/buidler/flags.js index 9b25b60..9120c5d 100644 --- a/test/units/buidler/flags.js +++ b/test/units/buidler/flags.js @@ -5,7 +5,6 @@ const shell = require('shelljs'); const verify = require('../../util/verifiers') const mock = require('../../util/integration'); -const plugin = require('../../../plugins/buidler.plugin'); // ======================= // CLI Options / Flags diff --git a/test/units/buidler/standard.js b/test/units/buidler/standard.js index 9beb2a3..06360cd 100644 --- a/test/units/buidler/standard.js +++ b/test/units/buidler/standard.js @@ -5,7 +5,6 @@ const shell = require('shelljs'); const verify = require('../../util/verifiers') const mock = require('../../util/integration'); -const plugin = require('../../../plugins/buidler.plugin'); // ======================= // Standard Use-case Tests @@ -69,4 +68,19 @@ describe('Buidler Plugin: standard use cases', function() { `Should have used specified network name: ${mock.loggerOutput.val}` ); }); + + // Simple.sol with a failing assertion in a buidler-truffle5 test + it('unit tests failing', async function() { + mock.install('Simple', 'truffle-test-fail.js', solcoverConfig); + mock.buidlerSetupEnv(this); + + try { + await this.env.run("coverage"); + assert.fail() + } catch(err){ + assert(err.message.includes('failed under coverage')); + } + + verify.coverageGenerated(buidlerConfig); + }); }) diff --git a/test/util/integration.js b/test/util/integration.js index a6d8254..cfca60c 100644 --- a/test/util/integration.js +++ b/test/util/integration.js @@ -39,7 +39,8 @@ function decacheConfigs(){ `${process.cwd()}/${temp}/${hardhatConfigName}`, `${process.cwd()}/${temp}/contracts/Simple.sol`, `${process.cwd()}/${temp}/test/simple.js`, - `${process.cwd()}/${temp}/test/account-one.js` + `${process.cwd()}/${temp}/test/account-one.js`, + `${process.cwd()}/${temp}/test/truffle-test-fail.js` ]; paths.forEach(pth => { @@ -198,6 +199,8 @@ function getDefaultHardhatConfig() { } function getBuidlerConfigJS(config){ + // Hardhat tests will crash if the buidler plugin is loaded from the shared entrypoint + // b/c of some kind of weird cacheing or context reset issue. const prefix =` const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing"); loadPluginFile(__dirname + "/../plugins/buidler.plugin"); @@ -214,7 +217,7 @@ function getBuidlerConfigJS(config){ function getHardhatConfigJS(config){ const prefix =` require("@nomiclabs/hardhat-truffle5"); - require(__dirname + "/../hardhat"); + require(__dirname + "/../plugins/nomiclabs.plugin"); `