Solidity – How to Set Maximum Block Gas in Ganache-CLI

ganachegasgas-limitsoliditytransactions

I'm running ganache-cli which seems to have a block gas maximum of around 6.5 million. All the research I've done about this question seems to provide answers of the user themselves setting the user gas LIMIT (not what I want) or setting a gas amount for the contract creation only, also not what I want.

What I have is a smart contract that I want to run millions of automated unit tests over in a "for" loop on the Solidity side. The smart contract contains randomness so each time it loops through a different result is output. I need to ensure over millions of unit tests that all the random results reach their expected value.

The problem is that I can only do about 20 "loops" before the 6.5 million gas is reached. I've tried doing a for loop on the web3 javascript side with Metamask however the problem here is that Metamask will pop up asking me to confirm the transaction every single time I want to run these 20 "loops". So 100 unit tests would require me clicking 5 times. A million? An awful lot.

How would I go about doing this? I thought if there is a way to increase the block gas maximum I might be able to increase my loop size to at least 1000 or so.

Or if you're aware of an alternate solution how I could automate millions of unit tests that would be great.

Best Answer

There is a way to increase the gasLimit. You will use a flag when starting ganache-cli to do so. Per the README, use -l or --gasLimit (the block gas limit (defaults to 0x6691b7)).

However, if you are having to do this, you will not be able to perform this on the main network.

A lot of Ethereum development is design decisions on what goes on and off chain. Due to the block gasLimit, a lot of decisions, such as this, conclude in some sort of off chain mechanism.

Related Topic