Skip to content

Commit ae7e290

Browse files
authored
Merge branch 'master' into patch-1
2 parents 5bb5b3f + c680e54 commit ae7e290

File tree

13 files changed

+712
-248
lines changed

13 files changed

+712
-248
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- checkout
5757
- <<: *step_install_nvm
5858
- run:
59-
name: Buidler & Hardhat E2E
59+
name: Hardhat E2E
6060
command: |
6161
./scripts/run-nomiclabs.sh
6262
workflows:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
0.8.4 / 2023-07-04
4+
==================
5+
* Update solidity-parser to 0.16.0 (https://github.com/sc-forks/solidity-coverage/issues/802)
6+
7+
0.8.3 / 2023-06-22
8+
==================
9+
* Updates for Hardhat v2.15.0 (https://github.com/sc-forks/solidity-coverage/pull/796)
10+
311
0.8.1 / 2022-09-06
412
===================
513
* Restore web3-utils (https://github.com/sc-forks/solidity-coverage/issues/743)

HARDHAT_README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ More documentation, including FAQ and information about solidity-coverage's API
128128
[29]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/upgrade.md#upgrading-from-06x-to-070
129129
[30]: https://github.com/sc-forks/solidity-coverage/tree/0.6.x-final#solidity-coverage
130130
[31]: https://github.com/sc-forks/solidity-coverage/releases/tag/v0.7.0
131-
[32]: https://github.com/sc-forks/buidler-e2e/tree/coverage
132131
[33]: https://github.com/sc-forks/moloch
133132
[34]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#reducing-the-instrumentation-footprint
134133

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
![npm (tag)](https://img.shields.io/npm/v/solidity-coverage/latest)
55
[![CircleCI](https://circleci.com/gh/sc-forks/solidity-coverage.svg?style=svg)][20]
66
[![codecov](https://codecov.io/gh/sc-forks/solidity-coverage/branch/master/graph/badge.svg)][21]
7-
[![buidler](https://buidler.dev/buidler-plugin-badge.svg?1)][26]
7+
[![Hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)][26]
88

99

1010
## Code coverage for Solidity testing
@@ -197,13 +197,12 @@ $ yarn
197197
[23]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#workflow-hooks
198198
[24]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#skipping-tests
199199
[25]: https://github.com/sc-forks/solidity-coverage/issues/417
200-
[26]: https://buidler.dev/
200+
[26]: https://hardhat.org/
201201
[27]: https://www.trufflesuite.com/docs
202202
[28]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/api.md
203203
[29]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/upgrade.md#upgrading-from-06x-to-070
204204
[30]: https://github.com/sc-forks/solidity-coverage/tree/0.6.x-final#solidity-coverage
205205
[31]: https://github.com/sc-forks/solidity-coverage/releases/tag/v0.7.0
206-
[32]: https://github.com/sc-forks/buidler-e2e/tree/coverage
207206
[33]: https://github.com/sc-forks/moloch
208207
[34]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#reducing-the-instrumentation-footprint
209208
[35]: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/e5fbbda9bac49039847a7ed20c1d966766ecc64a/scripts/coverage.js

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ table below shows how its core methods relate to the stages of a test run:
2020
disposable set of contracts/artifacts which coverage must use in lieu of the 'real' (uninstrumented)
2121
contracts.
2222

23-
+ there are two complete [coverage tool/plugin implementations][5] (for Buidler and Truffle)
23+
+ there are two complete [coverage tool/plugin implementations][5] (for Hardhat and Truffle)
2424
which can be used as sources if you're building something similar.
2525

2626
[5]: https://github.com/sc-forks/solidity-coverage/tree/master/plugins

docs/faq.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Downloading compiler version 0.5.16
5555
Extra non-whitespace after JSON value.
5656
```
5757

58-
...try setting the `measureStatementCoverage` option to `false` in `.solcoverjs`. This will reduce the footprint of
58+
...try setting the `measureStatementCoverage` option to `false` in `.solcover.js`. This will reduce the footprint of
5959
the instrumentation solidity-coverage adds to your files. You'll still get line, branch and function coverage but the data Istanbul collects
6060
for statements will be omitted.
6161

@@ -92,11 +92,11 @@ If your project is large, complex and uses ABI encoder V2 or Solidity >= V8, you
9292
Work-arounds for this problem are tracked below. (These are only available in hardhat. If you're using hardhat and none of them work for you, please open an issue.)
9393

9494
**Work-around #1**
95-
+ Set the `.solcoverjs` option `configureYulOptimizer` to `true`.
95+
+ Set the `.solcover.js` option `configureYulOptimizer` to `true`.
9696

9797
**Work-around #2**
98-
+ Set the `.solcoverjs` option: `configureYulOptimizer` to `true`.
99-
+ Set the `.solcoverjs` option: `solcOptimizerDetails` to:
98+
+ Set the `.solcover.js` option: `configureYulOptimizer` to `true`.
99+
+ Set the `.solcover.js` option: `solcOptimizerDetails` to:
100100
```js
101101
{
102102
peephole: false,

lib/api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,17 @@ class API {
279279
}
280280

281281
// Hardhat
282-
attachToHardhatVM(provider){
282+
async attachToHardhatVM(provider){
283283
const self = this;
284284
this.collector = new DataCollector(this.instrumenter.instrumentationData);
285285

286+
if ('init' in provider) {
287+
// Newer versions of Hardhat initialize the provider lazily, so we need to
288+
// call provider.init() explicitly. This is a no-op if the provider is
289+
// already initialized.
290+
await provider.init();
291+
}
292+
286293
let cur = provider;
287294

288295
// Go down to core HardhatNetworkProvider

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-coverage",
3-
"version": "0.8.1",
3+
"version": "0.8.4",
44
"description": "Code coverage for Solidity testing",
55
"main": "plugins/nomiclabs.plugin.js",
66
"bin": {
@@ -25,7 +25,7 @@
2525
"license": "ISC",
2626
"dependencies": {
2727
"@ethersproject/abi": "^5.0.9",
28-
"@solidity-parser/parser": "^0.14.1",
28+
"@solidity-parser/parser": "^0.16.0",
2929
"chalk": "^2.4.2",
3030
"death": "^1.1.0",
3131
"detect-port": "^1.3.0",
@@ -36,7 +36,7 @@
3636
"globby": "^10.0.1",
3737
"jsonschema": "^1.2.4",
3838
"lodash": "^4.17.15",
39-
"mocha": "7.1.2",
39+
"mocha": "10.2.0",
4040
"node-emoji": "^1.10.0",
4141
"pify": "^4.0.1",
4242
"recursive-readdir": "^2.2.2",
@@ -56,7 +56,7 @@
5656
"ethereum-waffle": "^3.4.0",
5757
"ethers": "^5.5.3",
5858
"ganache-cli": "6.12.2",
59-
"hardhat": "^2.11.0",
59+
"hardhat": "^2.17.3",
6060
"hardhat-gas-reporter": "^1.0.1",
6161
"nyc": "^14.1.1",
6262
"solc": "^0.7.5"

plugins/hardhat.plugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,19 @@ task("coverage", "Generates a code coverage report for tests")
198198
// ==============
199199
// Server launch
200200
// ==============
201-
let network = nomiclabsUtils.setupHardhatNetwork(env, api, ui);
201+
let network = await nomiclabsUtils.setupHardhatNetwork(env, api, ui);
202202

203203
if (network.isHardhatEVM){
204204
accounts = await utils.getAccountsHardhat(network.provider);
205205
nodeInfo = await utils.getNodeInfoHardhat(network.provider);
206206

207207
// Note: this only works if the reset block number is before any transactions have fired on the fork.
208208
// e.g you cannot fork at block 1, send some txs (blocks 2,3,4) and reset to block 2
209-
env.network.provider.on(HARDHAT_NETWORK_RESET_EVENT, () => {
210-
api.attachToHardhatVM(env.network.provider);
209+
env.network.provider.on(HARDHAT_NETWORK_RESET_EVENT, async () => {
210+
await api.attachToHardhatVM(env.network.provider);
211211
});
212212

213-
api.attachToHardhatVM(network.provider);
213+
await api.attachToHardhatVM(network.provider);
214214

215215
ui.report('hardhat-network', [
216216
nodeInfo.split('/')[1],

plugins/resources/nomiclabs.utils.js

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ const util = require('util')
1818
function getTestFilePaths(files){
1919
const target = globby.sync([files])
2020

21-
// Buidler/Hardhat supports js & ts
21+
// Hardhat supports js & ts
2222
const testregex = /.*\.(js|ts)$/;
2323
return target.filter(f => f.match(testregex) != null);
2424
}
2525

2626
/**
27-
* Normalizes Buidler/Hardhat paths / logging for use by the plugin utilities and
27+
* Normalizes Hardhat paths / logging for use by the plugin utilities and
2828
* attaches them to the config
29-
* @param {Buidler/HardhatConfig} config
30-
* @return {Buidler/HardhatConfig} updated config
29+
* @param {HardhatConfig} config
30+
* @return {HardhatConfig} updated config
3131
*/
3232
function normalizeConfig(config, args={}){
3333
config.workingDir = config.paths.root;
@@ -49,36 +49,14 @@ function normalizeConfig(config, args={}){
4949
return config;
5050
}
5151

52-
function setupBuidlerNetwork(env, api, ui){
53-
const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/construction");
54-
55-
let networkConfig = {};
56-
57-
let networkName = (env.buidlerArguments.network !== 'buidlerevm')
58-
? env.buidlerArguments.network
59-
: api.defaultNetworkName;
60-
61-
if (networkName !== api.defaultNetworkName){
62-
networkConfig = env.config.networks[networkName];
63-
configureHttpProvider(networkConfig, api, ui)
64-
} else {
65-
networkConfig.url = `http://${api.host}:${api.port}`
66-
}
67-
68-
const provider = createProvider(networkName, networkConfig);
69-
70-
return configureNetworkEnv(
71-
env,
72-
networkName,
73-
networkConfig,
74-
provider
75-
)
76-
}
77-
78-
function setupHardhatNetwork(env, api, ui){
52+
async function setupHardhatNetwork(env, api, ui){
53+
const hardhatPackage = require('hardhat/package.json');
7954
const { createProvider } = require("hardhat/internal/core/providers/construction");
8055
const { HARDHAT_NETWORK_NAME } = require("hardhat/plugins")
8156

57+
// after 2.15.0, the internal createProvider function has a different signature
58+
const newCreateProviderSignature = semver.satisfies(hardhatPackage.version, "^2.15.0");
59+
8260
let provider, networkName, networkConfig;
8361
let isHardhatEVM = false;
8462

@@ -91,12 +69,20 @@ function setupHardhatNetwork(env, api, ui){
9169
networkConfig = env.network.config;
9270
configureHardhatEVMGas(networkConfig, api);
9371

94-
provider = createProvider(
95-
networkName,
96-
networkConfig,
97-
env.config.paths,
98-
env.artifacts,
99-
)
72+
if (newCreateProviderSignature) {
73+
provider = await createProvider(
74+
env.config,
75+
networkName,
76+
env.artifacts,
77+
)
78+
} else {
79+
provider = createProvider(
80+
networkName,
81+
networkConfig,
82+
env.config.paths,
83+
env.artifacts,
84+
)
85+
}
10086

10187
// HttpProvider
10288
} else {
@@ -106,7 +92,12 @@ function setupHardhatNetwork(env, api, ui){
10692
networkConfig = env.config.networks[networkName]
10793
configureNetworkGas(networkConfig, api);
10894
configureHttpProvider(networkConfig, api, ui)
109-
provider = createProvider(networkName, networkConfig);
95+
96+
if (newCreateProviderSignature) {
97+
provider = await createProvider(env.config, networkName);
98+
} else {
99+
provider = createProvider(networkName, networkConfig);
100+
}
110101
}
111102

112103
return configureNetworkEnv(
@@ -227,7 +218,7 @@ function setNetworkFrom(networkConfig, accounts){
227218
// TODO: Hardhat cacheing??
228219
/**
229220
* Generates a path to a temporary compilation cache directory
230-
* @param {BuidlerConfig} config
221+
* @param {HardhatConfig} config
231222
* @return {String} .../.coverage_cache
232223
*/
233224
function tempCacheDir(config){
@@ -236,7 +227,7 @@ function tempCacheDir(config){
236227

237228
/**
238229
* Silently removes temporary folders and calls api.finish to shut server down
239-
* @param {Buidler/HardhatConfig} config
230+
* @param {HardhatConfig} config
240231
* @param {SolidityCoverage} api
241232
* @return {Promise}
242233
*/
@@ -260,7 +251,6 @@ module.exports = {
260251
normalizeConfig,
261252
finish,
262253
tempCacheDir,
263-
setupBuidlerNetwork,
264254
setupHardhatNetwork,
265255
getTestFilePaths,
266256
setNetworkFrom,

0 commit comments

Comments
 (0)