question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Solidity test can't be deployed: exceeds gas amount

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

“Large” solidity tests fail during the truffle test operation, with the message

The contract code couldn’t be stored, please check your gas amount.

This is similar to https://github.com/trufflesuite/truffle/issues/825 and I mentioned this there, but there are some differences. In particular, this is happening during test. I had poked around when I first started seeing these errors, and I found for instance that commenting out functions in Assert.sol let me include more in my test file before hitting that error.

But it turns out that bandaid only went so far. I still had to split my test into multiple files to get each to deploy, and in the end, even my simplest test (no steps I could split off to a separate file as I navigated through various calls to test a path) hit this error.

Interestingly, in the most recent case, I could deploy the test file if I changed x= new X(args); to x = X(DeployedAddresses.X()) as in my other files. The problem was that I needed to invoke the contract differently for this test than for the others. If I invoke it differently in the migration file, this test works but others now break because I’ve changed the behavior.

Steps to Reproduce

Unfortunately, I don’t know a way to distill this to something reproducible without exposing proprietary code.

Expected Behavior

Test contract will run.

Actual Results

    1) "before all" hook: prepare suite


  0 passing 
  1 failing

  1) TestX "before all" hook: prepare suite:
     Error: VM Exception while processing transaction: out of gas
      at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:41484:16)
      at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:329540:36
      at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:325210:9
      at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:328239:7)
      at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176416:18)
      at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176706:12)
      at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176861:12)
      at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176821:24)

Environment

  • Operating System: Ubuntu 16
  • Ethereum client: Ganache CLI v6.0.3 (ganache-core: 2.0.2) Also true of recent ganache (gui)
  • Truffle version (truffle version):

Truffle v4.0.4 (core: 4.0.4) Solidity v0.4.18 (solc-js)

Also true of the master version as of early this week, which I rebuilt from sources.

  • node version (node --version): v6.11.0

  • npm version (npm --version): 3.10.10

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
seesemichaeljcommented, Jul 2, 2018

The flag was added to ganache-cli in https://github.com/trufflesuite/ganache-cli/pull/550

4reactions
seesemichaeljcommented, Jul 5, 2018

Hey @asoong,

I’m sorry for not initially suggesting this; I didn’t quite do my homework (I’m knew to the Truffle team).

Looking at the docs, I highly suggest that you use the compiler optimizer since your contracts shouldn’t deploy on main and test nets without it! You can add this in your truffle.js configuration: https://truffleframework.com/docs/advanced/configuration#solc

solc: {
  optimizer: {
    enabled: true,
    runs: 200
  }
}

You can increase the number of runs to optimize more.

I’m going to go ahead and close this. This comment seems to be the answer to this issue

Please let us know if you still have issues after that!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Truffle solidity tests: out of gas & exceeds block gas limit
I am trying to run some basic test w/ my contract, written with Truffle's Solidity tests (tests written in Solidity). ... Note: This...
Read more >
Avoiding out-of-gas error in large Ethereum smart contracts
It means that the total amount of gas for all the transactions in a block including contract deploy cannot exceed this number.
Read more >
Solidity Error Exceeds block gas limit | Edureka Community
I have written a smart contract and tried to deploy it on testrpc. I am getting the following error: Error: Exceeds block gas...
Read more >
Exceeds block gas limit when deploy the smart contract local ...
One possibility is the gas limit became too low to be able to mine your contract. Because the gas limit in a private...
Read more >
gas limit gas used by transaction hardhat - You.com | The AI ...
Any transaction with the gas limit greater than 2 63 - 1 should be ignored by a client. Motivation. Designing Ethereum VM for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found