1
1
(define-constant ERR_FAILED_ASSERTION u999 )
2
2
(define-constant ERR_UNWRAP u998 )
3
3
(define-constant ERR_UNEXPECTED_RESULT u997 )
4
+ (define-constant ERR_IGNORED u996 )
5
+
6
+ (define-constant DEPLOYER tx-sender )
4
7
5
8
(define-data-var last-iteration-claimed uint u0 )
6
9
(define-data-var minted-initial bool false )
7
10
8
- ;; Helper to set up the Rendezvous testing environment. This should be called
9
- ;; by wallet_10, which has 200M STX. It mints the initial 200M STX to the
10
- ;; contract.
11
- (define-public (test-helper-initial-mint )
11
+ ;; General helpers
12
+
13
+ ;; Helper to simulate the initial balance of the SIP-031 contract. This should
14
+ ;; be called by wallet_10, which has 200M STX. It transfers the initial 200M
15
+ ;; STX to the contract.
16
+ (define-private (initial-mint-helper )
12
17
(ok
13
18
(and
14
19
;; Ensure that the caller is wallet_10 as per Devnet.toml. It was added
24
29
;; Helper to transfer extra STX amounts to the contract. In combination with
25
30
;; other tests, this ensures that extra transfers do not break the vesting
26
31
;; schedule.
27
- (define-public ( test-helper- transfer-to-contract (ustx-amount uint ))
32
+ (define-private ( extra- transfer-to-contract-helper (ustx-amount uint ))
28
33
(ok
29
34
(and
30
35
(not (is-eq tx-sender 'ST3FFKYTTB975A3JC3F99MM7TXZJ406R3GKE6JV56 ))
31
36
(> ustx-amount u0 )
32
37
(>= (stx-get-balance tx-sender ) ustx-amount)
33
- (try! (stx-transfer? ustx-amount tx-sender (as-contract tx-sender )))
38
+ (unwrap-panic (stx-transfer? ustx-amount tx-sender (as-contract tx-sender )))
34
39
)
35
40
)
36
41
)
37
42
43
+ ;; Property tests
44
+
45
+ ;; Helper to set up the Rendezvous testing environment for the property testing
46
+ ;; routine. The naming adheres to Rendezvous property test convention, which
47
+ ;; allows this function to be picked up during property testing runs.
48
+ (define-public (test-initial-mint-helper )
49
+ (initial-mint-helper )
50
+ )
51
+
52
+ ;; Helper to transfer extra STX amounts to the contract. The naming adheres to
53
+ ;; Rendezvous property test convention, which allows this function to be picked
54
+ ;; up during property testing runs.
55
+ (define-public (test-extra-transfer-helper (ustx-amount uint ))
56
+ (extra-transfer-to-contract-helper ustx-amount)
57
+ )
58
+
38
59
;; Tests that the recipient is updated if the caller is allowed.
39
60
(define-public (test-update-recipient-allowed (new-recipient principal ))
40
61
(ok
162
183
)
163
184
)
164
185
)
165
- )
186
+ )
187
+
188
+ ;; Invariants
189
+
190
+ ;; Public wrapper for initial mint setup, required for Rendezvous invariant
191
+ ;; testing. Rendezvous randomly calls public functions during invariant testing
192
+ ;; runs, so this exposes the initial mint helper as a public function that can
193
+ ;; be selected and called.
194
+ (define-public (initial-mint-helper-invariant-runs )
195
+ (if
196
+ (is-eq (initial-mint-helper ) (ok true ))
197
+ (ok true )
198
+ (err ERR_IGNORED)
199
+ )
200
+ )
201
+
202
+ ;; Public wrapper for extra STX transfers to the contract for Rendezvous
203
+ ;; invariant testing. Rendezvous randomly calls public functions during
204
+ ;; invariant testing, so this exposes the extra transfer helper as a public
205
+ ;; function that can be selected during test runs.
206
+ (define-public (extra-transfer-helper-invariant-runs (ustx-amount uint ))
207
+ (if
208
+ (is-eq (extra-transfer-to-contract-helper ustx-amount) (ok true ))
209
+ (ok true )
210
+ (err ERR_IGNORED)
211
+ )
212
+ )
213
+
214
+ ;; Tests that the recipient remains unchanged unless `update-recipient` was
215
+ ;; called successfully at least once.
216
+ (define-read-only (invariant-recipient-unchanged )
217
+ (if
218
+ (is-eq
219
+ u0
220
+ (default-to u0 (get called (map-get? context " update-recipient" )))
221
+ )
222
+ (is-eq (var-get recipient ) DEPLOYER)
223
+ true
224
+ )
225
+ )
226
+
227
+ ;; Tests that the amount returned by `calc-total-vested` never exceeds
228
+ ;; the total initial mint amount, regardless of any extra transfers
229
+ ;; to the contract.
230
+ (define-read-only (invariant-vested-lt-initial-mint (burn-height uint ))
231
+ (or
232
+ (<= burn-height DEPLOY_BLOCK_HEIGHT)
233
+ (<=
234
+ (calc-total-vested burn-height)
235
+ ;; We explicitly add up the total initial mint amount rather than using
236
+ ;; `INITIAL_MINT_AMOUNT` directly. This ensures the invariant remains
237
+ ;; valid even if the constants or their relationships change in the main
238
+ ;; contract, making this invariant's feedback more robust.
239
+ (+ INITIAL_MINT_IMMEDIATE_AMOUNT INITIAL_MINT_VESTING_AMOUNT)
240
+ )
241
+ )
242
+ )
0 commit comments