Picking up a Clarity contract

This article is part of the Pandora series of articles.

Pandora enables property-based testing, fuzzing, and invariant testing for smart contracts that run on the Stacks 2.x layer-1 blockchain. Pandora discovers and run tests written in Clarity and TypeScript.


Cargo is a fictional, simple smart contract that runs on the Stacks blockchain. Its purpose is to help facilitate tracking the progress a shipment makes throughout the supply chain.

As a smart contract, Cargo has the following properties:

You can find out more about Cargo in this article by Kenny Rogers. Cargo is deployed in Stacks testnet as ST3QFME3CANQFQNR86TYVKQYCFT7QX4PRXM1V9W6H.cargo.

Cargo was tested, but a bug made its way into testnet1.

Detecting the unexpected

Testing can decrease the number of defects but not remove all defects2. Mainstream, example-based, unit tests verify that a given function works as expected. What you want is one step further:

Verify that combinations of functions in the smart contract work as expected.

There is known technique for doing that, which I have noticed also on Ethereum, refered to as invariant testing3 and can be–and should be–also used when building on Stacks.

Next: Invariant testing from command-line.

  1. Reported by LNow and resolved by Kenny Rogers in this commit. 

  2. Program testing can be used to show the presence of bugs, but never to show their absence.–Dijkstra (1970) “Notes On Structured Programming” (EWD249), Section 3 (“On The Reliability of Mechanisms”), corollary at the end. 

  3. Model-based testing, also known as invariant testing on the Ethereum dapp.tools and forge communities, has its origins in Haskell (QuickCheck) and later in Erlang (Quviq QuickCheck). The technique is described in this paper.