- 0x.js@0.33.2 - @0xproject/abi-gen@0.2.6 - @0xproject/assert@0.2.1 - @0xproject/base-contract@0.0.4 - chai-as-promised-typescript-typings@0.0.11 - chai-typescript-typings@0.0.5 - @0xproject/connect@0.6.4 - contracts@2.1.16 - @0xproject/deployer@0.3.0 - @0xproject/dev-utils@0.3.0 - ethers-typescript-typings@0.0.3 - @0xproject/json-schemas@0.7.15 - @0xproject/monorepo-scripts@0.1.13 - @0xproject/react-docs-example@0.0.2 - @0xproject/react-docs@0.0.2 - @0xproject/react-shared@0.0.2 - @0xproject/sol-cov@0.0.2 - @0xproject/sra-report@0.0.2 - @0xproject/subproviders@0.8.0 - @0xproject/testnet-faucets@1.0.17 - @0xproject/tslint-config@0.4.11 - @0xproject/types@0.4.0 - @0xproject/utils@0.4.2 - web3-typescript-typings@0.10.1 - @0xproject/web3-wrapper@0.3.0 - @0xproject/website@0.0.19
@0xproject/sol-cov
A Solidity code coverage tool.
Installation
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 instance you use when running your Solidity tests. If you're unfamiliar with ProviderEngine, please read the Web3 Provider explained wiki article.
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.
import { CoverageSubprovider } from '@0xproject/sol-cov';
const provider = new ProviderEngine();
const artifactsPath = 'src/artifacts';
const contractsPath = 'src/contracts';
const networkId = 50;
// Some calls might not have `from` address specified. Nevertheless - transactions need to be submitted from an address with at least some funds. defaultFromAddress is the address that will be used to submit those calls as transactions from.
const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
const coverageSubprovider = new CoverageSubprovider(artifactsPath, contractsPath, networkId, defaultFromAddress);
provider.addProvider(coverageSubprovider);
After your test suite is complete (e.g global after
hook), 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 - 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 before getting started.
Install Dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
yarn config set workspaces-experimental true
Then install dependencies
yarn install
Lint
yarn lint