I am writing a proof of concept using truffle and testrpc and I have to spend hours optimizing the code to avoid out of gas errors. Is there a way to bypass this error or have a very high value. I have tried setting high limit on testrpc
testrpc -l 4500000000000
Tried specifying high gas in truffle.js
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
,gas: 500000000
}
}
But still, encounter out of gas when running my tests.
Transaction: 0x0981ab4c4ebdcb851e138d7a18344d256489ef01259f6b714edefdfe23ab824c
Contract created: 0xccb7c4bd42c1e8e809d9f4573a2c2e0590b27b78
Gas usage: 500000000
Block Number: 23
Block Time: Tue Jan 16 2018 08:35:30 GMT-0800 (PST)
Runtime Error: out of gas
If I comment out 5 lines of the code triggering events (for validation failures), it runs without any issues with the default 6.7M gas. Here are my events, I have switched to bytes32 from string.
// Used for error handling.
event AnyException(bytes32 m);
event AnyException(bytes32 m1, bytes32 m2);
event AnyException(bytes32 m1, bytes32 m2, bytes32 m3);
Here is a successful transaction after commenting 5 lines generating events using default gas in truffle.js.
Transaction: 0xb9f0f703c7f7e1ae5d51fc8170c00d2f12de146c6c2d5b48a47bd2a1e2a14203
Contract created: 0x87d84cf9d012a181658ce76fa03ab1a7bc0ad538
Gas usage: 6227032
Block Number: 28
Block Time: Tue Jan 16 2018 08:51:03 GMT-0800 (PST)
How can gas usage jump so high with 5 lines of event logs?