blob: fec08739495a0c202604da07be63b85b0bb4e6c1 (
plain) (
tree)
|
|
## @0xproject/sol-cov
A Solidity code coverage tool.
## Installation
```bash
yarn add -D @0xproject/sol-cov
```
## Usage
Sol-cov uses transaction traces in order to figure out which lines of Solidity source code have been covered by your tests. In order for it to gather these traces, you must add the `CoverageSubprovider` to the [ProviderEngine](https://github.com/MetaMask/provider-engine) instance you use when running your Solidity tests. If you're unfamiliar with ProviderEngine, please read the [Web3 Provider explained](https://0xproject.com/wiki#Web3-Provider-Explained) wiki article.
```
import { CoverageSubprovider } from '@0xproject/sol-cov'
const provider = new ProviderEngine();
const artifactsPath = 'src/artifacts';
const contractsPath = 'src/contracts';
const networkId = 50;
const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
const coverageSubprovider = new CoverageSubprovider(
artifactsPath,
contractsPath,
networkId,
defaultFromAddress,
);
provider.addProvider(coverageSubprovider);
```
The CoverageSubprovider eavesdrops on the `eth_sendTransaction` and `eth_call` RPC calls and collects traces after each call using `debug_traceTransaction`. `eth_call`'s' don't generate traces - so we take a snapshot, re-submit it as a transaction, get the trace and then revert the snapshot.
After all your tests are run, you'll need to call:
```
await coverageSubprovider.writeCoverageAsync()
```
This will create a `coverage.json` file in the `coverage` directory. This file has an [Istanbul format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md) - so you can use any of the existing Instanbul reporters.
## Contributing
We strongly encourage the community to help us make improvements. To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install Dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Lint
```bash
yarn lint
```
|