Hi,
I'm looking for some general tips in how to debug test non-trivial contracts written in Solidity. Here is what I currently use
1)
https://chriseth.github.io/cpp-ethereum/ - great for checking that a contract will compile
2) Alethzero - I'd really like to see more detailed documentation for this, specifically understanding / decoding the output from transaction calls (visible when clicking on a transaction sent to a contract in the blockchain view). I'd also like help decoding the internal state of the contract (visible when clicking on the Accounts tab and then selecting a contract).
3) Mix - latest Mac OS X build doesn't currently agree with 1) and 2), e.g. internal functions returning arrays of structs, but when building with an earlier version of Mix, it was very useful to set up scenarios, send transactions into the contract, query the current contract state via public functions etc. But now it seems to be less usable, and is lacking good documentation.
4) JS/web3.js front end, eg. AngularJS + Web3 - this is useful for querying state via public / external transactions, but doesn't give any line-by-line debugging facilities (and there is no println-like functionality that can be inserted). I have raised events and listened for them previously, but this is a heavyweight approach just to understand whether the internals are working correctly.
5)
http://meteor-dapp-cosmo.meteor.com/ - I haven't tried this, although it looks impressive. It chokes on my Solidity code that compiles elsewhere, however.
6)
https://www.npmjs.com/package/truffle or Embark - again, I haven't tried these, but like the idea of being able to unit-test contracts. But AFAIK, they still rely on black-box testing of external functions, so I'm not sure how to test internal functions.
I'd appreciate any other thoughts, particularly on how to test internal functions.
James
http://james.carlyle.space
Comments
Here is a contrived example
contract Contract { function arrayLength(uint[] _array) internal returns (uint) { return _array.length; } function processArray() public constant returns (uint) { uint[] a1; return arrayLength(a1); } function trivial(uint _uint) public constant returns (uint) { return _uint; } }
I want to be able to test that the arrayLength function works. Mix UI doesn't allow me to set the _array parameter value when I set up the scenario, although the arrayLength function is visible in the dropdown, when I create a new transaction in the chain that I want to execute.
Wierdly, when I click Rebuild, and edit the transaction that calls processArray(), it shows a parameter input field called _uint, i.e. the parameter for a different function. Will try and take a screenshot and raise an issue.
sorry for late reply.
As part of testing process you may use Solhint solidity linter. It provides security checks, style guide validation and best practice validations.
It's there:
https://github.com/protofire/solhint
https://protofire.github.io/solhint/
- Ilya