4

When I start ganache-cli in one terminal window and run ./node_modules/.bin/solidity-coverage (command from documentation) in another I get

Error: Exceeds block gas limit at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1) at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1 at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/~/truffle-migrate/index.js:225:1 at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1 at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1) at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1) at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1) at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1) at IncomingMessage. (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

I even deleted all tests and contracts and I still receive this error. truffle test and truffle migrate works. Any help appreciated

Here my truffle.js exports

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*",
      gas: 6700000 
    },
    coverage: {
      host: "localhost",
      network_id: "*",
      port: 8545,         // <-- If you change this, also set the port option in .solcover.js.
      gas: 0xfffffffffff, // <-- Use this high gas value
      gasPrice: 0x01      // <-- Use this low gas price
    }
  }
};

and my .solcover.js

module.exports = { 
    port: 8545,
    norpc: true,
    skipFiles: ['contracts/Migrations.sol'],
    copyPackages: ['zeppelin-solidity']
}

2 Answers 2

2

Try removing the line norpc: true in solcover.js and set port to 8555

3

The documentation states:

Network Configuration

By default, solidity-coverage generates a stub truffle.js that accomodates its special gas needs and connects to a coverage-enabled fork of the ganache-cli client called testrpc-sc on port 8555.

So, you will have ganache-cli running on port 8545 and a fork of it called testrpc-sc running on port 8555. You cannot use port 8545 with solcover, so your code should be:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*"
    },
    coverage: {
      host: "localhost",
      network_id: "*",
      port: 8555,         // <-- 8555 and not 8545
      gas: 0xfffffffffff, 
      gasPrice: 0x01      
    },
    ...etc...
  }
};

and your .solcover.js

module.exports = { 
    port: 8555,   // <-- 8555 and not 8545
    norpc: true,
    skipFiles: ['contracts/Migrations.sol'],
    copyPackages: ['zeppelin-solidity']
}

Here are the minimum steps required to make this work.

I've started by running ganache-cli and let it run:

ganache-cli 

on a different shell window (the other is running ganache-cli), I typed:

mkdir solcover
cd solcover/
truffle init
npm install --save-dev solidity-coverage
touch allFiredEvents
./node_modules/.bin/solidity-coverage

and the output was:

Generating coverage environment
Running: truffle compile  
(this can take a few seconds)...
Compiling ./contracts/Migrations.sol...

Compilation warnings encountered:

/Users/bordaloj/WIP/Batcave/Ethereum/solcover/coverageEnv/contracts/Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
  function Migrations() public {
  ^ (Relevant source part starts here and spans across multiple lines).

Writing artifacts to ./build/contracts

Skipping instrumentation of  ./coverageEnv/contracts/Migrations.sol
Running: truffle compile  
(this can take a few seconds)...
Compiling ./contracts/Migrations.sol...

Compilation warnings encountered:

/Users/bordaloj/WIP/Batcave/Ethereum/solcover/coverageEnv/contracts/Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
  function Migrations() public {
  ^ (Relevant source part starts here and spans across multiple lines).

Writing artifacts to ./build/contracts

Launched testrpc on port 8555
Running: truffle test  
(this can take a few seconds)...
Using network 'development'.



  0 passing (0ms)

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|

Istanbul coverage reports generated
Cleaning up...

Did it help?

3
  • If I do that it states "Could not connect to your Ethereum client" May 8, 2018 at 17:02
  • I edited the answer, can you try those steps and see if it works?
    – bordalix
    May 8, 2018 at 17:40
  • Okay that works for a fresh project and finally helped me to find out the real cause. I would like to give you credits for your answer and I will upvote this answer. But could you write a second answer where you say try removing the line norpc: true in solcover.js and set port to 8555 so I can accept an answer specific to my problem? I guess testrpc is also configured specifically because it didn't work with an extra terminal window with ganache May 8, 2018 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.