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 438b2fef0f Add onServerReady, onTestsComplete, onIstanbulComplete Hooks (#408) 5 years ago
.circleci Use ganache server (instead of provider) (#402) 5 years ago
dist Add onServerReady, onTestsComplete, onIstanbulComplete Hooks (#408) 5 years ago
docs Remove send/transfer warnings in README & docs 5 years ago
lib Add onServerReady, onTestsComplete, onIstanbulComplete Hooks (#408) 5 years ago
scripts Use ganache server (instead of provider) (#402) 5 years ago
test Add onServerReady, onTestsComplete, onIstanbulComplete Hooks (#408) 5 years ago
.gitignore Fix circle/ci 5 years ago
.npmignore Initial draft: 0.7.0 5 years ago
CHANGELOG.md Update changelog: 0.6.7 5 years ago
LICENSE Add MIT License 8 years ago
README.md Add onServerReady, onTestsComplete, onIstanbulComplete Hooks (#408) 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 Pre-empt EADDRINUSE and show useful error. (#407) 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

Join the chat at https://gitter.im/sc-forks/solidity-coverage npm version CircleCI codecov

Code coverage for Solidity testing

coverage example

  • For more details about what this is, how it works and potential limitations, see the accompanying article.
  • solidity-coverage is in development and its accuracy is unknown. If you find discrepancies between the coverage report and your suite's behavior, please open an issue.
  • solidity-coverage is Solcover

Install

$ npm install --save-dev solidity-coverage

Usage notes:

  • For pragma solidity >=0.4.22 <0.6.0 / Petersburg
  • Coverage runs tests a little more slowly.
  • Coverage distorts gas consumption.
  • Coverage launches its own in-process ganache instance. You can set ganache options via the providerOptions key in your .solcover.js config file.

Truffle V5

Add "solidity-coverage" to your plugins array in truffle-config.js

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

Run

truffle run coverage [options]

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)
--useGlobalTruffle Force use of truffle library module from globally installed truffle. (Default: false)
--usePluginTruffle Force use of truffle library module from plugin provided copy (Truffle v5.0.31.) Requires you have locally installed Truffle V5 <= 5.0.30 (Default: false)
--version Version info
--help Usage notes

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
client Object require("truffle").ganache Useful if you need a specific ganache version. (usage: client: require("ganache-core"))
providerOptions Object {} ganache-core options (ex: network_id: 55). Complete list of options here.
skipFiles Array ['Migrations.sol'] Array of contracts or folders (with paths expressed relative to the contracts directory) that should be skipped when doing instrumentation. Migrations.sol is skipped by default, and does not need to be added to this configuration option if it is used.
istanbulReporter Array ['html', 'lcov', 'text'] Coverage reporters for Istanbul. Optional reporter replaces the default reporters.
silent Boolean false suppress logging output
onServerReady Function async (config) => {} Function run when server is ready to receive calls, but before the tests execute. Useful if you need to launch the Oraclize/Provable bridge or have preparatory scripts which rely on the server's availability
onTestsComplete Function async (config) => {} Function run immediately after the tests
complete, but before Istanbul reports are generated.
onIstanbulComplete Function async (config) => {} Function run immediately after the Istanbul reports are generated, but before the ganache server is shut down. Useful if you need to clean resources up.

FAQ

Common problems & questions:

Example reports

Contribution Guidelines

Contributions are welcome! If you're opening a PR that adds features please consider writing some unit tests for them. Bugs can be reported in the issues.

Set up the development environment with:

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

Contributors