Skip to content

Commit b020fc7

Browse files
authored
Disable temp folder logic for hardhat >= 2.0.4 (#581)
1 parent 8660166 commit b020fc7

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"pify": "^4.0.1",
4141
"recursive-readdir": "^2.2.2",
4242
"sc-istanbul": "^0.4.5",
43+
"semver": "^7.3.4",
4344
"shelljs": "^0.8.3",
4445
"web3-utils": "^1.3.0"
4546
},
@@ -52,7 +53,7 @@
5253
"@truffle/contract": "^4.0.36",
5354
"buidler-gas-reporter": "^0.1.3",
5455
"decache": "^4.5.1",
55-
"hardhat": "^2.0.2",
56+
"hardhat": "2.0.2",
5657
"hardhat-gas-reporter": "^1.0.1",
5758
"mocha": "5.2.0",
5859
"nyc": "^14.1.1",

plugins/hardhat.plugin.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,19 @@ task("coverage", "Generates a code coverage report for tests")
128128

129129
config.temp = args.temp;
130130

131-
const {
132-
tempArtifactsDir,
133-
tempContractsDir
134-
} = utils.getTempLocations(config);
135-
136-
utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir)
137-
138-
config.paths.artifacts = tempArtifactsDir;
139-
config.paths.cache = nomiclabsUtils.tempCacheDir(config);
131+
// With Hardhat >= 2.0.4, everything should automatically recompile
132+
// after solidity-coverage corrupts the artifacts.
133+
// Prior to that version, we (try to) save artifacts to a temp folder.
134+
if (!config.useHardhatDefaultPaths){
135+
const {
136+
tempArtifactsDir,
137+
tempContractsDir
138+
} = utils.getTempLocations(config);
139+
140+
utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir)
141+
config.paths.artifacts = tempArtifactsDir;
142+
config.paths.cache = nomiclabsUtils.tempCacheDir(config);
143+
}
140144

141145
await env.run(TASK_COMPILE);
142146

plugins/resources/nomiclabs.utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const globby = require('globby');
33
const pluginUtils = require("./plugin.utils");
44
const path = require('path');
55
const DataCollector = require("./../../lib/collector")
6+
const semver = require("semver")
67
const util = require('util')
78

89
// =============================
@@ -37,6 +38,13 @@ function normalizeConfig(config, args={}){
3738
config.solcoverjs = args.solcoverjs
3839
config.gasReporter = { enabled: false }
3940

41+
try {
42+
const hardhatPackage = require('hardhat/package.json');
43+
if (semver.gt(hardhatPackage.version, '2.0.3')){
44+
config.useHardhatDefaultPaths = true;
45+
}
46+
} catch(e){ /* ignore */ }
47+
4048
return config;
4149
}
4250

scripts/run-nomiclabs.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ npx hardhat coverage
6666

6767
verifyCoverageExists
6868

69+
echo ""
70+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
71+
echo "wighawag/hardhat-deploy "
72+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
73+
echo ""
74+
cd ..
75+
npm install -g yarn
76+
git clone https://github.com/cgewecke/template-ethereum-contracts.git
77+
cd template-ethereum-contracts
78+
yarn
79+
yarn add $PR_PATH --dev
80+
cat package.json
81+
82+
# Here we want to make sure that HH cache triggers a
83+
# complete recompile after coverage runs by verifying
84+
# that gas consumption is same in both runs.
85+
yarn run gas
86+
yarn run coverage
87+
yarn run gas
88+
89+
verifyCoverageExists
90+
6991
# Install buidler-ethers
7092
echo ""
7193
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

yarn.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,7 @@ hardhat-gas-reporter@^1.0.1:
31393139
dependencies:
31403140
eth-gas-reporter "^0.2.19"
31413141

3142-
hardhat@^2.0.2:
3142+
31433143
version "2.0.2"
31443144
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.0.2.tgz#30c3c5a49f950aad2e39c479208b4132052dc735"
31453145
dependencies:
@@ -3950,6 +3950,12 @@ lru-cache@^5.1.1:
39503950
dependencies:
39513951
yallist "^3.0.2"
39523952

3953+
lru-cache@^6.0.0:
3954+
version "6.0.0"
3955+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
3956+
dependencies:
3957+
yallist "^4.0.0"
3958+
39533959
lru_map@^0.3.3:
39543960
version "0.3.3"
39553961
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:
53035309
version "6.3.0"
53045310
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
53055311

5312+
semver@^7.3.4:
5313+
version "7.3.4"
5314+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97"
5315+
dependencies:
5316+
lru-cache "^6.0.0"
5317+
53065318
semver@~5.4.1:
53075319
version "5.4.1"
53085320
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:
69316943
version "3.0.3"
69326944
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
69336945

6946+
yallist@^4.0.0:
6947+
version "4.0.0"
6948+
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
6949+
69346950
[email protected], yargs-parser@^13.1.2:
69356951
version "13.1.2"
69366952
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"

0 commit comments

Comments
 (0)