Skip to content

Commit 9732b55

Browse files
authored
Merge pull request #341 from sc-forks/maint/misc-pre-6
Misc 0.6.0 pre release (part II)
2 parents a3a4a97 + f3462cf commit 9732b55

File tree

8 files changed

+40
-165
lines changed

8 files changed

+40
-165
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc

Lines changed: 0 additions & 57 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,22 @@ $ npm install --save-dev solidity-coverage@beta
2626
$ npx solidity-coverage
2727
```
2828

29-
**NB:** for most projects you'll also need to configure a 'coverage' network in
30-
truffle-config.js. See the Network Configuration guide below.
29+
**NB:** Most projects will also need to set a `coverage` network in
30+
truffle-config.js. See [Network Configuration](#network-configuration).
3131

3232
### Usage notes:
33-
+ Requires Solidity pragmas >= `0.5.0`.
33+
+ For solidity pragma >= `0.5.0`.
3434
+ Tests run more slowly while coverage is being generated.
35-
+ Your contracts will be double-compiled and a delay between compilation and
35+
+ Your contracts will be double-compiled and a (long) delay between compilation and
3636
the beginning of test execution is possible if your contracts are large.
37-
+ solidity-coverage expects a globally installed truffle in your environment / on CI. If you
38-
prefer to control which Truffle version your tests are run with, please see the FAQ for
39-
[running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency).
40-
+ Solidity fixtures / mocks stored in the `tests/` directory are no longer supported. 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's unable to rewrite your contract ABIs appropriately. Mocks should be relocated to the root folder's `contracts` directory. More on why this is necessary at issue [146](https://github.com/sc-forks/solidity-coverage/issues/146)
37+
+ Truffle should be globallly installed in your environment.. If you prefer running truffle as
38+
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.
39+
+ 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's unable to control truffle's compilation of 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)
4140

4241
### Network Configuration
4342

44-
By default, solidity-coverage connects to a coverage-enabled fork of the ganache-cli client
45-
called **testrpc-sc** on port 8555. (It ships with `solidity-coverage` -
46-
there's nothing extra to download.)
43+
By default, this tool connects to a coverage-enabled fork of ganache-cli
44+
called **testrpc-sc** on port 8555. (It's a dependency - there's nothing extra to download.)
4745

4846
In `truffle-config.js`, add a coverage network following the example below.
4947

@@ -69,8 +67,8 @@ module.exports = {
6967
```
7068
### Options
7169

72-
You can also create a `.solcover.js` config file in the root directory of your project and specify
73-
additional options if necessary:
70+
Additional options can be specified in a `.solcover.js` config file located in
71+
the root directory of your project.
7472

7573
**Example:**
7674
```javascript
@@ -102,15 +100,14 @@ module.exports = {
102100

103101
### FAQ
104102

105-
Solutions to common issues people run into using this tool:
103+
Solutions to common problems people run into:
106104

107105
+ [Running out of gas](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-gas)
108106
+ [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)
109107
+ [Running out of time (in mocha)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-time-in-mocha)
110108
+ [Running on windows](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-on-windows)
111109
+ [Running testrpc-sc on its own](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own)
112110
+ [Running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency)
113-
+ [Using alongside HDWalletProvider](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#using-alongside-hdwalletprovider)
114111
+ [Integrating into CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
115112
+ [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)
116113
+ [Why are `send` and `transfer` throwing in my tests?](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-are-send-and-transfer-throwing)
@@ -119,14 +116,12 @@ Solutions to common issues people run into using this tool:
119116
### Example reports
120117
+ [metacoin](https://sc-forks.github.io/metacoin/) (Istanbul HTML)
121118
+ [openzeppelin-solidity](https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master) (Coveralls)
122-
+ [gnosis-contracts](https://codecov.io/gh/gnosis/gnosis-contracts/tree/master/contracts) (Codecov)
123119

124120
### Contribution Guidelines
125121

126122
Contributions are welcome! If you're opening a PR that adds features please consider writing some
127-
[unit tests](https://github.com/sc-forks/solidity-coverage/tree/master/test) for them. You could
128-
also lint your submission with `npm run lint`. Bugs can be reported in the
129-
[issues](https://github.com/sc-forks/solidity-coverage/issues).
123+
[unit tests](https://github.com/sc-forks/solidity-coverage/tree/master/test) for them. Bugs can be
124+
reported in the [issues](https://github.com/sc-forks/solidity-coverage/issues).
130125

131126
Set up the development environment with:
132127
```

docs/faq.md

Lines changed: 19 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
**Step 1: Create a metacoin project & install coverage tools**
77

88
```bash
9-
$ truffle init
9+
$ truffle unbox metacoin
10+
$ rm test/TestMetacoin.sol # No solidity tests, sorry.
1011

1112
# Install coverage dependencies
1213
$ npm init
@@ -19,7 +20,7 @@ $ npm install --save-dev solidity-coverage
1920
```javascript
2021
"scripts": {
2122
"test": "truffle test",
22-
"coverage": "./node_modules/.bin/solidity-coverage"
23+
"coverage": "npx solidity-coverage"
2324
},
2425
```
2526

@@ -30,7 +31,7 @@ sudo: required
3031
dist: trusty
3132
language: node_js
3233
node_js:
33-
- '7'
34+
- '10'
3435
install:
3536
- npm install -g truffle
3637
- npm install -g ganache-cli
@@ -43,7 +44,7 @@ before_script:
4344
after_script:
4445
- npm run coverage && cat coverage/lcov.info | coveralls
4546
```
46-
**NB:** It's probably best practice to run coverage in CI as an `after_script` or in a [parallel build](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/.travis.yml) rather than assume its equivalence to `truffle test`. Solidity-coverage's `testrpc` 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.
47+
**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.
4748

4849
**Step 4: Toggle the project on at Travis and Coveralls and push.**
4950

@@ -57,33 +58,12 @@ after_script:
5758

5859

5960

60-
6161
### Running out of gas
6262
If you have hardcoded gas costs into your tests some of them may fail when using solidity-coverage.
6363
This is because the instrumentation process increases the gas costs for using the contracts, due to
6464
the extra events. If this is the case, then the coverage may be incomplete. To avoid this, using
6565
`estimateGas` to estimate your gas costs should be more resilient in most cases.
6666

67-
**Example:**
68-
```javascript
69-
// Hardcoded Gas Call
70-
MyContract.deployed().then(instance => {
71-
instance.claimTokens(0, {gasLimit: 3000000}).then(() => {
72-
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
73-
done();
74-
})
75-
});
76-
77-
// Using gas estimation
78-
MyContract.deployed().then(instance => {
79-
const data = instance.contract.claimTokens.getData(0);
80-
const gasEstimate = web3.eth.estimateGas({to: instance.address, data: data});
81-
instance.claimTokens(0, {gasLimit: gasEstimate}).then(() => {
82-
assert(web3.eth.getBalance(instance.address).equals(new BigNumber('0')))
83-
done();
84-
})
85-
});
86-
```
8767

8868
### Running out of memory (Locally and in CI)
8969
(See [issue #59](https://github.com/sc-forks/solidity-coverage/issues/59)).
@@ -104,55 +84,20 @@ limit to 7.5MB (ProTip courtesy of [@federicobond](https://github.com/federicobo
10484
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))
10585
```javascript
10686
module.exports = {
107-
networks: {
108-
development: {
109-
host: "localhost",
110-
port: 8545,
111-
network_id: "*"
112-
},
113-
...etc...
114-
},
115-
mocha: {
116-
enableTimeouts: false
117-
}
87+
networks: {
88+
development: {
89+
host: "localhost",
90+
port: 8545,
91+
network_id: "*"
92+
},
93+
...etc...
94+
},
95+
mocha: {
96+
enableTimeouts: false
97+
}
11898
}
11999
```
120100

121-
### Using alongside HDWalletProvider
122-
[See Truffle issue #348](https://github.com/trufflesuite/truffle/issues/348).
123-
HDWalletProvider crashes solidity-coverage, so its constructor shouldn't be invoked while running this tool.
124-
One way around this is to instantiate the HDWallet conditionally in `truffle.js`:
125-
126-
```javascript
127-
var HDWalletProvider = require('truffle-hdwallet-provider');
128-
var mnemonic = 'bark moss walnuts earth flames felt grateful dead sophia loren';
129-
130-
if (!process.env.SOLIDITY_COVERAGE){
131-
provider = new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/')
132-
}
133-
134-
module.exports = {
135-
networks:
136-
ropsten: {
137-
provider: provider,
138-
network_id: 3
139-
},
140-
coverage: {
141-
host: "localhost",
142-
network_id: "*",
143-
port: 8555,
144-
...etc..
145-
}
146-
...etc...
147-
```
148-
149-
And set up an npm script to run the coverage tool like this:
150-
```javascript
151-
"scripts": {
152-
"coverage": "SOLIDITY_COVERAGE=true ./node_modules/.bin/solidity-coverage"
153-
},
154-
```
155-
156101
### Why has my branch coverage decreased? Why is assert being shown as a branch point?
157102

158103
`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
@@ -174,8 +119,8 @@ If an `assert` or `require` is marked with an `I` in the coverage report, then d
174119
175120
If you include contracts that have fallback function in the list of files to instrument and attempt to `send` or `transfer` to them,
176121
the methods will throw because the instrumentation consumes more gas than these methods allow. See the `skipFiles` option in the
177-
README to exclude these files and [issue 118](https://github.com/sc-forks/solidity-coverage/issues/118) for a more detailed discussion of
178-
this problem.
122+
README to exclude these files and [issue 118](https://github.com/sc-forks/solidity-coverage/issues/118) for a more detailed discussion. This problem persists in v0.6.x even though the vm is set to emit free logs.
123+
(Under investigation).
179124
180125
### Running on windows
181126
@@ -190,15 +135,8 @@ launching `testrpc-sc` on its own from the command line before running `solidity
190135
Sometimes its useful to launch `testrpc-sc` separately at the command line or with a script, after
191136
setting the `norpc` config option in `.solcover.js` to true:
192137
193-
If you installed using npm
194-
```
195-
$ ./node_modules/.bin/testrpc-sc <options>
196-
```
197-
198-
If you installed using yarn
199138
```
200-
$ ./node_modules/ethereumjs-testrpc-sc/bin/testrpc // v0.1.10 and below (testrpc v3.0.3)
201-
$ ./node_modules/ethereumjs-testrpc-sc/build/cli.node.js // All others (testrpc v4.0.1 +)
139+
$ npx testrpc-sc <options>
202140
```
203141
204142
### Running truffle as a local dependency

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"istanbul": "^0.4.5",
2626
"keccakjs": "^0.2.1",
2727
"req-cwd": "^1.0.1",
28-
"shelljs": "https://github.com/sc-forks/shelljs.git",
28+
"shelljs": "^0.8.3",
2929
"sol-explore": "^1.6.2",
3030
"solidity-parser-antlr": "0.4.5",
3131
"tree-kill": "^1.2.0",

test/cli/wallet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract('Wallet', accounts => {
99
const walletB = await Wallet.new();
1010

1111
await walletA.sendTransaction({
12-
value: web3.utils.toBN(100), from: accounts[0],
12+
value: web3.utils.toBN(500), from: accounts[0],
1313
});
1414
console.log('transaction done')
1515
await walletA.sendPayment(50, walletB.address, {

test/sources/cli/Wallet.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ contract Wallet {
99
}
1010

1111
function sendPayment(uint payment, address payable recipient) public {
12-
if (!recipient.send(payment))
13-
revert();
12+
require(recipient.send(payment), 'sendPayment failed');
1413
}
1514

1615
function getBalance() public view returns(uint){
1716
return address(this).balance;
1817
}
19-
18+
2019
function() external payable
2120
{
2221
if (msg.value > 0)

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,9 +2782,10 @@ shebang-regex@^1.0.0:
27822782
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
27832783
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
27842784

2785-
"shelljs@https://github.com/sc-forks/shelljs.git":
2785+
shelljs@^0.8.3:
27862786
version "0.8.3"
2787-
resolved "https://github.com/sc-forks/shelljs.git#7aa8ce4ebdcb42b95f59093772afce230f2a3ca0"
2787+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"
2788+
integrity sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==
27882789
dependencies:
27892790
glob "^7.0.0"
27902791
interpret "^1.0.0"

0 commit comments

Comments
 (0)