Add shared buidler / hardhat plugin entrypoint (#564)

pull/566/head
cgewecke 4 years ago committed by GitHub
parent 587a1f3e91
commit 0d74ff0b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      .circleci/config.yml
  2. 13
      hardhat.js
  3. 2
      package.json
  4. 14
      plugins/hardhat.plugin.js
  5. 6
      plugins/nomiclabs.plugin.js
  6. 5
      plugins/resources/nomiclabs.ui.js
  7. 33
      scripts/run-nomiclabs.sh
  8. 2
      test/integration/projects/bad-solcoverjs/hardhat.config.js
  9. 2
      test/integration/projects/ganache-solcoverjs/hardhat.config.js
  10. 2
      test/integration/projects/hardhat-compile-config/hardhat.config.js
  11. 2
      test/integration/projects/hardhat-gas-reporter/hardhat.config.js
  12. 2
      test/integration/projects/import-paths/hardhat.config.js
  13. 2
      test/integration/projects/libraries/hardhat.config.js
  14. 2
      test/integration/projects/multiple-suites/hardhat.config.js
  15. 2
      test/integration/projects/no-sources/hardhat.config.js
  16. 2
      test/integration/projects/skipping/hardhat.config.js
  17. 2
      test/integration/projects/solc-6/hardhat.config.js
  18. 2
      test/integration/projects/test-files/hardhat.config.js
  19. 2
      test/integration/projects/tests-folder/hardhat.config.js
  20. 1
      test/units/buidler/errors.js
  21. 1
      test/units/buidler/flags.js
  22. 16
      test/units/buidler/standard.js
  23. 7
      test/util/integration.js

@ -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

@ -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)
});

@ -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"
},

@ -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;
})

@ -0,0 +1,6 @@
if (global && global.__hardhatContext){
require("./hardhat.plugin");
return;
}
module.exports = require('./buidler.plugin')

@ -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`,

@ -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

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports={
logger: process.env.SILENT ? { log: () => {} } : console,

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports={
solidity: {

@ -1,6 +1,6 @@
require("hardhat-gas-reporter");
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports={
networks: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../hardhat");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {

@ -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

@ -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

@ -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);
});
})

@ -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");
`

Loading…
Cancel
Save