Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Sep 21, 2023
2 parents 5bb5b3f + c680e54 commit ae7e290
Show file tree
Hide file tree
Showing 13 changed files with 712 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- checkout
- <<: *step_install_nvm
- run:
name: Buidler & Hardhat E2E
name: Hardhat E2E
command: |
./scripts/run-nomiclabs.sh
workflows:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

0.8.4 / 2023-07-04
==================
* Update solidity-parser to 0.16.0 (https://github.com/sc-forks/solidity-coverage/issues/802)

0.8.3 / 2023-06-22
==================
* Updates for Hardhat v2.15.0 (https://github.com/sc-forks/solidity-coverage/pull/796)

0.8.1 / 2022-09-06
===================
* Restore web3-utils (https://github.com/sc-forks/solidity-coverage/issues/743)
Expand Down
1 change: 0 additions & 1 deletion HARDHAT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ More documentation, including FAQ and information about solidity-coverage's API
[29]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/upgrade.md#upgrading-from-06x-to-070
[30]: https://github.com/sc-forks/solidity-coverage/tree/0.6.x-final#solidity-coverage
[31]: https://github.com/sc-forks/solidity-coverage/releases/tag/v0.7.0
[32]: https://github.com/sc-forks/buidler-e2e/tree/coverage
[33]: https://github.com/sc-forks/moloch
[34]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#reducing-the-instrumentation-footprint

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![npm (tag)](https://img.shields.io/npm/v/solidity-coverage/latest)
[![CircleCI](https://circleci.com/gh/sc-forks/solidity-coverage.svg?style=svg)][20]
[![codecov](https://codecov.io/gh/sc-forks/solidity-coverage/branch/master/graph/badge.svg)][21]
[![buidler](https://buidler.dev/buidler-plugin-badge.svg?1)][26]
[![Hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)][26]


## Code coverage for Solidity testing
Expand Down Expand Up @@ -197,13 +197,12 @@ $ yarn
[23]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#workflow-hooks
[24]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#skipping-tests
[25]: https://github.com/sc-forks/solidity-coverage/issues/417
[26]: https://buidler.dev/
[26]: https://hardhat.org/
[27]: https://www.trufflesuite.com/docs
[28]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/api.md
[29]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/upgrade.md#upgrading-from-06x-to-070
[30]: https://github.com/sc-forks/solidity-coverage/tree/0.6.x-final#solidity-coverage
[31]: https://github.com/sc-forks/solidity-coverage/releases/tag/v0.7.0
[32]: https://github.com/sc-forks/buidler-e2e/tree/coverage
[33]: https://github.com/sc-forks/moloch
[34]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#reducing-the-instrumentation-footprint
[35]: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/e5fbbda9bac49039847a7ed20c1d966766ecc64a/scripts/coverage.js
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ table below shows how its core methods relate to the stages of a test run:
disposable set of contracts/artifacts which coverage must use in lieu of the 'real' (uninstrumented)
contracts.

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

[5]: https://github.com/sc-forks/solidity-coverage/tree/master/plugins
Expand Down
8 changes: 4 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Downloading compiler version 0.5.16
Extra non-whitespace after JSON value.
```

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

Expand Down Expand Up @@ -92,11 +92,11 @@ If your project is large, complex and uses ABI encoder V2 or Solidity >= V8, you
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.)

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

**Work-around #2**
+ Set the `.solcoverjs` option: `configureYulOptimizer` to `true`.
+ Set the `.solcoverjs` option: `solcOptimizerDetails` to:
+ Set the `.solcover.js` option: `configureYulOptimizer` to `true`.
+ Set the `.solcover.js` option: `solcOptimizerDetails` to:
```js
{
peephole: false,
Expand Down
9 changes: 8 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,17 @@ class API {
}

// Hardhat
attachToHardhatVM(provider){
async attachToHardhatVM(provider){
const self = this;
this.collector = new DataCollector(this.instrumenter.instrumentationData);

if ('init' in provider) {
// Newer versions of Hardhat initialize the provider lazily, so we need to
// call provider.init() explicitly. This is a no-op if the provider is
// already initialized.
await provider.init();
}

let cur = provider;

// Go down to core HardhatNetworkProvider
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-coverage",
"version": "0.8.1",
"version": "0.8.4",
"description": "Code coverage for Solidity testing",
"main": "plugins/nomiclabs.plugin.js",
"bin": {
Expand All @@ -25,7 +25,7 @@
"license": "ISC",
"dependencies": {
"@ethersproject/abi": "^5.0.9",
"@solidity-parser/parser": "^0.14.1",
"@solidity-parser/parser": "^0.16.0",
"chalk": "^2.4.2",
"death": "^1.1.0",
"detect-port": "^1.3.0",
Expand All @@ -36,7 +36,7 @@
"globby": "^10.0.1",
"jsonschema": "^1.2.4",
"lodash": "^4.17.15",
"mocha": "7.1.2",
"mocha": "10.2.0",
"node-emoji": "^1.10.0",
"pify": "^4.0.1",
"recursive-readdir": "^2.2.2",
Expand All @@ -56,7 +56,7 @@
"ethereum-waffle": "^3.4.0",
"ethers": "^5.5.3",
"ganache-cli": "6.12.2",
"hardhat": "^2.11.0",
"hardhat": "^2.17.3",
"hardhat-gas-reporter": "^1.0.1",
"nyc": "^14.1.1",
"solc": "^0.7.5"
Expand Down
8 changes: 4 additions & 4 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ task("coverage", "Generates a code coverage report for tests")
// ==============
// Server launch
// ==============
let network = nomiclabsUtils.setupHardhatNetwork(env, api, ui);
let network = await nomiclabsUtils.setupHardhatNetwork(env, api, ui);

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

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

api.attachToHardhatVM(network.provider);
await api.attachToHardhatVM(network.provider);

ui.report('hardhat-network', [
nodeInfo.split('/')[1],
Expand Down
72 changes: 31 additions & 41 deletions plugins/resources/nomiclabs.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ const util = require('util')
function getTestFilePaths(files){
const target = globby.sync([files])

// Buidler/Hardhat supports js & ts
// Hardhat supports js & ts
const testregex = /.*\.(js|ts)$/;
return target.filter(f => f.match(testregex) != null);
}

/**
* Normalizes Buidler/Hardhat paths / logging for use by the plugin utilities and
* Normalizes Hardhat paths / logging for use by the plugin utilities and
* attaches them to the config
* @param {Buidler/HardhatConfig} config
* @return {Buidler/HardhatConfig} updated config
* @param {HardhatConfig} config
* @return {HardhatConfig} updated config
*/
function normalizeConfig(config, args={}){
config.workingDir = config.paths.root;
Expand All @@ -49,36 +49,14 @@ function normalizeConfig(config, args={}){
return config;
}

function setupBuidlerNetwork(env, api, ui){
const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/construction");

let networkConfig = {};

let networkName = (env.buidlerArguments.network !== 'buidlerevm')
? env.buidlerArguments.network
: api.defaultNetworkName;

if (networkName !== api.defaultNetworkName){
networkConfig = env.config.networks[networkName];
configureHttpProvider(networkConfig, api, ui)
} else {
networkConfig.url = `http://${api.host}:${api.port}`
}

const provider = createProvider(networkName, networkConfig);

return configureNetworkEnv(
env,
networkName,
networkConfig,
provider
)
}

function setupHardhatNetwork(env, api, ui){
async function setupHardhatNetwork(env, api, ui){
const hardhatPackage = require('hardhat/package.json');
const { createProvider } = require("hardhat/internal/core/providers/construction");
const { HARDHAT_NETWORK_NAME } = require("hardhat/plugins")

// after 2.15.0, the internal createProvider function has a different signature
const newCreateProviderSignature = semver.satisfies(hardhatPackage.version, "^2.15.0");

let provider, networkName, networkConfig;
let isHardhatEVM = false;

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

provider = createProvider(
networkName,
networkConfig,
env.config.paths,
env.artifacts,
)
if (newCreateProviderSignature) {
provider = await createProvider(
env.config,
networkName,
env.artifacts,
)
} else {
provider = createProvider(
networkName,
networkConfig,
env.config.paths,
env.artifacts,
)
}

// HttpProvider
} else {
Expand All @@ -106,7 +92,12 @@ function setupHardhatNetwork(env, api, ui){
networkConfig = env.config.networks[networkName]
configureNetworkGas(networkConfig, api);
configureHttpProvider(networkConfig, api, ui)
provider = createProvider(networkName, networkConfig);

if (newCreateProviderSignature) {
provider = await createProvider(env.config, networkName);
} else {
provider = createProvider(networkName, networkConfig);
}
}

return configureNetworkEnv(
Expand Down Expand Up @@ -227,7 +218,7 @@ function setNetworkFrom(networkConfig, accounts){
// TODO: Hardhat cacheing??
/**
* Generates a path to a temporary compilation cache directory
* @param {BuidlerConfig} config
* @param {HardhatConfig} config
* @return {String} .../.coverage_cache
*/
function tempCacheDir(config){
Expand All @@ -236,7 +227,7 @@ function tempCacheDir(config){

/**
* Silently removes temporary folders and calls api.finish to shut server down
* @param {Buidler/HardhatConfig} config
* @param {HardhatConfig} config
* @param {SolidityCoverage} api
* @return {Promise}
*/
Expand All @@ -260,7 +251,6 @@ module.exports = {
normalizeConfig,
finish,
tempCacheDir,
setupBuidlerNetwork,
setupHardhatNetwork,
getTestFilePaths,
setNetworkFrom,
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-nomiclabs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# E2E CI: installs PR candidate on sc-forks/buidler-e2e (a simple example,
# E2E CI: installs PR candidate on sc-forks/hardhat-e2e (a simple example,
# similar to Metacoin) and runs coverage
#

Expand Down
4 changes: 2 additions & 2 deletions scripts/run-zeppelin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ cd openzeppelin-contracts
echo ">>>>> npm install"
npm install

# Use HH Merge version
npm install hardhat@2.11.0 --save-dev
# Use HH latest
npm install hardhat@latest --save-dev

echo ">>>>> npm uninstall solidity-coverage --save-dev"
npm uninstall solidity-coverage --save-dev
Expand Down
Loading

0 comments on commit ae7e290

Please sign in to comment.