When I run ./node_modules/.bin/solidity-coverage after installing in my project, I get the following error.
Launching testrpc on port 8555
Launching test command (this can take a few seconds)...
Using network 'development'.
SyntaxError: Error parsing /home/travis/prg/protocol/coverageEnv/contracts/governance/GovernanceProtocol.sol: Expected "contract", "import", "library", "pragma", "using", comment, end of input, end of line, or whitespace but "e" found. Line: 6, Column: 31
at peg$buildStructuredError (/usr/local/lib/node_modules/truffle/node_modules/solidity-parser/build/imports_parser.js:543:12)
at Object.peg$parse [as parse] (/usr/local/lib/node_modules/truffle/node_modules/solidity-parser/build/imports_parser.js:4142:11)
at Object.parse (/usr/local/lib/node_modules/truffle/node_modules/solidity-parser/index.js:34:23)
at /usr/local/lib/node_modules/truffle/node_modules/truffle-compile/profiler.js:200:36
at /usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/index.js:79:5
at /usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/node_modules/async/internal/onlyOnce.js:12:16
at next (/usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/node_modules/async/whilst.js:68:18)
at /usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/index.js:64:7
at /usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/fs.js:65:5
at /usr/local/lib/node_modules/truffle/node_modules/truffle-resolver/node_modules/async/internal/once.js:12:16
Cleaning up...
There was an error generating coverage. Possible reasons include:
1. Another application is using port 8555
2. Truffle crashed because your tests errored
Error: ENOENT: no such file or directory, open './allFiredEvents'
Exiting without generating coverage...
May be worth nothing that there is no configuration stub generated in my truffle.json after this error, which should be there if I understand the readme correctly.
This is almost definitely something wrong on my end though, since it looks like you guys got it to work on the melonport protocol just fine, which is the code that I'm currently trying the coverage tool on.
Hi @travs I think it's actually a solidity-parser error that caused by the contracts that are like this:
contract RedeemProtocol {}
I just stuck a nonsense statement in the contract to hack around it: bool x = true; May also work if you put the closing bracket on the following line - i.e add some whitespace? That needs a fix over in SP though. . .
@cgewecke
Thank you for the ultra-quick reply!
Hmm ok, I think you're right about the source being solidity-parser, but I'm unable to replicate this by just doing ./node_modules/.bin/solidity-parser ./contracts/governance/GovernanceProtocol.sol, or even ./node_modules/solidity-coverage/node_modules/.bin/solidity-parser ./contracts/governance/GovernanceProtocol.sol (not sure if they're different).
Once I can replicate I will open an issue in that repo.
Hmm interesting. We use a fork so it's the parser in /solidity-coverage - actually I'll fix our fork tonight, sorry. That's the easiest thing to do.
The commit that successfully generated the report is here @ sc-forks/protocol.
I also see that we made a .solcover.js config file and are accessing the local version of truffle that you have as a dep. The path to it is weird because coverage execution context is inside a folder that copies the target project.
@cgewecke
Ok, thank you again for tackling this with such speed.
Thanks for the tip about the config file; looking forward to your update :)
@travs You were right about it parsing fine . . . this was a bug in our instrumentation logic. It's fixed and published with 0.1.7. Also checked it against the sc-forks/protocol branch (hacky stuff removed) and it seems to work ok. There's a long pause after the compilation step but eventually it runs. Updated the linked-to report, which looks good! Very green!
Thanks for opening.
Also let me know if you run into any more difficulties - the fork I tested against is a few weeks old.
Ok, pulled the 0.1.7 release and now running into this error:
Launching testrpc on port 8555
Launching test command (this can take a few seconds)...
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/home/travis/prg/protocol/node_modules/truffle-provider/node_modules/web3/lib/web3/errors.js:35:16)
at XMLHttpRequest.request.onreadystatechange (/home/travis/prg/protocol/node_modules/truffle-provider/node_modules/web3/lib/web3/httpprovider.js:115:32)
at XMLHttpRequestEventTarget.dispatchEvent (/home/travis/prg/protocol/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/travis/prg/protocol/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpRequestError (/home/travis/prg/protocol/node_modules/xhr2/lib/xhr2.js:544:12)
at ClientRequest.<anonymous> (/home/travis/prg/protocol/node_modules/xhr2/lib/xhr2.js:414:24)
at emitOne (events.js:115:13)
at ClientRequest.emit (events.js:210:7)
at Socket.socketErrorListener (_http_client.js:400:9)
at emitOne (events.js:115:13)
Cleaning up...
I have the .solium.js file present as in your fork.
And nothing is running on 8555 (checked with ps -fp 8555 and lsof -f :8555.
Am I missing a step somewhere?
My testrpc versions as per npm list |grep rpc
├── [email protected]
│ ├─┬ [email protected] (git+https://github.com/sc-forks/testrpc-sc.git#15cc0fb8e031bee152c7b8e3f8df5f2ad33ca04f)
Will test on your fork in a few moments and confirm that this is local to me, and not the project.
Update: Alright so it actually works on your fork, but not on the current master branch. Curious :confused:
Update 2: Re-cloned our latest branch with a passing build (participation) and it runs the tests now, but fails just after the tests with a different error:
Cleaning up...
There was an error generating coverage. Possible reasons include:
1. Another application is using port 8555
2. Truffle crashed because your tests errored
Error: ENOENT: no such file or directory, open './allFiredEvents'
Exiting without generating coverage...
The master branch has build errors, so in all future attempts I will use the current participation branch
Ok cool, I'll check it out this afternoon.
Checked out participation and it ran . . . just a couple things:
subscribeRedeem.js where there are trailing commas in the list of function call args. Like here. Not sure if that's something weird on my end or not. (Just deleted the commas and it was fine.)solium.js. It should be called .solcover.js and look like this:module.exports = {
testCommand: './../node_modules/.bin/truffle test'
}
Invalid JSON RPC response: "" error once even though there's nothing running in the background. I sometimes get this if I've previously been running testrpc 8545 from the command line. Could also be a hidden zombie from a failed solidity-coverage run? Completely infuriating and the only solution I've found it restarting my computer. Really sorry. If you ever detect a pattern to this behavior please let me know. Output looked like this:

@travs RE: Invalid JSON RPC response: "" . . . if you continue to run into it, there's a workaround that maurelian just pinged me about. You can set an option called norpc in the .solcover.js config file to true.
Then in another window launch our custom testrpc from the command line like this:
./node_modules/ethereumjs-testrpc-sc/bin/testrpc --gasLimit 0xfffffffffff --port 8555
That seems to work consistently.
@cgewecke
The trailing comma thing is due to some ES2017 syntax introduced in Node 8; thanks for pointing it out, so we can specify which version of node our project is compatible with in the future.
Ok, I will continue trying different things in the meantime.
Can't get it to run at all now, even after a computer reset on Node 8.1.2, Node 6.11.0, or Node 7.10.0, on either of Ubuntu 16.04 or Arch.
@cgewecke
Agh, apologies; I didn't see your last comment before I made my last one.
Tried the workaround you suggested and it worked perfectly.
Thanks again 😄
@travs Oh good!!! Sorry about how brittle the testrpc launch is . . .it's starting to look like we might need to make the 'workaround' the 'actual way'.
@travs @cgewecke how to configure truffle for using with solidity-coverage? I am a beginner, please provide steps. Thanx in advance..
@utkarash2991 You could look at some of the example projects that are linked to in the README. They're all on GitHub.
If you have a simple truffle project, you should be able to install the package, run the tool and get a coverage report without any special configuration, per the instructions at the top of the README.
If that's not working, you're welcome to open a separate issue and provide a clear description of the errors you're seeing.
Thanks!
@cgewecke when i am running ./node_modules/.bin/solidity-coverage in my project i got the following error
Generating coverage environment
Instrumenting ./coverageEnv/contracts/ConvertLib.sol
Instrumenting ./coverageEnv/contracts/MetaCoin.sol
Skipping instrumentation of ./coverageEnv/contracts/Migrations.sol
testRpc stdout:
EthereumJS TestRPC v4.0.1 (ganache-core: 1.0.1)
testRpc stderr:
events.js:182
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8555
at Object.exports._errnoException (util.js:1024:11)
at exports._exceptionWithHostPort (util.js:1047:20)
at Server.setupListenHandle [as _listen2] (net.js:1319:14)
at listenInCluster (net.js:1367:12)
at Server.listen (net.js:1467:7)
at Server.server.listen (/home/utkarash/mytest/node_modules/ethereumjs-testrpc-sc/build/cli.node.js:119382:17)
at Object.
at __webpack_require__ (/home/utkarash/mytest/node_modules/ethereumjs-testrpc-sc/build/cli.node.js:21:30)
at /home/utkarash/mytest/node_modules/ethereumjs-testrpc-sc/build/cli.node.js:64:18
at Object.
Cleaning up...
testRpc errored after launching as a childprocess.
Exiting without generating coverage...
@utkarash2991 Ok that means that somehow the testrpc was left running in the background. I'm assuming you don't have a special script launching it separately? This problem can happen occasionally if you ctrl-c the tool without letting it shut down on it's own.
At the command line run:
lsof -n -i4TCP:8555 | grep LISTEN
You should see something like this as output:
node 2918 me 12u IPv6 0x8debd291692ede99 0t0 TCP *:d-fence (LISTEN)
Terminate the background server with: kill -9 2918 (Your process id will not be 2918 - use whatever it is based on your output.)
Then try running the coverage tool again.
@cgewecke Still i am facing the same issue.
Here are the steps i have done :
created my project directory and run truffle -init there.
Then i run the following commands:
$ npm init
$ npm install --save-dev coveralls
$ npm install --save-dev solidity-coverage as given in https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md
then i made the changes in package.json as stated.
and finally i am running : ./node_modules/.bin/solidity-coverage
and getiing the above mentioned error.
@cgewecke thanx for ur support
@utkarash2991 Could you run lsof -i at the command line and see if there is a node server open named d-fence in the list? If so that process needs to be killed.
@cgewecke .. run as a success.. Thanx fr ur support
@utkarash2991 Oh good! I'm going to open a separate issue discussing this problem so that people can easily find the error you experienced and see a solution. Thanks for reporting this.