Skip to content

Commit

Permalink
Add property tests for sbtc-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
BowTiedRadone committed Nov 19, 2024
1 parent a05c010 commit b122bfb
Showing 1 changed file with 162 additions and 0 deletions.
162 changes: 162 additions & 0 deletions contracts/contracts/sbtc-registry.tests.clar
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)
)
)

0 comments on commit b122bfb

Please sign in to comment.