Search code examples
soliditytruffle

Why using Solidity programming language to test smart contracts written in Solidity is not a good idea?


I am trying to use truffle, whereby truffle clearly states that you can use its testing functionalities to allow you to use solidity programming languages to test solidity contracts. Online, however, many developers use Mocha and Chai. Hence, require JS.

I know I can avoid using JS for testing and only use Solidity in truffle. But why no one is saying the limitation of doing this out loud. Moreover, are there any resources that clearly state this?

Why there are not enough resources on testing using solidity language?


Solution

  • Since JS tests are executed in higher scope, they have access to transaction receipts, and you can validate event logs for example. Receipts are not available in Solidity tests because they haven't been produced yet, as the transaction hasn't finished executing at that moment.

    Also because of this higher scope, JS testing frameworks allow you to interact programmatically with blockchain emulators. For example:

    • switch between several accounts sending transactions, usually used for testing authorization
    • set blocktime, so that you can test time-sensitive functionality