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:
- Created 6 years ago
- Reactions:8
- Comments:11 (4 by maintainers)
The flag was added to ganache-cli in https://github.com/trufflesuite/ganache-cli/pull/550
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#solcYou 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!