...by Daniel Szego
quote
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Wednesday, December 6, 2017

Solidity and Truffle Tips and Tricks - solidity unit test and console


The new feature from solidity is pretty cool, it offers the possibility to write unit tests with the help of solidity. On the one hand it offers the advantage to write unit tests in solidity without the need to integrate a further language into the process. However, Solidity is not really designed to be a language for writing unit tests, as an example writing out information to the running console might be tricky as well. What you can use instead of the console is an event: 

event ConsoleLog(string message);

and if you want to write into the log simply raise an event in the code: 

ConsoleLog("debug message");

Unfortunately with the current version of Truffle, the solutions works only if the unit test actually failed. Despite it is more than nothing.