Skip to content

Commit c1d9ea1

Browse files
authored
Improve API docs overview (#452)
1 parent f7603ac commit c1d9ea1

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

docs/api.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
# Solidity-Coverage API Documentation
1+
# Solidity-Coverage API
22

3-
`solidity-coverage`'s API provides test coverage measurement for the Solidity language.
4-
The repository contains two complete coverage tool/plugin implementations (for Buidler and Truffle)
5-
which can be used as sources if you're building something similar.
3+
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.
64

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

12-
+ compile
13-
+ ethereum client launch
14-
+ test
15-
+ report outcome and exit
8+
| Test Stage <img width=200/> | API Method <img width=200/> | Description <img width=800/> |
9+
|---------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10+
| compilation | `instrument` | A **pre-compilation** step: Rewrites contracts and generates an instrumentation data map. |
11+
| 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. |
12+
| test | `report` | A **post-test** step: Generates a coverage report from the data collected by the VM after tests complete. |
13+
| exit | `finish` | A **substitute** step: Shuts client down |
1614

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

19-
The API's corresponding methods are:
17+
**Additional Resources:**
18+
19+
+ the library includes [file system utilities](#Utils) for managing the
20+
disposable set of contracts/artifacts which coverage must use in lieu of the 'real' (uninstrumented)
21+
contracts.
22+
23+
+ there are two complete [coverage tool/plugin implementations][5] (for Buidler and Truffle)
24+
which can be used as sources if you're building something similar.
2025

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

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

3129
# Table of Contents
3230

@@ -226,8 +224,8 @@ const config = {
226224

227225
## loadSolcoverJS
228226

229-
Loads `.solcoverjs`. Users may specify options described in the README in `.solcover.js` config
230-
file which your application needs to consume.
227+
Loads `.solcoverjs`. Users may specify [options][7] in `.solcover.js` config file which your
228+
application needs to consume.
231229

232230
**Parameters**
233231

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

243+
[7]: https://github.com/sc-forks/solidity-coverage/tree/beta#config-options
244+
245245
-------------
246246

247247
## assembleFiles
@@ -360,9 +360,8 @@ Returns **Promise**
360360

361361
**Example**
362362
```javascript
363-
await utils.finish();
363+
await utils.finish(config, api);
364364
```
365365

366366

367367

368-

0 commit comments

Comments
 (0)