Skip to content

Commit 559adb2

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

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(define-constant ERR_FAILED_ASSERTION u999)
2+
(define-constant ERR_UNWRAP u998)
3+
4+
(define-data-var minted-initial bool false)
5+
6+
;; Helper to set up the Rendezvous testing environment. This should be called
7+
;; by wallet_10, which has 200M STX. It mints the initial 200M STX to the
8+
;; contract.
9+
(define-public (test-initial-mint)
10+
(ok
11+
(and
12+
;; Ensure that the caller is wallet_10 as per Devnet.toml. It was added
13+
;; to the devnet with 200M STX for this operation.
14+
(is-eq tx-sender 'ST3FFKYTTB975A3JC3F99MM7TXZJ406R3GKE6JV56)
15+
(not (var-get minted-initial))
16+
(unwrap-panic (stx-transfer? INITIAL_MINT_AMOUNT tx-sender (as-contract tx-sender)))
17+
(var-set minted-initial true)
18+
)
19+
)
20+
)
21+
22+
;; Tests that the recipient is updated if the caller is allowed.
23+
(define-public (test-update-recipient-allowed (new-recipient principal))
24+
(ok
25+
(and
26+
(is-eq (var-get recipient) contract-caller tx-sender)
27+
(try! (update-recipient new-recipient))
28+
(asserts!
29+
(is-eq new-recipient (var-get recipient))
30+
(err ERR_FAILED_ASSERTION)
31+
)
32+
)
33+
)
34+
)
35+
36+
;; Tests that the proper error is returned if the caller is not allowed.
37+
(define-public (test-update-recipient-not-allowed (new-recipient principal))
38+
(ok
39+
(and
40+
(not (is-eq (var-get recipient) contract-caller tx-sender))
41+
(asserts!
42+
(is-eq
43+
(unwrap-err! (update-recipient new-recipient) (err ERR_UNWRAP))
44+
ERR_NOT_ALLOWED
45+
)
46+
(err ERR_FAILED_ASSERTION)
47+
)
48+
)
49+
)
50+
)
51+
52+
;; Tests that the recipient is not updated if the caller is not allowed.
53+
(define-public (test-update-recipient-not-allowed-no-effect
54+
(new-recipient principal)
55+
)
56+
(ok
57+
(let (
58+
(recipient-before (var-get recipient))
59+
(update-recipient-result (update-recipient new-recipient))
60+
)
61+
(and
62+
(not (is-eq recipient-before contract-caller tx-sender))
63+
(not (is-eq recipient-before new-recipient))
64+
(asserts!
65+
(is-eq (var-get recipient) recipient-before)
66+
(err ERR_FAILED_ASSERTION)
67+
)
68+
)
69+
)
70+
)
71+
)

0 commit comments

Comments
 (0)