-2

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
rsc05
  • 3,626
  • 2
  • 36
  • 57

2 Answers2

0

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
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • @Peter Hejda but you can switch between several accounts in solidity as well see [1]. What makes JS special in block time? [1]: https://ethereum.stackexchange.com/questions/62555/switch-between-accounts-to-run-smart-contracts – rsc05 Jun 04 '22 at 11:48
  • 1
    @Anonymous This is JavaScript test in the linked post, not Solidity test... Ad block time: Imagine you have a function that unlocks tokens for some authorized address (e.g. dev team & advisors) after a predefined time (e.g. a year). When you want to test this functionality, you need to simulate running the function both before and after that predefined time. – Petr Hejda Jun 04 '22 at 12:55
0

I disagree with that. If you use a tool like Foundry, the tests are way faster in Solidity than in JS with Hardhat, you can use fuzzing to get random parameters in your tests and you can do the exact same tests that you do in Hardhat.

You can test everything, including reverts, events, using different accounts, setting the blocktime (you can override all the virtual machine's properties), gas consumption and basically anything you would need.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
0xAnthony
  • 36
  • 1