You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/build/get-started/developer-quickstart.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -477,7 +477,7 @@ Now with the actual writing of your contract complete, we now need to test its f
477
477
478
478
* Contract interaction in the [Clarinet REPL](../clarinet/contract-interaction.md)
479
479
* 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/)
481
481
* Writing unit tests with the [Clarinet JS SDK](../clarinet/testing-with-clarinet-sdk.md)
482
482
483
483
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.
Copy file name to clipboardExpand all lines: docs/build/rendezvous/overview.md
+23-14Lines changed: 23 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,10 +28,11 @@ A property is a universal truth about your smart contract's state, functions, et
28
28
29
29
**How to extract a property?**
30
30
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):
@@ -48,10 +49,11 @@ Say that your smart contract has a function that reverses a list of `uint`s. In
48
49
49
50
**Making your property valid for Rendezvous**
50
51
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:
52
53
>
54
+
> * Function lives in the contract file, annotated with `;; #[env(simnet)]`
53
55
> * Function name starts with `test-`
54
-
> * Function is declared as `public`
56
+
> * Function is declared as `private`
55
57
> * Test passes when it returns `(ok true)`
56
58
> * Test would be discarded if it returned `(ok false)`
57
59
> * 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.
68
70
69
71
**How to extract an invariant?**
70
72
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:
72
74
73
75
```clarity
76
+
;; #[env(simnet)]
74
77
(define-read-only (invariant-counter-gt-zero)
75
78
(let
76
79
(
@@ -92,12 +95,17 @@ Say that you have a counter contract, having functions to `increment` and `decre
92
95
93
96
**Making your invariant valid for Rendezvous**
94
97
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:
96
99
>
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`
99
103
> * 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 %}
101
109
102
110
## Why Test in Clarity?
103
111
@@ -129,14 +137,13 @@ Running tests in Clarity reduces the number of external tools and integrations y
129
137
130
138
## Getting Started
131
139
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.
133
141
134
142
```
135
143
my-project/
136
144
├── Clarinet.toml
137
145
├── contracts/
138
-
│ ├── my-contract.clar # Contract
139
-
│ ├── my-contract.tests.clar # Tests
146
+
│ └── my-contract.clar # Contract + its #[env(simnet)] tests
140
147
└── settings/
141
148
└── Devnet.toml
142
149
```
@@ -155,5 +162,7 @@ This will add Rendezvous to your project's `node_modules` and update your `packa
Copy file name to clipboardExpand all lines: docs/build/rendezvous/quickstart.md
+18-25Lines changed: 18 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,21 +246,13 @@ The main functions and state of the contract are now covered by tests. Line cove
246
246
247
247
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.
248
248
249
-
### Create the Test File
250
-
251
-
Create the Rendezvous test file:
252
-
253
-
```bash
254
-
touch contracts/stx-defi.tests.clar
255
-
```
256
-
257
249
### Add an Ice-Breaker Test
258
250
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`:
261
252
262
253
```clarity
263
-
(define-public (test-always-true)
254
+
;; #[env(simnet)]
255
+
(define-private (test-always-true)
264
256
(ok true)
265
257
)
266
258
```
@@ -316,15 +308,14 @@ If you see similar output, your setup works. You're ready to write a **real prop
316
308
317
309
### Define a Borrowing Property
318
310
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`:
320
312
321
313
```clarity
322
-
;; stx-defi.tests.clar
323
-
314
+
;; #[env(simnet)]
324
315
;; Property: Borrowing should always update the loan amount correctly.
325
316
;; The new loan amount should equal the old loan amount plus the borrowed
326
317
;; amount.
327
-
(define-public (test-borrow (amount uint))
318
+
(define-private (test-borrow (amount uint))
328
319
(let (
329
320
;; Record the loan amount before performing any action that would end up
330
321
;; 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**:
353
344
354
345
Rendezvous:
355
346
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.
358
349
3. Generates a random sequence to call each test.
359
350
4. Produces random argument values for each function parameter.
360
351
5. Randomly selects senders from settings/Devnet.toml.
@@ -378,13 +369,14 @@ Let's address them one by one.
378
369
379
370
### Handle Preconditions
380
371
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`:
382
373
383
374
```clarity
375
+
;; #[env(simnet)]
384
376
;; This is a helper function that will eventually be picked up during
385
377
;; property-based-testing runs. It allows creating deposits in the smart
386
378
;; contract so other tests can check properties requiring a deposit.
;; Call the deposit function and ignore the result.
390
382
(deposit-result (deposit amount))
@@ -394,13 +386,14 @@ Let's address them one by one.
394
386
)
395
387
```
396
388
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:
398
390
399
391
```clarity
392
+
;; #[env(simnet)]
400
393
;; Property: Borrowing should always update the loan amount correctly.
401
394
;; The new loan amount should equal the old loan amount plus the borrowed
402
395
;; amount.
403
-
(define-public (test-borrow (amount uint))
396
+
(define-private (test-borrow (amount uint))
404
397
(if (or
405
398
;; If amount is 0, the STX transfer performed in the borrow operation
@@ -678,17 +671,17 @@ You can see a complete step-by-step implementation of this tutorial with commit-
678
671
679
672
Now that you understand the power of Rendezvous, explore:
680
673
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/)
682
675
-**Your own contracts**: Apply Rendezvous to your projects and find bugs before they reach production
683
676
684
677
---
685
678
686
679
## Get Involved
687
680
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!
689
682
690
683
Have questions, found a bug, or want to contribute? We'd love to hear from you:
691
684
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)
693
686
-**Reach out** with questions or feedback
694
687
-**Share your findings** — contribute examples of bugs you've caught to show others how powerful advanced testing techniques can be
* 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/))
18
18
19
19
{% hint style="warning" %}
20
20
_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