Code coverage for Solidity smart-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
cgewecke a43ee6553e
Clarify compiler optimization warning
5 years ago
.circleci Use ganache server (instead of provider) (#402) 5 years ago
dist Add --temp command flag (#414) 5 years ago
docs Docs for beta release (#415) 5 years ago
lib Add 'onCompileComplete' option (#413) 5 years ago
scripts Fix zeppelin CI run 5 years ago
test Add --temp command flag (#414) 5 years ago
.gitignore Docs for beta release (#415) 5 years ago
.npmignore Docs for beta release (#415) 5 years ago
CHANGELOG.md Update changelog: 0.6.7 5 years ago
LICENSE Add MIT License 8 years ago
README.md Clarify compiler optimization warning 5 years ago
buidler.config.js Initial draft: 0.7.0 5 years ago
index.js Add index.js stub 5 years ago
package.json Update version to 0.7.0-beta.2 5 years ago
truffle-plugin.json Truffle plugin draft 5 years ago
yarn.lock Pre-empt EADDRINUSE and show useful error. (#407) 5 years ago

README.md

solidity-coverage

Gitter chat npm (tag) CircleCI codecov

Code coverage for Solidity testing

coverage example

Install

$ npm install --save-dev solidity-coverage@beta

Truffle V5

Add this package to your plugins array in truffle-config.js

module.exports = {
  networks: {...},
  plugins: ["solidity-coverage"]
}

Run

truffle run coverage [command-options]

Usage notes:

  • Coverage runs tests a little more slowly.
  • Coverage launches its own in-process ganache server.
  • You can set ganache options using the providerOptions key in your .solcover.js config.
  • Coverage distorts gas consumption. Tests that check exact gas consumption should be skipped.
  • Contracts are compiled without optimization. Please report unexpected compilation faults to issue 417

Command Options

Option Example Description
file --file="test/registry/*.js" Filename or glob describing a subset of JS tests to run. (Globs must be enclosed by quotes.)
solcoverjs --solcoverjs ./../.solcover.js Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed)
network --network development Use network settings defined in the Truffle config
temp* --temp build Caution Path to a disposable folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. More...
version Version info
help Usage notes

* Advanced use

Config Options

Additional options can be specified in a .solcover.js config file located in the root directory of your project.

Example:

module.exports = {
  skipFiles: ['Routers/EtherRouter.sol']
};
Option Type Default Description
silent Boolean false Suppress logging output
client Object require("ganache-core") Useful if you need a specific ganache version.
providerOptions Object { } ganache-core options
skipFiles Array ['Migrations.sol'] Array of contracts or folders (with paths expressed relative to the contracts directory) that should be skipped when doing instrumentation.
istanbulReporter Array ['html', 'lcov', 'text'] Istanbul coverage reporters
mocha Object { } Mocha options to merge into existing mocha config. grep and invert are useful for skipping certain tests under coverage using tags in the test descriptions.
onServerReady* Function Hook run after server is launched, before the tests execute. Useful if you need to use the Oraclize bridge or have setup scripts which rely on the server's availability. More...
onCompileComplete* Function Hook run after compilation completes, before tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. More...
onTestsComplete* Function Hook run after the tests complete, before Istanbul reports are generated.
onIstanbulComplete* Function Hook run after the Istanbul reports are generated, before the ganache server is shut down. Useful if you need to clean resources up.

* Advanced use

FAQ

Common problems & questions:

Example reports

Contribution Guidelines

Contributions are welcome! If you're opening a PR that adds features or options please consider writing full unit tests for them. (We've built simple fixtures for almost everything and are happy to add some for your case if necessary).

Set up the development environment with:

$ git clone https://github.com/sc-forks/solidity-coverage.git
$ yarn

Contributors