Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
# Solidity-Coverage API Documentation
# Solidity-Coverage API

`solidity-coverage`'s API provides test coverage measurement for the Solidity language.
The repository contains two complete coverage tool/plugin implementations (for Buidler and Truffle)
which can be used as sources if you're building something similar.
solidity-coverage tracks which lines are hit as your tests run by instrumenting the contracts with special solidity statements and detecting their execution in a coverage-enabled EVM.

`solidity-coverage`'s core algorithm resembles the one used by [Istanbul][3] for javascript programs.
It tracks line and branch locations by 'instrumenting' solidity contracts with special solidity
statements and detecting their execution in a coverage-enabled EVM. As such, its API spans the
full set of tasks typically required to run a solidity test suite.
As such, the API spans the full set of tasks typically required to run a solidity test suite. The
table below shows how its core methods relate to the stages of a test run:

+ compile
+ ethereum client launch
+ test
+ report outcome and exit
| Test Stage <img width=200/> | API Method <img width=200/> | Description <img width=800/> |
|---------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| compilation | `instrument` | A **pre-compilation** step: Rewrites contracts and generates an instrumentation data map. |
| client launch | `ganache` | A **substitute** step: Launches a ganache client with coverage collection enabled in its VM. As the client,runs it will mark line/branch hits on the instrumentation data map. |
| test | `report` | A **post-test** step: Generates a coverage report from the data collected by the VM after tests complete. |
| exit | `finish` | A **substitute** step: Shuts client down |

[3]: https://github.com/gotwarlost/istanbul

The API's corresponding methods are:
**Additional Resources:**

+ the library includes [file system utilities](#Utils) for managing the
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)
which can be used as sources if you're building something similar.

+ `instrument`: Rewrites contracts for instrumented compilation. Generates an instrumentation data map.
+ `ganache`: Launches a ganache client with coverage collection enabled in its VM. As the client
runs it will mark line/branch hits on the instrumentation data map.
+ `report`: Generates a coverage report from the data collected by the VM after tests complete. Converts
the instrumentation data map into an object IstanbulJS can process.
+ `finish`: Shuts client down
[5]: https://github.com/sc-forks/solidity-coverage/tree/beta/plugins

The library also includes some file system [utilities](#Utils) which are helpful for managing the
disposable set of contracts/artifacts which coverage must use in lieu of the 'real' contracts/artifacts.

# Table of Contents

Expand Down Expand Up @@ -226,8 +224,8 @@ const config = {

## loadSolcoverJS

Loads `.solcoverjs`. Users may specify options described in the README in `.solcover.js` config
file which your application needs to consume.
Loads `.solcoverjs`. Users may specify [options][7] in `.solcover.js` config file which your
application needs to consume.

**Parameters**

Expand All @@ -242,6 +240,8 @@ const solcoverJS = utils.loadSolcoverJS(config);
const api = new CoverageAPI(solcoverJS);
```

[7]: https://github.com/sc-forks/solidity-coverage/tree/beta#config-options

-------------

## assembleFiles
Expand Down Expand Up @@ -360,9 +360,8 @@ Returns **Promise**

**Example**
```javascript
await utils.finish();
await utils.finish(config, api);
```