I have a sol contract X.sol and a sol test file TestX.sol. X.sol is large: ~4m Gas after optimisation

TextX.sol compiles, migrates and executes tests fine when just executing a single test - testY, however.. when I add a testZ function and add even 1 line of (basic) solidity.. I get the following error:

1) TestX "before all" hook: prepare suite: Error: while migrating TestX: Returned error: VM Exception while processing transaction: out of gas

However if I leave the body of testZ empty, it migrates fine.

Basically, I just want to know if there is a way to get visibility on the size of the compiled test file? Or a way to optimise gas usage?

networks: {
  development: {
    host: 'localhost',
    port: 8545,
    gas: 6130000,
    network_id: '*'
solc: {
  optimizer: {
    enabled: true,
    runs: 200

1 Answer 1


Use this for Truffle:

development: {
    host:       'localhost',
    port:       8545,
    network_id: '*',
    gasPrice:   0x1,
    gas:        0x1fffffffffffff

And this for Ganache:

  • Cheers, manually changing gas limit for Ganache was sufficient
    – alsco77
    Dec 18, 2018 at 15:44
  • I would like to add that I generally do not recommend this mode of operation. Better use "real" gas-price and gas-limit (i.e., similar to what's used on mainnet). Otherwise, you might be in for a surprise when you go to production. In short, use it in solidity-coverage if you must, but try to avoid using it in truffle. Jun 17, 2020 at 15:55

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.