Fuzz Testing
Smart contracts on Stacks are immutable. Bugs are forever. Test early. Test often. Fuzzing finds edge cases that unit tests often miss.
What is Fuzz Testing?
Fuzzing hits your code with random inputs. It helps uncover unexpected behavior and subtle bugs. Unlike unit tests, it explores paths you didn't think of.
Rendezvous (rv
) is a Clarity fuzzer. It supports:
Property-Based Testing
You extract properties about your smart contract using Clarity. Rendezvous checks them multiple times with random inputs, in a stateful manner (the smart contract's state is not refreshed during the run).
What is a property?
A property is a universal truth about your smart contract's state, functions, etc.
How to extract a property?
Say that your smart contract has a function that reverses a list of uint
s. In this case, one property can be that "reversing a list twice returns the original list". The property will look like this:
Making your property valid for Rendezvous
For a property to be cosidered valid by Rendezvous, it has to comply with the following rules:
Function name starts with
test-
Function is declared as
public
Test passes when it returns
(ok true)
Test would be discarded if it returned
(ok false)
Test fails if it returns an error or throws an exception
Invariant Testing
You define read-only conditions in Clarity that must always hold true. Rendezvous attempts to create state transitions in your smart contract and continuously checks the conditions you defined to hold.
What is an invariant?
An invariant is a general truth regarding your smart contract's internal state. It will not be able to mutate the state, its role being solely to check the integrity of the state.
How to extract an invariant?
Making your invariant valid for Rendezvous
For an invariant to be cosidered valid by Rendezvous, it has to complain to the following ruleset:
Function name starts with invariant-
Function is declared as read-only (not public)
Function returns a boolean value (true if the invariant holds, false if violated)
The test can use the special context map to access execution history
Why Test in Clarity?
Rendezvous tests run in Clarity, just like your contracts.
Tests operate under the exact same constraints as production code.
Better understanding of Clarity.
No need to expose internals as public functions.
Fewer tools to manage.
Getting Started
Put tests next to contracts. Rendezvous will find them.
Installation
To install Rendezvous as a dependency in your project, use npm
:
This will add Rendezvous to your project's node_modules
and update your package.json
.
Rendezvous Docs
Last updated
Was this helpful?