6
6
### Code coverage for Solidity testing
7
7
![ coverage example] ( https://cdn-images-1.medium.com/max/800/1*uum8t-31bUaa6dTRVVhj6w.png )
8
8
9
- For more details about what this is, how it work and potential limitations, see
9
+ For more details about what this is, how it works and potential limitations, see
10
10
[ the accompanying article] ( https://blog.colony.io/code-coverage-for-solidity-eecfa88668c2 ) .
11
11
12
- This branch is an attempt to prepare solcover for npm publication and simplify its use as a
13
- command line utility. Gas cost issues are managed under the hood and the tool cleans up after
14
- itself if (when) it crashes.
15
-
16
12
### Install
17
13
```
18
14
$ npm install --save-dev https://github.com/JoinColony/solcover.git#truffle3
@@ -24,18 +20,19 @@ $ ./node_modules/solcover/exec.js
24
20
```
25
21
26
22
Tests run signficantly slower while coverage is being generated. A 1 to 2 minute delay
27
- between the end of Truffle compilation and the beginning of test execution is not impossible if your
23
+ between the end of Truffle compilation and the beginning of test execution is possible if your
28
24
test suite is large. Large solidity files can also take a while to instrument.
29
25
30
26
### Configuration
31
27
32
- By default, solcover generates a stub ` truffle.js ` that accomodates its special gas needs and
33
- connects to a modified version of testrpc on port 8555. If your tests can run on the development network
28
+ By default, Solcover generates a stub ` truffle.js ` that accomodates its special gas needs and
29
+ connects to a modified version of testrpc on port 8555. If your tests will run on the development network
34
30
using a standard ` truffle.js ` and a testrpc instance with no special options, you shouldn't have to
35
31
do any configuration. If your tests depend on logic added to ` truffle.js ` - for example:
36
32
[ zeppelin-solidity] ( https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/truffle.js )
37
- uses the file to expose a babel polyfill that its suite needs to run correctly - you can override the
38
- default behavior by specifying a coverage network in ` truffle.js ` .
33
+ uses the file to expose a babel polyfill that its suite requires - you can override the
34
+ default behavior by declaring a coverage network in ` truffle.js ` . Solcover will use your 'truffle.js'
35
+ instead of a dynamically generated one.
39
36
40
37
** Example coverage network config**
41
38
``` javascript
@@ -61,12 +58,14 @@ You can also create a `.solcover.js` config file in the root directory of your p
61
58
some additional options:
62
59
+ ** port** : <Number > The port you want Solcover to run testrpc on / have truffle connect to.
63
60
+ ** testrpcOptions** : <String > A string of options to be appended to a command line invocation
64
- of testrpc. Ex: ` --account="0x89a..f',10000" --port 8777 ` ". If you use this option specify the port
65
- in your testrpcOptions string AND as a ` port ` option.
61
+ of testrpc.
62
+ + Example: ` --account="0x89a...b1f',10000" --port 8777 ` ".
63
+ + Note: you should specify the port in your ` testrpcOptions ` string AND as a ` port ` option.
66
64
+ ** testCommand** : <String > By default Solcover runs ` truffle test ` or ` truffle test --network coverage ` .
67
- ` testCommand ` let you run tests some other way: ex: ` mocha --timeout 5000 ` . If you're doing this, you
68
- will probably need to make sure the web3 provider for your tests explicitly connects to the port solcover's
69
- testrpc is set to run on, e.g: ` var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8555")) `
65
+ This option lets you run tests some other way: ex: ` mocha --timeout 5000 ` . You
66
+ will probably also need to make sure the web3 provider for your tests explicitly connects to the port Solcover's
67
+ testrpc is set to run on, e.g:
68
+ + ` var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8555")) `
70
69
71
70
** Example .solcover.js config file**
72
71
```
@@ -84,20 +83,20 @@ This is because the instrumentation process increases the gas costs for using th
84
83
the extra events. If this is the case, then the coverage may be incomplete. To avoid this, using
85
84
` estimateGas ` to estimate your gas costs should be more resilient in most cases.
86
85
87
- ** Events testing** : Solcover injects events into your solidity files to log which lines your tests reach,
88
- so any tests that depend on how many events are fired or where the event sits in the logs array
86
+ ** Events testing** : Because Solcover injects events into your contracts to log which lines your tests reach,
87
+ any tests that ask how many events are fired or where the event sits in the logs array
89
88
will probably error while coverage is being generated.
90
89
91
90
** Using ` require ` in ` migrations.js ` files** : Truffle overloads Node's ` require ` function but
92
91
implements a simplified search algorithm for node_modules packages
93
92
([ see issue #383 at Truffle] ( https://github.com/trufflesuite/truffle/issues/383 ) ).
94
93
Because Solcover copies an instrumented version of your project into a temporary folder, ` require `
95
- statements handled by Truffle internally don 't resolve correctly.
94
+ statements handled by Truffle internally won 't resolve correctly.
96
95
97
96
** Coveralls / CodeCov** : These CI services take the Istanbul reports generated by Solcover and display
98
- line coverage. Istanbul's own html report provides significantly more detailed
99
- reporting and can show whether your tests actually cover all the conditional branches
100
- in your code. It can be found inside the ` coverage ` folder at ` index.html ` after you run the tool.
97
+ line coverage. Istanbul's own html report publishes significantly more detail and can show whether
98
+ your tests actually reach all the conditional branches in your code. It can be found inside the
99
+ ` coverage ` folder at ` index.html ` after you run the tool.
101
100
102
101
### Examples
103
102
0 commit comments