Skip to content

Commit c311433

Browse files
BowTiedRadonemoodmosaic
authored andcommitted
Add rendezvous property test for SIP-031's claimable balance per iteration
1 parent 4c999b2 commit c311433

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

stackslib/src/chainstate/stacks/boot/sip-031.tests.clar

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(define-constant ERR_UNWRAP u998)
33
(define-constant ERR_UNEXPECTED_RESULT u997)
44

5+
(define-data-var last-iteration-claimed uint u0)
56
(define-data-var minted-initial bool false)
67

78
;; Helper to set up the Rendezvous testing environment. This should be called
@@ -20,6 +21,20 @@
2021
)
2122
)
2223

24+
;; Helper to transfer extra STX amounts to the contract. In combination with
25+
;; other tests, this ensures that extra transfers do not break the vesting
26+
;; schedule.
27+
(define-public (test-helper-transfer-to-contract (ustx-amount uint))
28+
(ok
29+
(and
30+
(not (is-eq tx-sender 'ST3FFKYTTB975A3JC3F99MM7TXZJ406R3GKE6JV56))
31+
(> ustx-amount u0)
32+
(>= (stx-get-balance tx-sender) ustx-amount)
33+
(try! (stx-transfer? ustx-amount tx-sender (as-contract tx-sender)))
34+
)
35+
)
36+
)
37+
2338
;; Tests that the recipient is updated if the caller is allowed.
2439
(define-public (test-update-recipient-allowed (new-recipient principal))
2540
(ok
@@ -111,6 +126,7 @@
111126
(let (
112127
(recipient-balance-before (stx-get-balance (var-get recipient)))
113128
(claimable (calc-claimable-amount burn-block-height))
129+
(current-iteration (/ (- burn-block-height DEPLOY_BLOCK_HEIGHT) INITIAL_MINT_VESTING_ITERATION_BLOCKS))
114130
)
115131
(and
116132
(is-eq (var-get recipient) contract-caller tx-sender)
@@ -123,6 +139,26 @@
123139
)
124140
(err ERR_FAILED_ASSERTION)
125141
)
142+
(var-set last-iteration-claimed current-iteration)
143+
)
144+
)
145+
)
146+
)
147+
148+
;; Tests that the claimable amount is greater than the STX per iteration if the
149+
;; last iteration claimed is less than the current iteration.
150+
(define-public (test-claimable-amount-gt-iteration-stx)
151+
(ok
152+
(let (
153+
(recipient-balance-before (stx-get-balance (var-get recipient)))
154+
(claimable (calc-claimable-amount burn-block-height))
155+
(current-iteration (/ (- burn-block-height DEPLOY_BLOCK_HEIGHT) INITIAL_MINT_VESTING_ITERATION_BLOCKS))
156+
)
157+
(and
158+
(is-eq (var-get recipient) contract-caller tx-sender)
159+
(> claimable u0)
160+
(> current-iteration (var-get last-iteration-claimed))
161+
(asserts! (>= claimable STX_PER_ITERATION) (err claimable))
126162
)
127163
)
128164
)

0 commit comments

Comments
 (0)