Published on

Testing Solidity Code

Authors

When you write contracts (a.k.a code) for an Ethereum blockchain the most common language used to write these contracts is Solidity. To test this code you can use the excellent Truffle framework together with Ganache (a personal Ethereum blockchain designed to make it easy to test Ethereum code against a chain).

Where it can get hairy is if you try to test Solidity code using Solidity code. If you are used to things like breakpoints or logging out what is going on to try debug a test you will find this pretty painful to do in Solidity tests. For example trying to log out a Solidity address field did not seem to have a simple approach to do this (you need to cast address to a type that the standard logger accepts which was not simple).

In the end the simplest approach was to use Javascript to test Solidity code. Even looking at some of the big projects like OpenZeppelin you find that they too test their code using Javascript.