Skip to content

Commit 1a6cc3c

Browse files
BowTiedRadonemoodmosaic
authored andcommitted
Add rendezvous property tests for SIP-031's claim
1 parent 559adb2 commit 1a6cc3c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(define-constant ERR_FAILED_ASSERTION u999)
22
(define-constant ERR_UNWRAP u998)
3+
(define-constant ERR_UNEXPECTED_RESULT u997)
34

45
(define-data-var minted-initial bool false)
56

@@ -68,4 +69,61 @@
6869
)
6970
)
7071
)
72+
)
73+
74+
;; Tests that the proper error is returned if the caller is not allowed.
75+
(define-public (test-claim-not-allowed)
76+
(ok
77+
(and
78+
(not (is-eq (var-get recipient) contract-caller tx-sender))
79+
(asserts!
80+
(is-eq
81+
(unwrap-err! (claim) (err ERR_UNWRAP))
82+
ERR_NOT_ALLOWED
83+
)
84+
(err ERR_FAILED_ASSERTION)
85+
)
86+
)
87+
)
88+
)
89+
90+
;; Tests that the proper error is returned if there is nothing to claim.
91+
(define-public (test-claim-nothing-to-claim)
92+
(ok
93+
(and
94+
(is-eq (var-get recipient) contract-caller tx-sender)
95+
(is-eq (calc-claimable-amount burn-block-height) u0)
96+
(asserts!
97+
(is-eq
98+
(unwrap-err! (claim) (err ERR_UNWRAP))
99+
ERR_NOTHING_TO_CLAIM
100+
)
101+
(err ERR_FAILED_ASSERTION)
102+
)
103+
)
104+
)
105+
)
106+
107+
;; Tests that the claim is successful if the caller is allowed, and the
108+
;; recipient balance increases by the claimable amount.
109+
(define-public (test-claim-allowed)
110+
(ok
111+
(let (
112+
(recipient-balance-before (stx-get-balance (var-get recipient)))
113+
(claimable (calc-claimable-amount burn-block-height))
114+
)
115+
(and
116+
(is-eq (var-get recipient) contract-caller tx-sender)
117+
(> claimable u0)
118+
(asserts! (is-ok (claim)) (err ERR_UNEXPECTED_RESULT))
119+
(asserts!
120+
(is-eq
121+
(stx-get-balance (var-get recipient))
122+
(+ recipient-balance-before claimable)
123+
)
124+
(err ERR_FAILED_ASSERTION)
125+
)
126+
)
127+
)
128+
)
71129
)

0 commit comments

Comments
 (0)