5

I am trying to run some basic test w/ my contract, written with Truffle's Solidity tests (tests written in Solidity).

When runninng truffle test, I get

Error: VM Exception while processing transaction: out of gas

Note: This is caused by the contract constructor new ..., which is indeed doing a lot of things. And I can't break anything down in my code.

Is there any way to get this working with a test written in Solidity? Is there a way to configure the amount of gas the test contract has available?

--

UPDATE:

Actually I figured out changing the gas config value in truffle.js does have an effect. Yet, I am hitting now another roadblock

Error: Error: Exceeds block gas limit

I guess that I have no other choice than optimising the deployment (thus, the constructor) of my contract so as to make it lighter?

4

Add gas: 350000 to your truffle.js file, example of mine below

module.exports = {
  networks: {
     development: {
       host: "localhost",
       port: 8545,
       network_id: "*", // Match any network id
       gas: 3500000
     }
   },
   mocha: {
    useColors: true
   }
};

The new version of truffle, version 4 at this moment has added a gas check to tests. so this is needed now.

3

I ran into the same issue today - but for me the issue was, that my test-file.sol was seemingly too large. So I split up my tests into two files, and all the tests ran just fine again.

It probably makes sense anyways to structure test-files in multiple smaller suites than one big file that you'd have to scroll through.

2

Probably should make it lighter.

If you're using TestRPC or a private chain, you can set the gaslimit, but it's a network property. I would reserve that method for troubleshooting i.e. to confirm what you're dealing with. Note that out-of-gas sometimes happens when the contract throws on purpose, so it can be misleading.

If you don't find a way to operate within a budget you're probably setting yourself up for disappointment when you try to deploy to the live network.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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