1

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.

1

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.

  • 1
    Exactly what I was looking for, thank you! – Ectogold Nov 16 '18 at 10:36
0

To extend the previous answer, you can use --gasLimit=0x1fffffffffffff.

This will set the block gas limit to 2 ^ 53 - 1, which happens to be Javascript's max safe integer.

You cannot use a value larger than that, because Ganache was implemented in Javascript, and they did not bother to use a BigNumber for this field in opposed to other fields (for example, when setting --account=address,balance, you can use a value larger than Javascript's max safe integer for the balance part, because it is probably converted to BigNumber instead of Number).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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