4

I have a contract which is very long. It can't be deployed without compressing it first and so it makes it impossible to properly debug it in mix.

As anyone found a workaround than working on smaller chunks ? I'm finding it difficult to debug only using javascript since transactions are taking 15-30sec to process.

  • 1
    Hi, Why can't you debug the uncompressed contract in mix? (Just curious, is there any error / issue with that?) – Waqar Lim Apr 10 '16 at 19:44
  • most of the times it will either make mix crash or just show strange things,like calling a whole bunch of function that aren't even part/linked in anyway with the function i'm testing, the VM probably works fine but the part where it's supposed to highlight what it's doing + gas usage is messed up and seems to works fine on uncompressed contracts – user697 Apr 10 '16 at 20:39
  • Yeah, mix is killing the browser. What about creating an issue in the Mist repo? – niksmac Apr 11 '16 at 1:21
5

At risk of being downvoted, I'll say "don't debug using a debugger".

Use solidity events, and log profusely in your contracts. Logging is dirt cheap when it comes to gas, and it's easy to capture every Solidity event using web3.js event listeners, which parse the output to the degree where you can log it straight to a JSON logfile with a couple of lines of code.

So log everything that happens in your contracts to a logfile, and you can reconstruct what happened. The bonus part of this is if you have some issue later in production, and you have all this gas-cheap logging enabled, you can likely find the source of your problem quickly, post-mortem. This technique has saved me numerous times in all my years of development. It's the "bigdata" approach (but at small scale)

I've debugged over 1000 lines of solidity this way already with complex business logic, it's worked pretty well. Event logging has been one of the more delightful features of Ethereum that I've discovered.

transactions are taking 15-30sec to process.

Use a testrpc implementation or hack up geth to mine every second like I did. That also helped me debug very quickly. See links below.

Some links for further reading:

Solidity Events

web3.js listening for all events

Bunyan, a node.js logging module

Hacking Geth to make it mine once/second

ethereumjs-testrpc AFAICT is the most mature EVM emulator for testing.

If you do mostly on-blockchain interactions, then Dapple is a unit test framework for Solidity. I haven't used it but I hear it's good. (my app is mostly off-blockchain right now, so I haven't needed it).

And finally, a good way to stop making hard to find bugs is to write black box unit tests. I hacked up my own unit test framework, but I hear truffle is pretty mature now so that might be a good choice to start with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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