-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property tests for
sbtc-registry
- Loading branch information
1 parent
a05c010
commit b122bfb
Showing
1 changed file
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,164 @@ | ||
;; Placeholder for property-based tests. | ||
;; Add your test cases here. | ||
|
||
(define-constant deployer tx-sender) | ||
|
||
(define-constant ERR_WRONG_ERROR_CODE (err u1000)) | ||
(define-constant ERR_ASSERTION_FAILED (err u1001)) | ||
|
||
(define-read-only (can-test-is-protocol-caller-ok (caller principal)) | ||
(is-eq deployer caller) | ||
) | ||
|
||
(define-public (test-is-protocol-caller-ok (caller principal)) | ||
(let | ||
( | ||
(is-protocol-caller-result (validate-protocol-caller caller)) | ||
) | ||
(ok (is-ok is-protocol-caller-result)) | ||
) | ||
) | ||
|
||
(define-read-only (can-test-is-protocol-caller-err (caller principal)) | ||
(not (is-eq deployer caller)) | ||
) | ||
|
||
(define-public (test-is-protocol-caller-err (caller principal)) | ||
(let | ||
( | ||
(unwrap-error (err u9999)) | ||
(is-protocol-caller-result (validate-protocol-caller caller)) | ||
) | ||
(ok | ||
(and | ||
(is-err is-protocol-caller-result) | ||
(is-eq | ||
(unwrap-err! is-protocol-caller-result unwrap-error) | ||
u400 | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
(define-read-only (can-test-complete-withdrawal-reject | ||
(request-id uint) | ||
(signer-bitmap uint) | ||
) | ||
(is-eq deployer contract-caller) | ||
) | ||
|
||
(define-public (test-complete-withdrawal-reject | ||
(request-id uint) | ||
(signer-bitmap uint) | ||
) | ||
(ok | ||
(begin | ||
(try! (complete-withdrawal-reject request-id signer-bitmap)) | ||
(asserts! | ||
(is-eq | ||
(unwrap-panic (map-get? withdrawal-status request-id)) | ||
false | ||
) | ||
ERR_ASSERTION_FAILED | ||
) | ||
) | ||
) | ||
) | ||
|
||
(define-read-only (can-test-withdrawal-req-id-incremented | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(is-eq contract-caller deployer) | ||
) | ||
|
||
(define-public (test-withdrawal-req-id-incremented | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(let ( | ||
(last-withdrawal-req-id-before (var-get last-withdrawal-request-id)) | ||
) | ||
(try! (create-withdrawal-request amount max-fee sender recipient height)) | ||
(asserts! | ||
(is-eq | ||
(var-get last-withdrawal-request-id) | ||
(+ last-withdrawal-req-id-before u1) | ||
) | ||
ERR_ASSERTION_FAILED | ||
) | ||
(ok true) | ||
) | ||
) | ||
|
||
(define-read-only (can-test-withdrawal-req-id-non-deployer | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(not (is-eq contract-caller deployer)) | ||
) | ||
|
||
(define-public (test-withdrawal-req-id-non-deployer | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(let ( | ||
(unwrap-error (err u9999)) | ||
(withdrawal-request-result | ||
(create-withdrawal-request amount max-fee sender recipient height) | ||
) | ||
) | ||
(asserts! | ||
(is-eq | ||
(unwrap-err! withdrawal-request-result unwrap-error) | ||
u400 | ||
) | ||
ERR_ASSERTION_FAILED | ||
) | ||
(ok true) | ||
) | ||
) | ||
|
||
(define-read-only (can-test-withdrawal-req-id-not-updated-non-deployer | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(not (is-eq contract-caller deployer)) | ||
) | ||
|
||
(define-public (test-withdrawal-req-id-not-updated-non-deployer | ||
(amount uint) | ||
(max-fee uint) | ||
(sender principal) | ||
(recipient { version: (buff 1), hashbytes: (buff 32) }) | ||
(height uint) | ||
) | ||
(let ( | ||
(last-withdrawal-req-id-before (var-get last-withdrawal-request-id)) | ||
) | ||
(asserts! | ||
(is-eq | ||
(var-get last-withdrawal-request-id) | ||
last-withdrawal-req-id-before | ||
) | ||
ERR_ASSERTION_FAILED | ||
) | ||
(ok true) | ||
) | ||
) |