Published on

Testing a Permissioned Networks Gas Limit Is Being Hit

Authors

When working on an Ethereum permissioned network Eth is not as essential as on the Ethereum public chain.

But Eth is still vital for gas to prevent contracts running forever or for too long.

To test that a permissioned network has had its gas configured properly I wrote a little contract that has a long-running loop:

pragma solidity ^0.5.3;

contract LongRun {

    function hitGasLimit() external {
        for(uint i=0; i<=1000000;i++){
        }
    }
}

I then hit this long running contract method in a migration script called 1_super_long_run.js:

const LongRun = artifacts.require('./LongRun.sol')

module.exports = async (deployer) => {
  await deployer.deploy(LongRun)
  const longRunInstance = await LongRun.deployed()
  await longRunInstance.hitGasLimit()
}

If the gasLimit is configured properly you should see output similar to the below:

...
Error: Returned error: VM Exception while processing transaction: out of gas
...