Solidity code coverage plugin for buidler.
- For more details about how it works and potential limitations, see the accompanying article.
solidity-coverage
is also JoinColony/solcover
$ npm install --save-dev solidity-coverage
And add the following to your buidler.config.js
:
usePlugin("solidity-coverage");
module.exports = {
networks: {
coverage: {
url: 'http://localhost:8555'
}
},
}
This plugin implements a coverage
task
npx buidler coverage --network coverage [options]
Options can be specified in a .solcover.js
config file located in the root directory of your project.
Project Examples:
- Simple: buidler-metacoin
- More complex: MolochDao/moloch
Config 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. |
istanbulFolder | String | ./coverage |
Folder location for Istanbul coverage reports. |
istanbulReporter | Array | ['html', 'lcov', 'text', 'json'] |
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. More... | |
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. More... |
- 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
More documentation, including FAQ and information about solidity-coverage's API is available here.