Solidity-coverage: Error: while migrating Migrations (Exceeds block gas limit)

Created on 13 Sep 2018  路  18Comments  路  Source: sc-forks/solidity-coverage

I am trying to use solidity-coverage to evaluate my tests scripts. The thing is, my smart contracts are pretty big before adding all extra stuff needed for coverage evaluation, and I got out of gas issues at migration.

I've increassed the gas value in my truffle.js

coverage: { host: "localhost", network_id: "*", port: 8555, gas: 0xFFFFFFFFFFFFF, gasPrice: 0x01 }

and I also modified the testrpcOptions entry in .solcover.js

testrpcOptions: '-p 8555 -l 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -g 0x1',

Still, I get an error when running solidity-coverage:

Error: while migrating Migrations: Returned error: Exceeds block gas limit at /home/.../node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:361:1 at process._tickCallback (internal/process/next_tick.js:68:7)

Any idea what I am doing wrong?

All 18 comments

@Amxx Yes, it looks like something might have broken with the -l option on ganache 6.1.6 and we recently upgraded the client to that version. Also saw this problem recently at #277

Could you try?

  • removing the testrpcOptions from the .solcover.js
  • using the suggested coverage network default for gas: 0xfffffffffff

It used to give me out of gas messages ... but I guess I somehow reset something and it ~works now.
Still, my tests (that run correctly with truffle test) flood me with Error: sender account not recognized when running solidity-coverage

@Amxx Do you have a link to your project? Happy to take a look.

the code i'm working not is not public but I managed to create a minimum working example.
TestContract.sol.txt
999_test.js.txt

EDIT: We found what was causing the problem, it wasn't solidity-coverage related. Thanks!

@cgewecke I'm having the same issue as well. Most of our test suite runs however coverage returns the out of gas error for some tests on rebalancingSetToken.spec.ts. I can isolate the problem down to one function call coreWrapper.deployRebalancingSetTokenAsync. We use a constants.ts file to send a default amount of gas with each transaction which is currently set at 12000000.

To fix I tried adding the l flag in solcover.js to increase the block gas limit but return OP's error. I've tried bumping to the newest version of solidity-coverage, as well as toggled between v6.1.2 and v6.1.8 of ganache-cli. My truffle.js also looks the same as OPs. Here's links to the files talked about above and the branch as a whole, curious if you can give any guidance

branch
solcover.js (without l flag)
truffle.js
constants.ts
RebalancingSetToken.sol
rebalancingSetToken.spec.ts

Same thing here, is there any fix for this issue?

I also have the same issue:

My command in package.json to run the Ganache CLI and my tests in parallel:
concurrently --names \"TestRPC,Coverage\" --kill-others \"node_modules\\.bin\\testrpc-sc --port 8555\" \"node_modules\\.bin\\solidity-coverage\" || true

My truffle-config.js:

module.exports = {
    // See <http://truffleframework.com/docs/advanced/configuration>
    // to customize your Truffle configuration!

    networks: {
        coverage: {
            host: 'localhost',
            network_id: '*',
            port: 8555,
            gas: 0xfffffffffff,
            gasPrice: 0x01,
        },
    },

    compilers: {
        solc: {
            version: '0.5.0',
        },
    },

    // Use same settings as in 'compile_contract.js'
    solc: {
        optimizer: {
            enabled: true,
            runs: 10,
        },
    },
};

And the .solcover.js

module.exports = {
    port: 8555,
    norpc: true,
    skipFiles: ['contracts/Migrations.sol'],
    testrpcOptions: '-p 8555 -l 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -g 0x1',
};

The output is like:

[Coverage] Generating coverage environment
[Coverage] Running: truffle compile --network coverage
[Coverage] (this can take a few seconds)...
[TestRPC] Ganache CLI v6.1.6 (ganache-core: 2.1.6)
[TestRPC]
[TestRPC] Available Accounts
[TestRPC] ==================
[TestRPC] (0) 0xf785a0ae0c24bff2d857c630586e6f0698e50771 (~100 ETH)
[TestRPC] (1) 0xaf288c21043d9518bf274e108696d33c25eb4741 (~100 ETH)
// snip
[TestRPC]
[TestRPC] Private Keys
[TestRPC] ==================
[TestRPC] (0) 0x04eb7cf8da005c71278b2b40f0a7848a2272aa05ebc04ee44f79945a8fd2bb2a
// snip
[TestRPC]
[TestRPC] HD Wallet
[TestRPC] ==================
[TestRPC] Mnemonic:      capital first cram collect cycle need defy knife electric length napkin eagle
[TestRPC] Base HD Path:  m/44'/60'/0'/0/{account_index}
[TestRPC]
[TestRPC] Gas Price
[TestRPC] ==================
[TestRPC] 20000000000
[TestRPC]
[TestRPC] Gas Limit
[TestRPC] ==================
[TestRPC] 6721975
[TestRPC]
[TestRPC] Listening on 127.0.0.1:8555
[Coverage] Compiling .\contracts\AuthorizationContract.sol...
[Coverage] Compiling .\contracts\CommonContract.sol...
[Coverage] Compiling .\contracts\ManufacturerContract.sol...
[Coverage] Compiling .\contracts\Migrations.sol...
[Coverage] Compiling .\contracts\OrderContract.sol...
[Coverage] Compiling .\contracts\ProductContract.sol...
[Coverage] Compiling .\contracts\SupplierContract.sol...
[Coverage] Compiling .\contracts\SupplyChainLogContract.sol...
[Coverage] Compiling .\contracts\AuthorizationContract.sol...
[Coverage] Compiling .\contracts\CommonContract.sol...
[Coverage] Compiling .\contracts\ManufacturerContract.sol...
[Coverage] Compiling .\contracts\OrderContract.sol...
[Coverage] Compiling .\contracts\ProductContract.sol...
[Coverage] Compiling .\contracts\SupplierContract.sol...
[Coverage] Writing artifacts to .\build\contracts
[Coverage]
[Coverage] Instrumenting  ./coverageEnv/contracts/AuthorizationContract.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/CommonContract.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/ManufacturerContract.sol
[Coverage] Skipping instrumentation of  ./coverageEnv/contracts/Migrations.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/OrderContract.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/ProductContract.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/SupplierContract.sol
[Coverage] Instrumenting  ./coverageEnv/contracts/SupplyChainLogContract.sol
[Coverage] Running: truffle compile --network coverage
[Coverage] (this can take a few seconds)...
[Coverage] Compiling .\contracts\AuthorizationContract.sol...
[Coverage] Compiling .\contracts\CommonContract.sol...
[Coverage] Compiling .\contracts\ManufacturerContract.sol...
[Coverage] Compiling .\contracts\Migrations.sol...
[Coverage] Compiling .\contracts\OrderContract.sol...
[Coverage] Compiling .\contracts\ProductContract.sol...
[Coverage] Compiling .\contracts\SupplierContract.sol...
[Coverage] Compiling .\contracts\SupplyChainLogContract.sol...
[Coverage] Compiling .\contracts\AuthorizationContract.sol...
[Coverage] Compiling .\contracts\CommonContract.sol...
[Coverage] Compiling .\contracts\ManufacturerContract.sol...
[Coverage] Compiling .\contracts\OrderContract.sol...
[Coverage] Compiling .\contracts\ProductContract.sol...
[Coverage] Compiling .\contracts\SupplierContract.sol...
[Coverage] Writing artifacts to .\build\contracts
[Coverage]
[Coverage] Running: truffle test --network coverage
[Coverage] (this can take a few seconds)...
[TestRPC] net_version
[TestRPC] eth_accounts
[Coverage] Using network 'coverage'.
[Coverage]
[TestRPC] eth_accounts
[Coverage] Compiling .\contracts\AuthorizationContract.sol...
[Coverage] Compiling .\contracts\CommonContract.sol...
[Coverage] Compiling .\contracts\ManufacturerContract.sol...
[Coverage] Compiling .\contracts\OrderContract.sol...
[Coverage] Compiling .\contracts\ProductContract.sol...
[Coverage] Compiling .\contracts\SupplierContract.sol...
[TestRPC] eth_getBlockByNumber
[TestRPC] eth_accounts
[TestRPC] eth_getBlockByNumber
[TestRPC] net_version
[TestRPC] eth_getBlockByNumber
[TestRPC] eth_getBlockByNumber
[TestRPC] net_version
[TestRPC] eth_estimateGas
[TestRPC] eth_getBlockByNumber
[TestRPC] net_version
[TestRPC] eth_sendTransaction
[TestRPC] eth_call
[TestRPC] eth_blockNumber
[Coverage] Error: while migrating Migrations: Returned error: Exceeds block gas limit
[Coverage]     at C:\Users\Documents\test\SupplyChainLog\SmartContracts\SupplyChainLog\Solidity\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
[Coverage]     at <anonymous>
[Coverage]     at process._tickCallback (internal/process/next_tick.js:188:7)
[Coverage] Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2)
[Coverage] Solidity v0.5.0 (solc-js)
[Coverage] Node v8.9.3
[Coverage] -----------------------------|----------|----------|----------|----------|----------------|
[Coverage] File                         |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
[Coverage] -----------------------------|----------|----------|----------|----------|----------------|
[Coverage]  contracts\                  |        0 |        0 |        0 |        0 |                |
[Coverage]   AuthorizationContract.sol  |        0 |        0 |        0 |        0 |       15,16,20 |
[Coverage]   CommonContract.sol         |        0 |      100 |        0 |        0 |          11,16 |
[Coverage]   ManufacturerContract.sol   |        0 |        0 |        0 |        0 |... 3,94,97,101 |
[Coverage]   OrderContract.sol          |        0 |        0 |        0 |        0 |... 161,162,164 |
[Coverage]   ProductContract.sol        |        0 |        0 |        0 |        0 |... 223,225,229 |
[Coverage]   SupplierContract.sol       |        0 |        0 |        0 |        0 |... 3,94,97,101 |
[Coverage]   SupplyChainLogContract.sol |        0 |        0 |        0 |        0 |... 18,21,22,25 |
[Coverage] -----------------------------|----------|----------|----------|----------|----------------|
[Coverage] All files                    |        0 |        0 |        0 |        0 |                |
[Coverage] -----------------------------|----------|----------|----------|----------|----------------|
[Coverage]
[Coverage] Istanbul coverage reports generated
[Coverage] Cleaning up...
[Coverage] Some truffle tests failed while running coverage
[Coverage] node_modules\.bin\solidity-coverage exited with code 1
--> Sending SIGTERM to other processes..
[TestRPC] node_modules\.bin\testrpc-sc --port 8555 exited with code 1

I did update my project to reproduce this error:
See https://github.com/mstack/bootcamp-blockchain-smartcontracts/tree/master/Lab%202

[Coverage] Error: while migrating Migrations: Returned error: Exceeds block gas limit
[Coverage]     at C:\Users\azurestef\Documents\Github\bootcamp-blockchain-smartcontracts\Lab 2\Solidity\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
[Coverage]     at <anonymous>
[Coverage]     at process._tickCallback (internal/process/next_tick.js:188:7)
[Coverage] Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2)
[Coverage] Solidity v0.5.0 (solc-js)
[Coverage] Node v8.9.3

We can't support parallel execution of coverage and regular tests this way, sorry. It a super cool idea though.

Running the testrpc outside of the solidity-coverage while setting norpc: true in .solcover.js worked for me.

My .solcover,js:

module.exports = {
  port: 8555,
  testrpcOptions: '-g 0x1 -l 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -p 8555',
  norpc: true,
  compileCommand: '../node_modules/.bin/truffle compile --network coverage',
  testCommand: '../node_modules/.bin/truffle test --network coverage',
  copyPackages: ['openzeppelin-solidity'],
};

Command to run testrpc:

./node_modules/.bin/testrpc-sc -g 0x1 -l 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -p 8555

The above solution almost worked for me if it wasn't for the Number can only safely store up to 53 bits error that it was throwing.

After reading up on some other issues and how ethereumjs-vm might have a limit of 53 bits for the gas limit parameter that is provided what worked was starting testrpc with:

./node_modules/.bin/testrpc-sc -g 0x1 -l 9007199254740991 -p 8555

(The reason being that 9007199254740991 is equal to 2^53 - 1)

Thanks @GNSPS. As a sidenote - in the latest version testrpc-sc launches with high gas defaults that should be ok out of the box. Would love to know if that's not working.

I've had luck just copy-pasting the README network config into truffle-config.js and avoiding the gas options on the client when it needs to be launched separately.

It's still giving me a Returned error: VM Exception while processing transaction: out of gas error. 馃槥

@GNSPS Are you using 0.6.4? And can you show the truffle config, launch commands etc?

Got it working! 馃檶

Solidity-coverage is working out of the box, after all! Just had to up the gas parameter in truffle-config to something bigger than the default (commenting it out was not working). This is what did it for truffle-config.js:

module.exports = {
  networks: {
    development: {
[...]
    coverage: {
      host: 'localhost',
      network_id: '*', // eslint-disable-line camelcase
      port: 8555,
      gas: 800000000,
    },
[...]
  },
};

Thanks for the help @cgewecke !! 馃帀

@GNSPS Sweet!

I'm getting the same error as @GNSPS:

Error: VM Exception while processing transaction: out of gas

With [email protected], [email protected] and [email protected].

You can see the source code here: https://github.com/MainframeHQ/mainframe-lending-protocol/tree/f2bf524639a9c601e0690939bd20161f97f8d3a3

I tried setting the gas to 100 million but that didn't work.

Was this page helpful?
0 / 5 - 0 ratings