I am testing the amount of gas used for my contract functions using Truffle and Ganache CLI. Does anyone know if I can assume that the gas usage reported during my tests will be an accurate representation of the gas that will be used when I deploy to the main ethereum network?
In theory if you use the same network version (the right hard fork) the gas costs should be exactly the same.
However there are some aspects which may change the gas costs:
- Calls the external contracts if the external contracts' contents are not the same
- Amount of data in contract(s). Saving a value in a variable for the first time is more expensive than subsequent saves, for example.
- In general different contract states