26

How are Ethereum contracts tested? I've seen Truffle which referrers to itself as an Ethereum development framework. Are there any other frameworks and what is their level of maturity? Is there a de facto standard framework used by most contract developers?

How would one go about testing the Greeter contract (https://chriseth.github.io/browser-solidity/) for example?

0

4 Answers 4

29

Via a Framework

There are currently four primary frameworks available that can facilitate writing unit tests for your contracts. Listed in order of Github stars as of 2016-01-25.

Disclaimer: I'm the author of the Populus testing library.

Embark

This is the framework with the widest adoption.

Truffle

dapple

Populus

Roll your own

You can also roll your own testing framework pretty easily by leveraging either ethereumjs-vm or pytester depending on whether you prefer javascript or python.

6
  • 1
    Populus looks cool. I'll also give it a try.
    – hcvst
    Commented Jan 26, 2016 at 12:02
  • By all means let me know if you run into any problems. Commented Jan 26, 2016 at 15:51
  • 2
    Do any of these frameworks allow systematic testing of the effect of out of Gas exceptions? (I'm thinking that some kind of montecarlo style approach where you check invariants against lots of scenarios might be useful) Commented Feb 25, 2016 at 23:34
  • 1
    "Do any of these frameworks allow systematic testing of the effect of out of Gas exceptions?" I'm not exactly sure what you mean by this. I know that with Populus you can test this by seeing that a TransactionError exception is raised as well as verifying that the gasUsed value from the transaction receipt is 100% of the provided gas. Commented Feb 27, 2016 at 2:37
  • There's also an option to write UTs in Go, using statically compiled bindings (i.e. code completion) from the .sol files: github.com/ethereum/go-ethereum/wiki/…. I've not found very much documentation on this approach though, would be interested in what others have found.
    – Symmetric
    Commented Jul 8, 2017 at 17:35
1

Brownie

One of the best blockchain development framework written in Python. It supports native pytest which is able to run unit as well as integration tests.

The whole info on how to write and perfrom proper testing:

https://eth-brownie.readthedocs.io/en/stable/tests-pytest-intro.html

0

Waffle

This is another popular testing library. It has support for TypeScript and works well with HardHat.

https://github.com/EthWorks/Waffle

0

I can only offer you a link to these instructions that had helped me personally.

It shows the basics of testing smartContracts by using both Solidity and JavaScript. (You pick your favourite)

https://betterprogramming.pub/how-to-test-ethereum-smart-contracts-35abc8fa199d

Hope it helps you too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.