Using property-based testing to test Token and Crowdsale smart contracts

Nicolás Berger
Winding Tree
Published in
2 min readAug 2, 2017

--

I had the opportunity to participate and speak at the last Lisk Berlin Blockchain Meetup on July 18th. My talk was about how we use property-based testing (a.k.a. generative testing or QuickCheck) to throughly test the smart contracts that govern the Líf token (the token of the Winding Tree decentralized travel marketplace) and the upcoming Winding Tree ICO crowdsale.

There were other great talks: Max Kordekfrom (from Lisk) gave a wrap-up on what they’ve been doing and what’s next for Lisk. Thomas Schouten (also from Lisk) presented his “Thoughts on funding mechanisms and a tokenised future”. Benjamin Jones (from Bitwala) talked about “Crypto & The Real World — An unholy marriage”. My talk was titled “Testing a Token with more than examples — Stateful property-based testing of smart contracts” and you can watch it right here (our talk starts at 52:47):

What is property-based testing?

Property-based testing is a software testing technique that aims at verifying properties of a program that must hold true on every input, where the inputs are generated randomly from the broad universe of data that makes sense for the program.

Instead of each test being just an example input with assertions on the expected output (as it is in example-based testing), there are generators that generate all sorts of input data, properties that are checked against that input data and finally, in case a property fails on a certain input, a shrink process will try and find the smallest example that still makes the property to fail.

What’s powerful about property-based testing is that by feeding random data to your program, it can actually find bugs and edge cases that might not have been found by a programmer just writing example-based tests. It also forces the programmer to think harder about the problem at hand, as writing the properties is sometimes not a trivial task.

The most famous library for property-based testing is called QuickCheck, first implemented in Haskell and then in Erlang. Other great implementations are Hypothesis for python, test.check for clojure (of which I’m a contributor), and JSVerify for javascript which is the one we are using in Winding Tree.

Want to learn more about property-based testing? Start by watching this great talk by John Hughes (one of the original creators of both the Haskell and Erlang QuickCheck libraries): Testing the Hard Stuff and Staying Sane. Maybe read these two posts: Property-based testing: what is it? and An introduction to property based testing with JS Verify. Also feel free to continue the conversation in our slack or via twitter.

Finally: Thanks to Lisk and especially to Joel Fernandez for the opportunity to participate in the meetup!

--

--

Software Engineer. Clojure(Script), Javascript, etc. Ramblings about things I love & hate.