1
1
(define-constant ERR_FAILED_ASSERTION u999 )
2
2
(define-constant ERR_UNWRAP u998 )
3
+ (define-constant ERR_UNEXPECTED_RESULT u997 )
3
4
4
5
(define-data-var minted-initial bool false )
5
6
68
69
)
69
70
)
70
71
)
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
+ )
71
129
)
0 commit comments