# Avoiding out of gas for Truffle tests

Author: Markus Waas

Published: 2020-03-07T06:26:23.000Z

Updated: 2026-09-13T14:25:30.000Z

Source: [https://soliditydeveloper.com/avoiding-out-of-gas-for-truffle-tests](<https://soliditydeveloper.com/avoiding-out-of-gas-for-truffle-tests>)

## Compatibility and review

Before you start

Corrected the distinction between gas units and transaction fees. The zero-gas-price snippet is a legacy Truffle test convenience for networks explicitly configured to accept it; it never raises the execution gas limit.

[Official reference](<https://ethereum.org/developers/docs/gas/>)

You have probably seen this error message a lot of times:

```
Error: VM Exception while processing transaction: out of gas
```

Truffle can surface confusing errors, especially in older versions. But when a transaction really runs out of gas, changing its gas price will not fix it: the **gas limit** controls the available execution work, while the **gas price** controls the fee per unit.

For an actual out-of-gas failure, inspect the execution, estimate the required gas and check the transaction and block limits. A function that grows without bound may need redesign rather than a larger limit.

There is a separate test convenience: on a local network configured to accept zero fees, `gasPrice: 0` simplifies ETH-balance assertions. It does not make execution unlimited, and a network with a positive base fee will reject a zero-price transaction. In a compatible legacy Truffle setup, the defaults look like this:

```javascript
MyContract.defaults({
    gasPrice: 0,
})
```

With zero fees accepted by your local test chain, ETH-balance assertions no longer need a transaction-fee adjustment. For realistic fee tests, use the receipt’s gas usage and effective gas price instead.

## Keep testing gas limits

Even unit tests benefit from checking that important operations remain within realistic gas limits. A passing balance assertion does not prove that an operation is affordable or can execute on your target network.

[Truffle and Ganache were sunset in 2023](<https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat>); preserve the snippet for legacy projects and use a maintained environment for new work.
