Docs for beta release (#415)

truffle-plugin
cgewecke 5 years ago
parent fab8aaa543
commit 00f32f68d2
  1. 1
      .gitignore
  2. 3
      .npmignore
  3. 126
      README.md
  4. 88
      docs/advanced.md
  5. 143
      docs/faq.md
  6. 91
      docs/testrpc-sc.md
  7. 138
      docs/upgrade.md

1
.gitignore vendored

@ -5,6 +5,5 @@ node_modules/
.DS_Store
test/artifacts
test/cache
yarn.lock
temp
.nyc_output/

@ -1,3 +1,4 @@
test/
.circleci/
docs/
docs/
.nyc_output/

@ -1,33 +1,25 @@
# solidity-coverage
[![Join the chat at https://gitter.im/sc-forks/solidity-coverage](https://badges.gitter.im/sc-forks/solidity-coverage.svg)](https://gitter.im/sc-forks/solidity-coverage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![npm version](https://badge.fury.io/js/solidity-coverage.svg)](https://badge.fury.io/js/solidity-coverage)
[![CircleCI](https://circleci.com/gh/sc-forks/solidity-coverage.svg?style=svg)](https://circleci.com/gh/sc-forks/solidity-coverage)
[![codecov](https://codecov.io/gh/sc-forks/solidity-coverage/branch/master/graph/badge.svg)](https://codecov.io/gh/sc-forks/solidity-coverage)
### Code coverage for Solidity testing
![coverage example](https://cdn-images-1.medium.com/max/800/1*uum8t-31bUaa6dTRVVhj6w.png)
+ For more details about what this is, how it works and potential limitations, see
[the accompanying article](https://blog.colony.io/code-coverage-for-solidity-eecfa88668c2).
+ `solidity-coverage` is in development and **its accuracy is unknown.** If you
find discrepancies between the coverage report and your suite's behavior, please open an
[issue](https://github.com/sc-forks/solidity-coverage/issues).
+ `solidity-coverage` is [Solcover](https://github.com/JoinColony/solcover)
### Install
[![Gitter chat](https://badges.gitter.im/sc-forks/solidity-coverage.svg)][18]
![npm (tag)](https://img.shields.io/npm/v/solidity-coverage/beta)
[![CircleCI](https://circleci.com/gh/sc-forks/solidity-coverage.svg?style=svg)][20]
[![codecov](https://codecov.io/gh/sc-forks/solidity-coverage/branch/beta/graph/badge.svg)][21]
## Code coverage for Solidity testing
![coverage example][22]
+ For more details about what this is, how it works and potential limitations,
see [the accompanying article][16].
+ `solidity-coverage` is [Solcover][17]
## Install
```
$ npm install --save-dev solidity-coverage@beta
```
### Usage notes:
+ Coverage runs tests a little more slowly.
+ Coverage distorts gas consumption. Tests that check exact gas consumption should be skipped.
+ Coverage launches its own in-process ganache server.
+ You can set [ganache options](https://github.com/trufflesuite/ganache-core#options) using the `providerOptions` key in your `.solcover.js` config.
### Truffle V5
## Truffle V5
**Add** "solidity-coverage" to your plugins array in `truffle-config.js`
**Add** this package to your plugins array in `truffle-config.js`
```javascript
module.exports = {
networks: {...},
@ -36,24 +28,31 @@ module.exports = {
```
**Run**
```
truffle run coverage [options]
truffle run coverage [command-options]
```
## Usage notes:
+ Coverage runs tests a little more slowly.
+ Coverage launches its own in-process ganache server.
+ You can set [ganache options][1] using the `providerOptions` key in your `.solcover.js` [config][15].
+ Coverage [distorts gas consumption][13]. Tests that check exact gas consumption should be skipped.
### Command Options
| Option <img width=200/> | Example <img width=700/>| Description <img width=1000/> |
## Command Options
| Option <img width=200/> | Example <img width=750/>| Description <img width=1000/> |
|--------------|------------------------------------|--------------------------------|
| file | `--file="test/registry/*.js"` | Filename or glob describing a subset of JS tests to run. (Globs must be enclosed by quotes.)|
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
| network | `--network development` | Use network settings defined in the Truffle config |
| temp | `--temp build` | :warning: *Use with caution* :warning:. Disposable folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. |
| temp[<sup>*</sup>][14] | `--temp build` | :warning: **Caution** :warning: Path to a *disposable* folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. [More...][14] |
| version | | Version info |
| help | | Usage notes |
### Config Options
[<sup>*</sup> Advanced use][14]
## Config Options
Additional options can be specified in a `.solcover.js` config file located in
the root directory of your project.
Additional options can be specified in a `.solcover.js` config file located in the root directory
of your project.
**Example:**
```javascript
@ -67,37 +66,37 @@ module.exports = {
| ------ | ---- | ------- | ----------- |
| silent | *Boolean* | false | Suppress logging output |
| client | *Object* | `require("ganache-core")` | Useful if you need a specific ganache version. |
| providerOptions | *Object* | `{ }` | [ganache-core options](https://github.com/trufflesuite/ganache-core#options) |
| providerOptions | *Object* | `{ }` | [ganache-core options][1] |
| skipFiles | *Array* | `['Migrations.sol']` | Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. |
| istanbulReporter | *Array* | `['html', 'lcov', 'text']` | [Istanbul coverage reporters](https://istanbul.js.org/docs/advanced/alternative-reporters/) |
| mocha | *Object* | `{ }` | [Mocha options](https://mochajs.org/api/mocha) 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 |
| onTestsComplete | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated. |
| onCompileComplete | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. |
| 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. |
| istanbulReporter | *Array* | `['html', 'lcov', 'text']` | [Istanbul coverage reporters][2] |
| mocha | *Object* | `{ }` | [Mocha options][3] to merge into existing mocha config. `grep` and `invert` are useful for skipping certain tests under coverage using tags in the test descriptions.|
| onServerReady[<sup>*</sup>][14] | *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...][14] |
| onCompileComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. [More...][14]|
| onTestsComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated.|
| onIstanbulComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the Istanbul reports are generated, *before* the ganache server is shut down. Useful if you need to clean resources up.|
[<sup>*</sup> Advanced use][14]
### FAQ
## FAQ
Common problems & questions:
+ [Running out of gas](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-gas)
+ [Running out of memory (locally and in CI)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-memory-locally-and-in-ci)
+ [Running out of time (in mocha)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-time-in-mocha)
+ [Running in CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
+ [Why are asserts and requires highlighted as branch points?](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-has-my-branch-coverage-decreased-why-is-assert-being-shown-as-a-branch-point)
+ [Running in CI][7]
+ [Running out of gas][4]
+ [Running out of time][6]
+ [Running out of memory][5]
+ [Why are `require` statements highlighted as branch points?][8]
### Example reports
+ [metacoin](https://sc-forks.github.io/metacoin/) (Istanbul HTML)
+ [openzeppelin-solidity](https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master) (Coveralls)
## Example reports
+ [metacoin][9] (Istanbul HTML)
+ [openzeppelin-solidity][10](Coveralls)
### Contribution Guidelines
## Contribution Guidelines
Contributions are welcome! If you're opening a PR that adds features please consider writing some
[unit tests](https://github.com/sc-forks/solidity-coverage/tree/master/test) for them. Bugs can be
reported in the [issues](https://github.com/sc-forks/solidity-coverage/issues).
Contributions are welcome! If you're opening a PR that adds features or options *please consider
writing full [unit tests][11] for them*. (We've built simple fixtures for almost everything
and are happy to add some for your case if necessary).
Set up the development environment with:
```
@ -105,7 +104,7 @@ $ git clone https://github.com/sc-forks/solidity-coverage.git
$ yarn
```
### Contributors
## Contributors
+ [@area](https://github.com/area)
+ [@cgewecke](https://github.com/cgewecke)
+ [@adriamb](https://github.com/adriamb)
@ -126,3 +125,26 @@ $ yarn
+ [@angus-hamill](https://github.com/angus-hamill)
+ [@kandrianov](https://github.com/kandrianov)
+ [@yxliang01](https://github.com/yxliang01)
[1]: https://github.com/trufflesuite/ganache-core#options
[2]: https://istanbul.js.org/docs/advanced/alternative-reporters/
[3]: https://mochajs.org/api/mocha
[4]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-gas
[5]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-memory
[6]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-time
[7]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#continuous-integration
[8]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#notes-on-branch-coverage
[9]: https://sc-forks.github.io/metacoin/
[10]: https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master
[11]: https://github.com/sc-forks/solidity-coverage/tree/beta/test/units
[12]: https://github.com/sc-forks/solidity-coverage/issues
[13]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#notes-on-gas-distortion
[14]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md
[15]: #config-options
[16]: https://blog.colony.io/code-coverage-for-solidity-eecfa88668c2
[17]: https://github.com/JoinColony/solcover
[18]: https://gitter.im/sc-forks/solidity-coverage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[19]: https://badge.fury.io/js/solidity-coverage
[20]: https://circleci.com/gh/sc-forks/solidity-coverage
[21]: https://codecov.io/gh/sc-forks/solidity-coverage
[22]: https://cdn-images-1.medium.com/max/800/1*uum8t-31bUaa6dTRVVhj6w.png

@ -0,0 +1,88 @@
# Advanced Use
## Skipping tests
Sometimes it's convenient to skip specific tests when running coverage. You can do this by
tagging your test descriptions and setting appropriate filters in the `.solcover.js` mocha options.
**Example**
```javascript
// Mocha test to skip
it("is a gas usage simulation [ @skip-on-coverage ]", async function(){
...
})
```
```javascript
//.solcover.js
module.exports = {
mocha: {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
}
}
```
## Workflow hooks
The plugin exposes a set of workflow hooks that let you run arbitrary async logic between the main
stages of the coverage generation process. These are useful for tasks like launching secondary
services which need to connect to a running ganache instance (ex: the Oraclize/Provable bridge),
or reading data from the compilation artifacts to run special preparatory steps for your tests.
The stages/hooks are (in order of execution):
| Stage | Post-stage hook |
|----------------------------------------|--------------------|
| Launch server | onServerReady |
| Instrument and compile contracts | onCompileComplete |
| Run tests using instrumented artifacts | onTestsComplete |
| Generate istanbul coverage reports | onIstanbulComplete |
The tool's general workflow is:
+ Launch an ethereum client, attaching special listeners that monitor each opcode execution step
+ Read Solidity contract sources from a standard contracts directory
+ Rewrite the sources so the code execution path can be tracked by the opcode monitors.
+ Compile the modified sources, without optimization
+ Save the compilation artifacts to a temporary folder
+ Tell the testing framework to use the instrumented artifacts & run tests to completion.
+ Transfer collected data to a coverage reporter & report.
Each hook is passed a `config` object provided by your plugin's dev platform which will contain
relevant source/artifact paths and network info for that stage.
**Example**
```javascript
// .solcover.js
const { provableBridge } = require('./helpers');
async function serverReadyHandler(config){
await provableBridge(config.port);
}
module.exports = {
onServerReady: serverReadyHandler,
}
```
## Setting the temporary artifacts directory
The `temp` command line option lets you to specify the name of a disposable folder to
stage the compilation artifacts of instrumented contracts in before the tests are run.
**Example**
```
$ truffle run coverage --temp build
```
By default this folder is called `.coverage_artifacts`. If you already have
preparatory scripts which run between compilation and the tests, you'll probably
find it inconvenient to modify them to handle an alternate path.
This option allows you to avoid that but it's important to realise that the temp
folder is **automatically deleted** when coverage completes. You shouldn't use it if your preferred
build target contains information you want to preserve between test runs.

@ -1,106 +1,107 @@
# FAQ
### Continuous Integration: installing Metacoin on TravisCI with Coveralls
- [Table of Contents](#contents)
* [Continuous Integration](#continuous-integration)
* [Running out of memory](#running-out-of-memory)
* [Running out of time](#running-out-of-time)
* [Notes on gas distortion](#notes-on-gas-distortion)
* [Notes on branch coverage](#notes-on-branch-coverage)
## Continuous Integration
An example using Truffle MetaCoin, TravisCI, and Coveralls:
**Step 1: Create a metacoin project & install coverage tools**
```bash
$ mkdir metacoin && cd metacoin
$ truffle unbox metacoin
$ rm test/TestMetacoin.sol # No solidity tests, sorry.
# Install coverage dependencies
# Install coverage and development dependencies
$ npm init
$ npm install --save-dev truffle
$ npm install --save-dev coveralls
$ npm install --save-dev solidity-coverage
```
**Step 2: Add test and coverage scripts to the `package.json`:**
**Step 2: Add solidity-coverage to the plugins array in truffle-config.js:**
```javascript
"scripts": {
"test": "truffle test",
"coverage": "npx solidity-coverage"
},
module.exports = {
networks: {...},
plugins: ["solidity-coverage"]
}
```
**Step 3: Create a .travis.yml:**
```yml
sudo: required
dist: trusty
language: node_js
node_js:
- '10'
install:
- npm install -g truffle
- npm install -g ganache-cli
- npm install
script:
- npm test
before_script:
- testrpc > /dev/null &
- sleep 5
after_script:
- npm run coverage && cat coverage/lcov.info | coveralls
- npx truffle run coverage
- cat coverage/lcov.info | coveralls
```
**NB:** It's best practice to run coverage in a [parallel CI build](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/.travis.yml) rather than assume its equivalence to `truffle test`. Coverage's `testrpc-sc` uses gasLimits far above the current blocklimit and rewrites your contracts in ways that might affect their behavior. It's also less robust than Truffle and may fail more frequently.
**NB:** It's best practice to run coverage as a separate CI job rather than assume its
equivalence to `test`. Coverage uses block gas settings far above the network limits,
ignores [EIP 170][4] and rewrites your contracts in ways that might affect
their behavior.
**Step 4: Toggle the project on at Travis and Coveralls and push.**
[It should look like this](https://coveralls.io/github/sc-forks/metacoin)
[It should look like this][1]
**Appendix: Coveralls vs. Codecov**
[Codecov.io](https://codecov.io/) is another CI coverage provider (we use it for this project). They're very reliable, easy to integrate with and have a nice UI. Unfortunately we haven't found a way to get their reports to show branch coverage. Coveralls has excellent branch coverage reporting out of the box (see below).
![missed_branch](https://user-images.githubusercontent.com/7332026/28502310-6851f79c-6fa4-11e7-8c80-c8fd80808092.png)
**TLDR: We recommend Coveralls for the accuracy of its branch reporting.**
We use [Codecov.io][2] here as a coverage provider for our JS tests - they're great. Unfortunately we haven't found a way to get their reports to show branch coverage for Solidity. Coveralls has excellent Solidity branch coverage reporting out of the box (see below).
![missed_branch][3]
### Running out of gas
If you have hardcoded gas costs into your tests some of them may fail when using solidity-coverage.
This is because the instrumentation process increases the gas costs for using the contracts, due to
the extra events. If this is the case, then the coverage may be incomplete. To avoid this, using
`estimateGas` to estimate your gas costs should be more resilient in most cases.
## Running out of memory
### Running out of memory (Locally and in CI)
(See [issue #59](https://github.com/sc-forks/solidity-coverage/issues/59)).
If your target contains dozens of contracts, you may run up against node's 1.7MB memory cap during the
contract compilation step. This can be addressed by setting the `testCommand` option in `.solcover.js` as
below:
```javascript
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage'
If your target contains dozens of large contracts, you may run up against node's memory cap during the
contract compilation step. This can be addressed by setting the size of the memory space allocated to the command
when you run it. (NB: you must use the relative path to the truffle `bin` in node_modules)
```
$ node --max-old-space-size=4096 ../node_modules/.bin/truffle run coverage [options]
```
Note the path: it reaches outside a temporarily generated `coverageEnv` folder to access a locally
installed version of truffle in your root directory's `node_modules`.
Large projects may also hit their CI container memcap running coverage after unit tests. This can be
addressed on TravisCI by adding `sudo: required` to the `travis.yml`, which raises the container's
limit to 7.5MB (ProTip courtesy of [@federicobond](https://github.com/federicobond).
## Running out of time
Truffle sets a default mocha timeout of 5 minutes. Because tests run slower under coverage, it's possible to hit this limit with a test that iterates hundreds of times before producing a result. Timeouts can be disabled by configuring the mocha option in `.solcover.js` as below: (ProTip courtesy of [@cag](https://github.com/cag))
### Running out of time (in mocha)
Truffle sets a default mocha timeout of 5 minutes. Because tests run slower under coverage, it's possible to hit this limit with a test that iterates hundreds of times before producing a result. Timeouts can be disabled by configuring the mocha option in `truffle.js` as below: (ProTip courtesy of [@cag](https://github.com/cag))
```javascript
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*"
},
...etc...
},
mocha: {
enableTimeouts: false
enableTimeouts: false
}
}
```
### Why has my branch coverage decreased? Why is assert being shown as a branch point?
## Notes on gas distortion
Solidity-coverage instruments by injecting statements into your code, increasing its execution costs.
`assert` and `require` check whether a condition is true or not. If it is, they allow execution to proceed. If not, they throw, and all changes are reverted. Indeed, prior to [Solidity 0.4.10](https://github.com/ethereum/solidity/releases/tag/v0.4.10), when `assert` and `require` were introduced, this functionality was achieved by code that looked like
+ If you are running gas usage simulations, they will **not be accurate**.
+ If you have hardcoded gas costs into your tests, some of them may **error**.
+ If your solidity logic constrains gas usage within narrow bounds, it may **fail**.
+ Solidity's `.send` and `.transfer` methods usually work fine though.
Using `estimateGas` to calculate your gas costs or allowing your transactions to use the default gas
settings should be more resilient in most cases.
Gas metering within Solidity is increasingly seen as anti-pattern because EVM gas costs are recalibrated from fork to fork. Depending on their exact values can result in deployed contracts ceasing to behave as intended.
## Notes on branch coverage
Solidity-coverage treats `assert` and `require` as code branches because they check whether a condition is true or not. If it is, they allow execution to proceed. If not, they throw, and all changes are reverted. Indeed, prior to [Solidity 0.4.10](https://github.com/ethereum/solidity/releases/tag/v0.4.10), when `assert` and `require` were introduced, this functionality was achieved by code that looked like
```
if (!x) throw;
@ -115,37 +116,7 @@ Clearly, the coverage should be the same in these situations, as the code is (fu
If an `assert` or `require` is marked with an `I` in the coverage report, then during your tests the conditional is never true. If it is marked with an `E`, then it is never false.
### Running on windows
Since `v0.2.6` it's possible to produce a report on Windows (thanks to [@phiferd](https://github.com/phiferd),
who also maintains their own windows-compatible fork of solidity-coverage with other useful improvements). However,
problems remain with the tool's internal launch of `testrpc-sc` so you should create a `.solcover.js` config
file in your root directory and set the `norpc` option to `true`. Then follow the directions below for
launching `testrpc-sc` on its own from the command line before running `solidity-coverage` itself.
### Running testrpc-sc on its own
Sometimes its useful to launch `testrpc-sc` separately at the command line or with a script, after
setting the `norpc` config option in `.solcover.js` to true:
```
$ npx testrpc-sc <options>
```
### Running truffle as a local dependency
If your project ships with Truffle as a dev dependency and expects that instance to be
invoked when running tests, you should either set the `copyNodeModules` option to `true`
in your`.solcover.js` config file OR (if doing so results in poor run time performance), set
the config's `testCommand` and `compileCommand` options as below:
```javascript
compileCommand: '../node_modules/.bin/truffle compile',
testCommand: '../node_modules/.bin/truffle test --network coverage',
```
[1]: https://coveralls.io/builds/25886294
[2]: https://codecov.io/
[3]: https://user-images.githubusercontent.com/7332026/28502310-6851f79c-6fa4-11e7-8c80-c8fd80808092.png
[4]: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md

@ -1,91 +0,0 @@
# How to upgrade testrpc-sc
Warning: this is a birds nest. Any ideas for improvement, however small, are welcome.
### testrpc-sc:
+ published on `npm` as `ethereumjs-testrpc-sc`
+ published **from the coverage branch** of [`sc-forks/testrpc-sc`](https://github.com/sc-forks/testrpc-sc/tree/coverage)
+ a webpack bundle of `sc-forks/ganache-core-sc#coverage` and all of its dependencies.
+ changes to `sc-forks/ganache-core` do not propagate until `testrpc-sc` is rebuilt and published
+ publishing `testrpc-sc` does not propagate until `solidity-coverage`s deps are updated.
To publish a new version:
```
$ git checkout develop
$ git pull upstream develop
$ git checkout coverage
$ git rebase develop
> Update your ganache-core hash
> NOTE TO CGEWECKE: MAKE SURE YOU RENAMED THE PACKAGE (and the .bin command)!!!!
> OTHERWISE YOU WILL PUBLISH OVER THE REAL GANACHE-CLI
>
$ rm -rf node_modules
$ yarn install // This step seems to be absolutely necessary.
$ npm run build // Check build, just to make sure
$ npm version patch // If helpful. If you're tracking the upstream with a ganache-core sync, use theirs.
$ git push
$ npm publish // This also runs build.
// Go to `solidity-coverage` and pin its `testrpc-sc` dependency to the new version.
```
### sc-forks/ganache-core-sc:
+ is what testrpc-sc used to be
+ set by default to [its `coverage` branch](https://github.com/sc-forks/ganache-core-sc)
+ depends on `sc-forks/ethereumjs-vm-sc.git`
+ depends on `sc-forks/provider-engine-sc.git#8.1.19`
+ differs from `truffle-suite/ganache-core` by these deps and
[two lines](https://github.com/sc-forks/ganache-core/blob/ae31080cdc581fef416a1c68cbe28ff71b6fb7c9/lib/blockchain_double.js#L36-L37)
in `blockchain_double.js` which set the block and transaction default gas limits.
To sync `ganache-core-sc` with its upstream parent at `truffle-suite`
```
$ git checkout master
$ git remote add upstream https://github.com/trufflesuite/ganache-core.git
$ git pull upstream master
$ git push
$ git checkout coverage
$ git rebase -i master (there will probably be conflicts)
$ git push
```
### How can I modify ethereumjs-vm-sc and test the changes at `solidity-coverage`?
Since `solidity-coverage@0.1.10`, ethereumjs-vm-sc is an independent dev dependency,
required by the coverage unit tests. The new testrpc has a separate webpacked copy. The simplest
thing to do is open a branch at `solidity-coverage` and develop directly on the `vm` dep.
When you're satisfied that tests pass with your changes, copy your work over to the `ethereumjs-vm-sc` repo itself.
In `test/util/vm.js` the `results` object passed back by `vm.runTx` at [callMethod](https://github.com/sc-forks/solidity-coverage/blob/master/test/util/vm.js#L120)
also contains things like the runState and the logs: ex: `results.vm.runState.logs`.
+ To merge / publish the changes:
+ Merge `ethereumjs-vm-sc#my-new-vm` to master.
+ follow the `testrpc-sc` publication steps above.
There's no reason to worry about changing ethereumjs-vm-sc at master. If that affects anyone (unlikely)
they have safe harbour at any solidity-coverage installation @0.1.9 and up. They can update.
### E2E Testing
[sc-forks/zeppelin-solidity](https://github.com/sc-forks/zeppelin-solidity) has been configured to
serve as a simple pre-publication E2E test. By default the package pulls solidity-coverage from the repo's master branch.
You can trigger a [CI build](https://travis-ci.org/sc-forks/zeppelin-solidity) and [Coveralls report](https://coveralls.io/github/sc-forks/zeppelin-solidity) by running:
```
$ npm run ci
```
### solidity-parser-sc
We also publish `solidity-parser-sc` because `consensys/solidity-parser` in its .pegjs form has been
left to die in the wild, unloved by all. Publish at the publish branch by running `npm version patch`, `npm publish`.

@ -0,0 +1,138 @@
# How to install 0.7.0
**Install**
```
$ npm install --save-dev solidity-coverage@beta
```
**Add** this package to your plugins array in `truffle-config.js`
```javascript
module.exports = {
networks: {...},
plugins: ["solidity-coverage"]
}
```
**Run**
```
truffle run coverage [command-options]
```
A full list of options and other information are [available here][8]
# Upgrading from 0.6.x to 0.7.0-beta.x
First, follow [the installation instructions](#how-to-install-070) and see if it works.
:rabbit2: It does!? Bye.
:elephant: It does not. Good...
#### Are you using Truffle V5?
+ Everything works best with Truffle versions >= 5.0.31.
#### Are you launching testrpc-sc yourself as a stand-alone client?
+ Stop launching it. The coverage plugin needs to initialize the client itself so it can hook into the EVM.
+ By default it uses the ganache bundled with Truffle, but you can use any version (see below).
#### Were you passing testrpc-sc lots of options as flags? :jp: :jp: :jp: :jp: :jp:
+ If the flags were `allowUnlimitedContractSize`, `gasLimit`, `gasPrice` or `emitFreeLogs`,
you can safely ignore them. Ditto if your port was `8555`.
+ If the flags were things like `accounts` or `network_id`, you'll need to transfer them as
[ganache-core options][1] to the `providerOptions` key in .solcover.js.
+ Ganache's "cli flag" and "js option" formats are slightly different. Check out [their docs][1]
**Example**
*Before (at the command line)*
```
$ testrpc-sc --account="0x2b...7cd,1000000000000000000000000" -i 1999 --noVmErrorsOnRPCResponse
```
*Now (in .solcover.js)*
```javascript
providerOptions: {
accounts: [{
secretKey: "0x2b.............7cd",
balance: "0xD3C21BCECCEDA1000000" // <-- Must be hex
}],
network_id: 1999,
vmErrorsOnRPCResponse: false
}
#### Do you have a 'coverage' network in truffle-config.js?
+ If you copy-pasted it from the <= 0.6.x docs, **you can safely delete it**.
+ You should be able to `truffle run coverage --network <network-name>` and use the same config you
run your regular tests with.
+ You can also omit the network flag and you'll be given default settings which look like this:
```javascript
'soliditycoverage': {
port: 8555,
host: "127.0.0.1",
network_id: "*",
}
```
#### Do your tests depend on the specific ganache version you have as a local dependency?
+ Declare it in .solcover.js using the client option
```javascript
client: require('ganache-cli'),
```
#### Does your config contain any deprecated options?
+ They are:
```
accounts, # Now: `providerOptions: { total_accounts: <number> }`
buildDirPath, # Now: `--temp <path>` (At the command line, see Advanced Use)
copyPackages,
copyNodeModules,
deepSkip,
testCommand,
compileCommand,
noRpc
```
+ You can delete them.
#### Do you usually: (1) launch testrpc-sc, (2) do something special, (3) run solidity-coverage?
+ See [the workflow hooks documentation][3]. The "something special" will likely need to run within
an async function declared in .solcover.js
#### Are you what some might call an 'advanced user'?
+ See [Advanced Use][2]
#### Would you like to see some real-world installation examples?
+ [metacoin][4]
+ [openzeppelin-contracts][5]
+ [joinColony/colonyNetwork][6]
+ [aragon/aragon-court][7]
#### :tada: It's still not working!! :tada:
+ If your project is public, please open an issue linking to it and we will advise and/or
open a PR into your repo installing solidity-coverage after patching any relevant bugs here.
+ If your project is private, see if you can generate a reproduction case for the
problem and we'll try to fix that.
[1]: https://github.com/trufflesuite/ganache-core#options
[2]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md
[3]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md#workflow-hooks
[4]: https://github.com/sc-forks/metacoin
[5]: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1923
[6]: https://github.com/JoinColony/colonyNetwork/pull/716
[7]: https://github.com/aragon/aragon-court/pull/123
[8]: https://github.com/sc-forks/solidity-coverage/tree/beta#command-options
Loading…
Cancel
Save