Skip to content

Commit fa2231f

Browse files
authored
Rendezvous-related updates following v1 release (#1864)
1 parent 8ee1e48 commit fa2231f

6 files changed

Lines changed: 225 additions & 95 deletions

File tree

docs/build/get-started/developer-quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ Now with the actual writing of your contract complete, we now need to test its f
477477

478478
* Contract interaction in the [Clarinet REPL](../clarinet/contract-interaction.md)
479479
* Running your contract in a [local blockchain environment](../clarinet/local-blockchain-development.md)
480-
* Fuzz testing with [Rendezvous](https://stacks-network.github.io/rendezvous/)
480+
* Fuzz testing with [Rendezvous](https://stx-labs.github.io/rendezvous/)
481481
* Writing unit tests with the [Clarinet JS SDK](../clarinet/testing-with-clarinet-sdk.md)
482482

483483
We'll go with unit testing for now. In your `tests` folder, open up the related `message-board.test.ts` file and let's use the unit test written below.

docs/build/rendezvous/overview.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ A property is a universal truth about your smart contract's state, functions, et
2828

2929
**How to extract a property?**
3030

31-
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:
31+
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". You write the property directly inside your contract, marked as [simnet-only code](../clarinet/simnet-only-code.md):
3232

3333
```clarity
34-
(define-public (test-reverse-list (seq (list 127 uint)))
34+
;; #[env(simnet)]
35+
(define-private (test-reverse-list (seq (list 127 uint)))
3536
(begin
3637
(asserts!
3738
(is-eq seq
@@ -48,10 +49,11 @@ Say that your smart contract has a function that reverses a list of `uint`s. In
4849

4950
**Making your property valid for Rendezvous**
5051

51-
> For a property to be cosidered valid by Rendezvous, it has to comply with the following rules:
52+
> For a property to be considered valid by Rendezvous, it has to comply with the following rules:
5253
>
54+
> * Function lives in the contract file, annotated with `;; #[env(simnet)]`
5355
> * Function name starts with `test-`
54-
> * Function is declared as `public`
56+
> * Function is declared as `private`
5557
> * Test passes when it returns `(ok true)`
5658
> * Test would be discarded if it returned `(ok false)`
5759
> * Test fails if it returns an error or throws an exception
@@ -68,9 +70,10 @@ An invariant is a general truth regarding your smart contract's internal state.
6870

6971
**How to extract an invariant?**
7072

71-
Say that you have a counter contract, having functions to `increment` and `decrement`. In this case, you could use the Rendezvous [`context`](https://stacks-network.github.io/rendezvous/chapter_6.html?#the-rendezvous-context) to extract an invariant regarding your smart contract's internal state:
73+
Say that you have a counter contract, having functions to `increment` and `decrement`. In this case, you could use the Rendezvous [`context`](https://stx-labs.github.io/rendezvous/chapter_6.html#the-rendezvous-context) to extract an invariant regarding your smart contract's internal state:
7274

7375
```clarity
76+
;; #[env(simnet)]
7477
(define-read-only (invariant-counter-gt-zero)
7578
(let
7679
(
@@ -92,12 +95,17 @@ Say that you have a counter contract, having functions to `increment` and `decre
9295

9396
**Making your invariant valid for Rendezvous**
9497

95-
> For an invariant to be cosidered valid by Rendezvous, it has to complain to the following ruleset:
98+
> For an invariant to be considered valid by Rendezvous, it has to comply with the following ruleset:
9699
>
97-
> * Function name starts with invariant-
98-
> * Function is declared as read-only (not public)
100+
> * Function lives in the contract file, annotated with `;; #[env(simnet)]`
101+
> * Function name starts with `invariant-`
102+
> * Function is declared as `read-only`
99103
> * Function returns a boolean value (true if the invariant holds, false if violated)
100-
> * The test can use the special context map to access execution history
104+
> * The test can use the special `context` map to access execution history
105+
106+
{% hint style="info" %}
107+
Invariant testing requires the `context` map and a `update-context` private function in your contract (both annotated with `;; #[env(simnet)]`). Rendezvous uses them to track how many times each public function has been called. See the [Rendezvous Reference](https://stx-labs.github.io/rendezvous/chapter_6.html#the-rendezvous-context) for the exact definitions.
108+
{% endhint %}
101109

102110
## Why Test in Clarity?
103111

@@ -129,14 +137,13 @@ Running tests in Clarity reduces the number of external tools and integrations y
129137

130138
## Getting Started
131139

132-
Put tests next to contracts. Rendezvous will find them.
140+
Write your tests directly inside your contract, marked as [simnet-only code](../clarinet/simnet-only-code.md) with the `;; #[env(simnet)]` annotation. Clarinet strips this code when deploying to real networks, so it never reaches mainnet — and Rendezvous picks it up automatically during testing.
133141

134142
```
135143
my-project/
136144
├── Clarinet.toml
137145
├── contracts/
138-
│ ├── my-contract.clar # Contract
139-
│ ├── my-contract.tests.clar # Tests
146+
│ └── my-contract.clar # Contract + its #[env(simnet)] tests
140147
└── settings/
141148
└── Devnet.toml
142149
```
@@ -155,5 +162,7 @@ This will add Rendezvous to your project's `node_modules` and update your `packa
155162

156163
### Additional Resources
157164

158-
* \[[Github](https://stacks-network.github.io/rendezvous/)] Rendezvous repo
159-
* \[[Youtube @jofawole](https://youtu.be/deWQxCEy9_M?si=bBpUoKGpJvFLFu_9)] How to Use Rendezvous to Fuzz Clarity Contracts
165+
* \[[GitHub](https://github.com/stx-labs/rendezvous)] Rendezvous repository
166+
* \[[Rendezvous Book](https://stx-labs.github.io/rendezvous/)] Full documentation
167+
* \[[Library API](https://stx-labs.github.io/rendezvous/chapter_9.html)] Drive the testing loop yourself from TypeScript
168+
* \[[YouTube @jofawole](https://youtu.be/deWQxCEy9_M?si=bBpUoKGpJvFLFu_9)] How to Use Rendezvous to Fuzz Clarity Contracts

docs/build/rendezvous/quickstart.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,13 @@ The main functions and state of the contract are now covered by tests. Line cove
246246

247247
Rendezvous lets you test a broader range of inputs, not just specific examples. Let's see how to write your first property-based test and why it matters.
248248

249-
### Create the Test File
250-
251-
Create the Rendezvous test file:
252-
253-
```bash
254-
touch contracts/stx-defi.tests.clar
255-
```
256-
257249
### Add an Ice-Breaker Test
258250

259-
Before writing any meaningful properties, it's a good idea to check that Rendezvous can run. Add a simple "always-true" test to verify your setup.
260-
Open `contracts/stx-defi.tests.clar` and add an always-true test:
251+
Before writing any meaningful properties, it's a good idea to check that Rendezvous can run. Add a simple "always-true" test, annotated with `#[env(simnet)]`, to the end of `contracts/stx-defi.clar`:
261252

262253
```clarity
263-
(define-public (test-always-true)
254+
;; #[env(simnet)]
255+
(define-private (test-always-true)
264256
(ok true)
265257
)
266258
```
@@ -316,15 +308,14 @@ If you see similar output, your setup works. You're ready to write a **real prop
316308

317309
### Define a Borrowing Property
318310

319-
You want to test that **borrowing always updates the loan amount correctly**:
311+
You want to test that **borrowing always updates the loan amount correctly**. Add this to the end of `contracts/stx-defi.clar`:
320312

321313
```clarity
322-
;; stx-defi.tests.clar
323-
314+
;; #[env(simnet)]
324315
;; Property: Borrowing should always update the loan amount correctly.
325316
;; The new loan amount should equal the old loan amount plus the borrowed
326317
;; amount.
327-
(define-public (test-borrow (amount uint))
318+
(define-private (test-borrow (amount uint))
328319
(let (
329320
;; Record the loan amount before performing any action that would end up
330321
;; changing the internal state of the smart contract. Query the loans map
@@ -353,8 +344,8 @@ You want to test that **borrowing always updates the loan amount correctly**:
353344

354345
Rendezvous:
355346

356-
1. Injects all property-based tests directly into the deployed contract.
357-
2. Detects all public `test-*` functions automatically.
347+
1. Deploys the contract with all `#[env(simnet)]`-annotated test functions included.
348+
2. Detects all private `test-*` functions automatically.
358349
3. Generates a random sequence to call each test.
359350
4. Produces random argument values for each function parameter.
360351
5. Randomly selects senders from settings/Devnet.toml.
@@ -378,13 +369,14 @@ Let's address them one by one.
378369

379370
### Handle Preconditions
380371

381-
**First, you need deposits.** You can create a helper function that Rendezvous will pick up during property-based testing runs. This helper will allow deposits to be created so other tests can check properties that require deposits:
372+
**First, you need deposits.** You can create a helper function that Rendezvous will pick up during property-based testing runs. Add this to `contracts/stx-defi.clar`:
382373

383374
```clarity
375+
;; #[env(simnet)]
384376
;; This is a helper function that will eventually be picked up during
385377
;; property-based-testing runs. It allows creating deposits in the smart
386378
;; contract so other tests can check properties requiring a deposit.
387-
(define-public (test-deposit-helper (amount uint))
379+
(define-private (test-deposit-helper (amount uint))
388380
(let (
389381
;; Call the deposit function and ignore the result.
390382
(deposit-result (deposit amount))
@@ -394,13 +386,14 @@ Let's address them one by one.
394386
)
395387
```
396388

397-
**Next, add discard logic to the borrow test.** A test is discarded when it returns `(ok false)`. Wrap the core test logic in a conditional that checks for invalid preconditions (the three cases listed above) and returns `(ok false)` to discard those cases:
389+
**Next, add discard logic to the borrow test.** A test is discarded when it returns `(ok false)`. Replace the previous `test-borrow` with this version that checks for invalid preconditions (the three cases listed above) and returns `(ok false)` to discard those cases:
398390

399391
```clarity
392+
;; #[env(simnet)]
400393
;; Property: Borrowing should always update the loan amount correctly.
401394
;; The new loan amount should equal the old loan amount plus the borrowed
402395
;; amount.
403-
(define-public (test-borrow (amount uint))
396+
(define-private (test-borrow (amount uint))
404397
(if (or
405398
;; If amount is 0, the STX transfer performed in the borrow operation
406399
;; would fail, resulting in a false negative.
@@ -479,7 +472,7 @@ Seed : 1880056597
479472
480473
Counterexample:
481474
- Test Contract : stx-defi
482-
- Test Function : test-borrow (public)
475+
- Test Function : test-borrow (private)
483476
- Arguments : [1]
484477
- Caller : wallet_8
485478
- Outputs : {"type":{"response":{"ok":"bool","error":{"string-ascii":{"length":33}}}}}
@@ -678,17 +671,17 @@ You can see a complete step-by-step implementation of this tutorial with commit-
678671

679672
Now that you understand the power of Rendezvous, explore:
680673

681-
- **More examples**: Study other smart contracts in the [Examples Chapter](https://stacks-network.github.io/rendezvous/chapter_8.html) of the [Rendezvous Docs](https://stacks-network.github.io/rendezvous/)
674+
- **More examples**: Study other smart contracts in the [Examples Chapter](https://stx-labs.github.io/rendezvous/chapter_8.html) of the [Rendezvous Docs](https://stx-labs.github.io/rendezvous/)
682675
- **Your own contracts**: Apply Rendezvous to your projects and find bugs before they reach production
683676

684677
---
685678

686679
## Get Involved
687680

688-
**Found this tutorial useful?** Star the [Rendezvous repository on GitHub](https://github.com/stacks-network/rendezvous) to show your support!
681+
**Found this tutorial useful?** Star the [Rendezvous repository on GitHub](https://github.com/stx-labs/rendezvous) to show your support!
689682

690683
Have questions, found a bug, or want to contribute? We'd love to hear from you:
691684

692-
- **Open an issue** on [GitHub](https://github.com/stacks-network/rendezvous/issues)
685+
- **Open an issue** on [GitHub](https://github.com/stx-labs/rendezvous/issues)
693686
- **Reach out** with questions or feedback
694687
- **Share your findings** — contribute examples of bugs you've caught to show others how powerful advanced testing techniques can be

docs/build/stacks-devtools-catalog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Official Stacks devtools are built and maintained by either **Stacks Labs** or *
8080

8181
### Testing & Simulation
8282

83-
* [**Rendezvous**](https://stacks-network.github.io/rendezvous/) - A smart contract fuzzer for Clarity.
83+
* [**Rendezvous**](https://stx-labs.github.io/rendezvous/) - A smart contract fuzzer for Clarity.
8484

8585
***
8686

docs/learn/network-fundamentals/audits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For any project, layers of security are crucial. Audits represent one layer, whi
1414
* Bitcoin L2 Labs' [whitehat security program](https://bitcoinl2-labs.github.io/2024/06/04/orange-hats.html)
1515
* Stacks Foundation's partnership with Staking Defense League
1616
* Stacks Founation's ongoing [Immunefi bug bounty program](https://immunefi.com/bug-bounty/stacks/information/)
17-
* Dedicated Stacks Foundation Residents focused exclusively on fuzz and penetration testing (created [Rendezvous](https://stacks-network.github.io/rendezvous/))
17+
* Dedicated Stacks Foundation Residents focused exclusively on fuzz and penetration testing (created [Rendezvous](https://stx-labs.github.io/rendezvous/))
1818

1919
{% hint style="warning" %}
2020
_All 'high' or 'critical' issues listed in audits have either been mitigated or otherwise made obsolete, even if the report states otherwise._

0 commit comments

Comments
 (0)