You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-62Lines changed: 32 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,96 +19,66 @@ find discrepancies between the coverage report and your suite's behavior, please
19
19
```
20
20
$ npm install --save-dev solidity-coverage
21
21
```
22
-
23
-
### Run
24
-
Set a `coverage` network in truffle-config.js (see [Network Configuration](#network-configuration)) and then run:
25
-
```
26
-
$ npx solidity-coverage
27
-
```
28
-
29
22
### Usage notes:
30
-
+ For pragma solidity >=0.4.22 <0.6.0 / Petersburg / Truffle v4 and v5
31
-
+ Tests run more slowly while coverage is being generated.
32
-
+ Your contracts will be double-compiled and a (long) delay between compilation and
33
-
the beginning of test execution is possible if your contracts are large.
34
-
+ Truffle should be globallly installed in your environment.. If you prefer running truffle as
35
-
a local dependency, please see [this section](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency) of the FAQ.
36
-
+ If your suite uses native Solidity testing or accesses contracts via mocks stored in `tests/` (a la Zeppelin), coverage will trigger test errors because it can't control the way truffle compiles that folder. Mocks should be relocated to the root `contracts` directory. More on why this is necessary at issue [146](https://github.com/sc-forks/solidity-coverage/issues/146)
37
-
38
-
### Network Configuration
39
-
40
-
By default, this tool connects to a coverage-enabled fork of ganache-cli
41
-
called **testrpc-sc** on port 8555.
42
-
+ it's a dependency - there's nothing extra to download.
43
-
+ the solidity-coverage command launches it automatically in the background. (See [this section of the FAQ](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own) if you need to launch it separately yourself)
23
+
+ For pragma solidity >=0.4.22 <0.6.0 / Petersburg
24
+
+ Coverage runs tests a little more slowly.
25
+
+ Coverage distorts gas consumption.
26
+
+ Coverage launches its own in-process ganache instance. You can
27
+
set [ganache options](https://github.com/trufflesuite/ganache-core#options) via
28
+
the `providerOptions` key in your `.solcover.js` config file.
44
29
45
-
In `truffle-config.js`, add a coverage network following the example below.
30
+
### Truffle V5
46
31
47
-
**Example**
32
+
Add "solidity-coverage" to your plugins array in `truffle-config.js`
48
33
```javascript
49
34
module.exports= {
50
-
networks: {
51
-
development: {
52
-
host:"localhost",
53
-
port:8545,
54
-
network_id:"*"
55
-
},
56
-
coverage: {
57
-
host:"localhost",
58
-
network_id:"*",
59
-
port:8555, // <-- If you change this, also set the port option in .solcover.js.
| --file | --file="test/registry/*.js" | Filename or glob describing a subset of JS tests to run. (Globs must be enclosed by quotes.)|
49
+
| --solcoverjs | --solcoverjs ./../.solcover.js | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
| accounts |*Number*| 35 | Number of accounts to launch testrpc with. |
89
-
| port |*Number*| 8555 | Port to run testrpc on / have truffle connect to |
90
-
| norpc |*Boolean*| false | Prevent solidity-coverage from launching its own testrpc. Useful if you are managing a complex test suite with a [shell script](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/ed872ca0a11c4926f8bb91dd103bea1378a3384c/scripts/coverage.sh)|
91
-
| testCommand |*String*|`truffle test`| Run an arbitrary test command. ex: `mocha --timeout 5000`. NB: Also set the `port` option to whatever your tests require (probably 8545). |
92
-
| testrpcOptions |*String*|`--port 8555`| options to append to a command line invocation of testrpc. NB: Using this overwrites the defaults so always specify a port in this string *and* in the `port` option |
93
-
| copyNodeModules |*Boolean*| false |:warning:**DEPRECATED** use `copyPackages` instead :warning: Copies `node_modules` into the coverage environment. May significantly increase the time for coverage to complete if enabled. Useful if your contracts import solidity files from an npm installed package (and your node_modules is small). |
94
-
| copyPackages |*Array*|`[]`| Copies specific `node_modules` packages into the coverage environment. May significantly reduce the time for coverage to complete compared to `copyNodeModules`. Useful if your contracts import solidity files from an npm installed package. |
69
+
| client |*Object*| require("truffle").ganache | Useful if you need a specific ganache version. (usage: `client: require("ganache-core")`)|
70
+
| providerOptions |*Object*| {} | ganache-core options (ex: `network_id: 55`). Complete list of options [here](https://github.com/trufflesuite/ganache-core#options). |
95
71
| skipFiles |*Array*|`['Migrations.sol']`| Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. `Migrations.sol` is skipped by default, and does not need to be added to this configuration option if it is used. |
96
-
| deepSkip | boolean | false | Use this if instrumentation hangs on large, skipped files (like Oraclize). It's faster. |
97
-
| dir |*String*|`.`| Solidity-coverage copies all the assets in your root directory (except `node_modules`) to a special folder where it instruments the contracts and executes the tests. `dir` allows you to define a relative path from the root directory to those assets. Useful if your contracts & tests are within their own folder as part of a larger project.|
| istanbulReporter |*Array*|['html', 'lcov', 'text']| Coverage reporters for Istanbul. Optional reporter replaces the default reporters. |
100
73
101
74
### FAQ
102
75
103
-
Solutions to common problems people run into:
76
+
Common problems & questions:
104
77
105
78
+[Running out of gas](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-gas)
106
79
+[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)
107
80
+[Running out of time (in mocha)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-time-in-mocha)
108
-
+[Running on windows](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-on-windows)
109
-
+[Running testrpc-sc on its own](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own)
110
-
+[Running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency)
111
-
+[Integrating into CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
81
+
+[Running in CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
112
82
+[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)
0 commit comments