Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sc-forks/solidity-coverage
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9d2483594d55d7c4c46eb1a704ea27981554073f
Choose a base ref
...
head repository: sc-forks/solidity-coverage
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bfe149c4c020306aa31ada4925f765ea5fd1c9f1
Choose a head ref
  • 14 commits
  • 14 files changed
  • 6 contributors

Commits on May 26, 2023

  1. Copy the full SHA
    e1416d9 View commit details

Commits on Jun 22, 2023

  1. Copy the full SHA
    5aee556 View commit details
  2. 0.8.3

    cgewecke committed Jun 22, 2023
    Copy the full SHA
    89882a2 View commit details

Commits on Jul 4, 2023

  1. Copy the full SHA
    2b20b1a View commit details
  2. 0.8.4

    cgewecke committed Jul 4, 2023
    Copy the full SHA
    4da00a8 View commit details
  3. Update changelog: 0.8.4

    cgewecke committed Jul 4, 2023
    Copy the full SHA
    1d69897 View commit details

Commits on Sep 21, 2023

  1. Copy the full SHA
    d5c134b View commit details
  2. Copy the full SHA
    b56f209 View commit details
  3. Copy the full SHA
    dea15cd View commit details
  4. Copy the full SHA
    c680e54 View commit details
  5. Add a package description to package.json (#775)

    ilovehackathons authored Sep 21, 2023
    Copy the full SHA
    70a5084 View commit details
  6. Copy the full SHA
    255d700 View commit details
  7. Copy the full SHA
    34beea7 View commit details
  8. 0.8.5

    cgewecke committed Sep 21, 2023
    Copy the full SHA
    bfe149c View commit details
Showing with 736 additions and 250 deletions.
  1. +1 −1 .circleci/config.yml
  2. +18 −0 .github/dependabot.yaml
  3. +8 −0 CHANGELOG.md
  4. +0 −1 HARDHAT_README.md
  5. +7 −4 README.md
  6. +1 −1 docs/api.md
  7. +4 −4 docs/faq.md
  8. +8 −1 lib/api.js
  9. +5 −5 package.json
  10. +4 −4 plugins/hardhat.plugin.js
  11. +31 −41 plugins/resources/nomiclabs.utils.js
  12. +1 −1 scripts/run-nomiclabs.sh
  13. +2 −2 scripts/run-zeppelin.sh
  14. +646 −185 yarn.lock
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ jobs:
- checkout
- <<: *step_install_nvm
- run:
name: Buidler & Hardhat E2E
name: Hardhat E2E
command: |
./scripts/run-nomiclabs.sh
workflows:
18 changes: 18 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
---
version: 2
updates:
- package-ecosystem: npm
directory: /
open-pull-requests-limit: 5
schedule:
interval: daily
time: "9:00"
timezone: MST
commit-message:
prefix: build
include: scope
assignees:
- cgewecke
labels:
- build
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)
1 change: 0 additions & 1 deletion HARDHAT_README.md
Original file line number Diff line number Diff line change
@@ -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

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
@@ -91,7 +91,7 @@ module.exports = {

[<sup>*</sup> Advanced use][14]

## Viewing the reports:
## Viewing the reports:
+ You can find the Istanbul reports written to the `./coverage/` folder generated in your root directory.

## API
@@ -171,6 +171,10 @@ $ yarn
+ [@Shelvak](https://github.com/Shelvak)
+ [@rynobey](https://github.com/rynobey)
+ [@ZumZoom](https://github.com/ZumZoom)
+ [@fvictorio](https://github.com/fvictorio)
+ [@ChristopherDedominici](https://github.com/ChristopherDedominici)
+ [@joaoh9](https://github.com/joaoh9)
+ [@ilovehackathons](https://github.com/ilovehackathons)

[1]: https://github.com/trufflesuite/ganache-core#options
[2]: https://istanbul.js.org/docs/advanced/alternative-reporters/
@@ -197,13 +201,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
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -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.

@@ -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,
9 changes: 8 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solidity-coverage",
"version": "0.8.2",
"description": "",
"version": "0.8.5",
"description": "Code coverage for Solidity testing",
"main": "plugins/nomiclabs.plugin.js",
"bin": {
"solidity-coverage": "./plugins/bin.js"
@@ -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",
@@ -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",
@@ -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"
8 changes: 4 additions & 4 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
@@ -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],
72 changes: 31 additions & 41 deletions plugins/resources/nomiclabs.utils.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;

@@ -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 {
@@ -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(
@@ -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){
@@ -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}
*/
@@ -260,7 +251,6 @@ module.exports = {
normalizeConfig,
finish,
tempCacheDir,
setupBuidlerNetwork,
setupHardhatNetwork,
getTestFilePaths,
setNetworkFrom,
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
#

4 changes: 2 additions & 2 deletions scripts/run-zeppelin.sh
Original file line number Diff line number Diff line change
@@ -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
Loading