diff --git a/package.json b/package.json index 4efbdec3..91d7a896 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "pify": "^4.0.1", "recursive-readdir": "^2.2.2", "sc-istanbul": "^0.4.5", + "semver": "^7.3.4", "shelljs": "^0.8.3", "web3-utils": "^1.3.0" }, @@ -52,7 +53,7 @@ "@truffle/contract": "^4.0.36", "buidler-gas-reporter": "^0.1.3", "decache": "^4.5.1", - "hardhat": "^2.0.2", + "hardhat": "2.0.2", "hardhat-gas-reporter": "^1.0.1", "mocha": "5.2.0", "nyc": "^14.1.1", diff --git a/plugins/hardhat.plugin.js b/plugins/hardhat.plugin.js index 7c7e3512..b277489e 100644 --- a/plugins/hardhat.plugin.js +++ b/plugins/hardhat.plugin.js @@ -128,15 +128,19 @@ task("coverage", "Generates a code coverage report for tests") config.temp = args.temp; - const { - tempArtifactsDir, - tempContractsDir - } = utils.getTempLocations(config); - - utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir) - - config.paths.artifacts = tempArtifactsDir; - config.paths.cache = nomiclabsUtils.tempCacheDir(config); + // With Hardhat >= 2.0.4, everything should automatically recompile + // after solidity-coverage corrupts the artifacts. + // Prior to that version, we (try to) save artifacts to a temp folder. + if (!config.useHardhatDefaultPaths){ + const { + tempArtifactsDir, + tempContractsDir + } = utils.getTempLocations(config); + + utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir) + config.paths.artifacts = tempArtifactsDir; + config.paths.cache = nomiclabsUtils.tempCacheDir(config); + } await env.run(TASK_COMPILE); diff --git a/plugins/resources/nomiclabs.utils.js b/plugins/resources/nomiclabs.utils.js index 6ca79bfc..a3271c61 100644 --- a/plugins/resources/nomiclabs.utils.js +++ b/plugins/resources/nomiclabs.utils.js @@ -3,6 +3,7 @@ const globby = require('globby'); const pluginUtils = require("./plugin.utils"); const path = require('path'); const DataCollector = require("./../../lib/collector") +const semver = require("semver") const util = require('util') // ============================= @@ -37,6 +38,13 @@ function normalizeConfig(config, args={}){ config.solcoverjs = args.solcoverjs config.gasReporter = { enabled: false } + try { + const hardhatPackage = require('hardhat/package.json'); + if (semver.gt(hardhatPackage.version, '2.0.3')){ + config.useHardhatDefaultPaths = true; + } + } catch(e){ /* ignore */ } + return config; } diff --git a/scripts/run-nomiclabs.sh b/scripts/run-nomiclabs.sh index 3608709a..1b5eff03 100755 --- a/scripts/run-nomiclabs.sh +++ b/scripts/run-nomiclabs.sh @@ -66,6 +66,28 @@ npx hardhat coverage verifyCoverageExists +echo "" +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "wighawag/hardhat-deploy " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "" +cd .. +npm install -g yarn +git clone https://github.com/cgewecke/template-ethereum-contracts.git +cd template-ethereum-contracts +yarn +yarn add $PR_PATH --dev +cat package.json + +# Here we want to make sure that HH cache triggers a +# complete recompile after coverage runs by verifying +# that gas consumption is same in both runs. +yarn run gas +yarn run coverage +yarn run gas + +verifyCoverageExists + # Install buidler-ethers echo "" echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" diff --git a/yarn.lock b/yarn.lock index 76158999..70ea2dda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3139,7 +3139,7 @@ hardhat-gas-reporter@^1.0.1: dependencies: eth-gas-reporter "^0.2.19" -hardhat@^2.0.2: +hardhat@2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.0.2.tgz#30c3c5a49f950aad2e39c479208b4132052dc735" dependencies: @@ -3950,6 +3950,12 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + dependencies: + yallist "^4.0.0" + lru_map@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" @@ -5303,6 +5309,12 @@ semver@^6.0.0, semver@^6.3.0: version "6.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" +semver@^7.3.4: + version "7.3.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" + dependencies: + lru-cache "^6.0.0" + semver@~5.4.1: version "5.4.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" @@ -6931,6 +6943,10 @@ yallist@^3.0.0, yallist@^3.0.2, yallist@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + yargs-parser@13.1.2, yargs-parser@^13.1.2: version "13.1.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"