-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-multi-sig-manager.repl
99 lines (81 loc) · 2.67 KB
/
test-multi-sig-manager.repl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(load "kadena_repl_sandbox/kda-env/init.repl")
(begin-tx)
(namespace 'free)
(load "multi-sig-manager.pact")
(create-table domains)
(create-table transactions)
(create-table approvals)
(commit-tx)
(typecheck "free.multi-sig-manager")
(begin-tx)
(env-data {'k-alice:["alice-key"],
'k-bob:["bob-key"],
'k-carol:["carol-key"]})
(free.multi-sig-manager.add-domain "MY-DOMAIN" (map (read-keyset) ["k-alice","k-bob", "k-carol"]) 2)
(commit-tx)
; Deploy a first SC
(begin-tx)
(load "example_contract_v1.pact")
(commit-tx)
(begin-tx)
(env-hash (hash "First attempt"))
(expect-failure "Transaction not registered" "not registered" (free.multi-sig-manager.enforce-approved "MY-DOMAIN"))
(commit-tx)
; Register the transaction
(begin-tx)
;without sig
(env-sigs [])
(expect-failure "No sig"
(free.multi-sig-manager.propose-transaction "MY-DOMAIN" (hash "Second attempt")))
; with sig ok
(env-sigs [{'key:"alice-key", 'caps:[]}])
(free.multi-sig-manager.propose-transaction "MY-DOMAIN" (hash "Second attempt"))
(commit-tx)
(begin-tx)
(env-sigs [])
(env-hash (hash "Second attempt"))
(expect-failure "Not approved" "Not enough approvals" (free.multi-sig-manager.enforce-approved "MY-DOMAIN"))
(commit-tx)
(begin-tx)
; First approver
(env-data {'k-alice:["alice-key"]})
; without sigs
(env-sigs [])
(expect-failure "No sigs" "Keyset failure"
(free.multi-sig-manager.approve (hash "Second attempt") (read-keyset 'k-alice)))
; with sigs
(env-sigs [{'key:"alice-key", 'caps:[]}])
(free.multi-sig-manager.approve (hash "Second attempt") (read-keyset 'k-alice))
(commit-tx)
(begin-tx)
(env-sigs [])
(env-hash (hash "Second attempt"))
(expect-failure "Not approved" "Not enough approvals" (free.multi-sig-manager.enforce-approved "MY-DOMAIN"))
(commit-tx)
; Try to redeploy with a missing signature
; should not work =>
; but in REPL I can't find how to "expect-failure" a contract deployment
; so uncomment it and verify it fails with Not enough approvals
;==========================================================>
;(begin-tx)
;(env-hash (hash "Second attempt"))
;(load "example_contract_v2.pact")
;(comit-tx)
;==========================================================>
; Second approver
(begin-tx)
(env-data {'k-carol:["carol-key"]})
(env-sigs [{'key:"carol-key", 'caps:[]}])
(free.multi-sig-manager.approve (hash "Second attempt") (read-keyset 'k-carol))
(commit-tx)
; Now it should be ok
(begin-tx)
(env-sigs [])
(env-hash (hash "Second attempt"))
(expect "Approved" true (free.multi-sig-manager.enforce-approved "MY-DOMAIN"))
(rollback-tx)
; Try to redeploy the contract => Should work
(begin-tx)
(env-hash (hash "Second attempt"))
(load "example_contract_v2.pact")
(commit-tx)