Skip to content

Commit

Permalink
All principals tests pass now
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd34df00d committed Nov 15, 2023
1 parent 1c8122e commit b9c13e7
Showing 1 changed file with 172 additions and 174 deletions.
346 changes: 172 additions & 174 deletions pact-core-tests/pact-tests/principals.repl
Original file line number Diff line number Diff line change
Expand Up @@ -386,63 +386,63 @@
""
(typeof-principal "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQD"))

; ;; p: guard validation
;
; (expect
; "creating principal pact guards creates p: guards with correct format"
; "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:pact-guard"
; (test-ns.tester.pact-test))
;
; (expect
; "validating principal pact guards roundtrips with create-principal"
; true
; (continue-pact 1))
;
; ;; clear env
; (pact-state true)
;
; (expect
; "is-principal returns true for p: guards"
; true
; (is-principal (test-ns.tester.pact-test)))
;
; (expect
; "is-principal should be false for improper p: guards - empty hash"
; false
; (is-principal "p::pact-guard"))
;
; (expect
; "is-principal should be false for improper p: guards - empty name"
; false
; (is-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:"))
;
; ;; clear env
; (pact-state true)
;
; (expect
; "typeof-principal should return p: for pact guards"
; "p:"
; (typeof-principal (test-ns.tester.pact-test)))
;
; (expect
; "typeof-principal should fail for p: accounts: empty fqn"
; ""
; (typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:"))
;
; (expect
; "typeof-principal should fail for p: accounts: empty hash"
; ""
; (typeof-principal "p::pact-guard"))
;
; (expect
; "typeof-principal should fail for p: accounts: hash too big"
; ""
; (typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46gg:pact-guard"))
;
; (expect
; "typeof-principal should fail for p: accounts: hash too small"
; ""
; (typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46:pact-guard"))
;; p: guard validation

(expect
"creating principal pact guards creates p: guards with correct format"
"p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:pact-guard"
(test-ns.tester.pact-test))

(expect
"validating principal pact guards roundtrips with create-principal"
true
(continue-pact 1))

;; clear env
(pact-state true)

(expect
"is-principal returns true for p: guards"
true
(is-principal (test-ns.tester.pact-test)))

(expect
"is-principal should be false for improper p: guards - empty hash"
false
(is-principal "p::pact-guard"))

(expect
"is-principal should be false for improper p: guards - empty name"
false
(is-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:"))

;; clear env
(pact-state true)

(expect
"typeof-principal should return p: for pact guards"
"p:"
(typeof-principal (test-ns.tester.pact-test)))

(expect
"typeof-principal should fail for p: accounts: empty fqn"
""
(typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:"))

(expect
"typeof-principal should fail for p: accounts: empty hash"
""
(typeof-principal "p::pact-guard"))

(expect
"typeof-principal should fail for p: accounts: hash too big"
""
(typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46gg:pact-guard"))

(expect
"typeof-principal should fail for p: accounts: hash too small"
""
(typeof-principal "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46:pact-guard"))

(commit-tx)
(begin-tx)
Expand All @@ -463,139 +463,137 @@
, "keys3"
])

; TODO create-pact-guard
; (module tester G
; (defcap G ()
; true)
;
; (defschema test-schema
; "test schema"
; guard:string)
;
; (deftable test-table:{test-schema})
;
; (defun f:string ()
; (insert test-table "admin"
; { "guard":
; (create-principal (create-module-guard 'tester))
; }))
;
; (defun g ()
; (at 'guard (read test-table "admin")))
;
; (defun both-guard (ks1 ks2)
; (enforce-keyset ks1)
; (enforce-keyset ks2))
;
; (defun h ()
; (insert test-table "user"
; { "guard":
; (create-principal
; (create-user-guard
; (both-guard
; (read-keyset 'ks1)
; (read-keyset 'ks2)
; )))
; }))
;
; (defun j ()
; (at 'guard (read test-table "user")))
;
; (defun k ()
; (validate-principal
; (create-user-guard
; (both-guard
; (read-keyset 'ks1)
; (read-keyset 'ks2)))
; (create-principal
; (create-user-guard
; (both-guard
; (read-keyset 'ks1)
; (read-keyset 'ks2))))
; ))
;
; (defpact pact-test ()
; (step
; (let*
; ((guard
; (create-principal
; (create-pact-guard "pact-guard"))))
;
; (update test-table "user"
; { "guard": guard
; })
;
; guard
; ))
;
; (step
; (validate-principal
; (create-pact-guard "pact-guard")
; (at 'guard (read test-table "user"))
; )))
; )
;
; (module tester2 G
; (defcap G ()
; true)
;
; (defun f:string ()
; (create-principal (create-module-guard 'tester)))
;
; (defun g:bool ()
; (validate-principal
; (create-module-guard 'tester)
; (create-principal (create-module-guard 'tester))))
; )
;
; (create-table tester.test-table)
; (tester.f)
; (tester.h)
(module tester G
(defcap G ()
true)

(defschema test-schema
"test schema"
guard:string)

(deftable test-table:{test-schema})

(defun f:string ()
(insert test-table "admin"
{ "guard":
(create-principal (create-module-guard 'tester))
}))

(defun g ()
(at 'guard (read test-table "admin")))

(defun both-guard (ks1 ks2)
(enforce-keyset ks1)
(enforce-keyset ks2))

(defun h ()
(insert test-table "user"
{ "guard":
(create-principal
(create-user-guard
(both-guard
(read-keyset 'ks1)
(read-keyset 'ks2)
)))
}))

(defun j ()
(at 'guard (read test-table "user")))

(defun k ()
(validate-principal
(create-user-guard
(both-guard
(read-keyset 'ks1)
(read-keyset 'ks2)))
(create-principal
(create-user-guard
(both-guard
(read-keyset 'ks1)
(read-keyset 'ks2))))
))

(defpact pact-test ()
(step
(let*
((guard
(create-principal
(create-pact-guard "pact-guard"))))

(update test-table "user"
{ "guard": guard
})

guard
))

(step
(validate-principal
(create-pact-guard "pact-guard")
(at 'guard (read test-table "user"))
)))
)

(module tester2 G
(defcap G ()
true)

(defun f:string ()
(create-principal (create-module-guard 'tester)))

(defun g:bool ()
(validate-principal
(create-module-guard 'tester)
(create-principal (create-module-guard 'tester))))
)

(create-table tester.test-table)
(tester.f)
(tester.h)

(commit-tx)
(begin-tx)

;; m: guard validation

; TODO
; (expect
; "creating principals for autonomous module guards creates m: guards with same name"
; "m:tester:tester"
; (tester.g))
(expect
"creating principals for autonomous module guards creates m: guards with same name"
"m:tester:tester"
(tester.g))

; (expect
; "creating principal module guards for other modules creates m: guards that show provenance"
; "m:tester2:tester"
; (tester2.f))
(expect
"creating principal module guards for other modules creates m: guards that show provenance"
"m:tester2:tester"
(tester2.f))

; (expect
; "validating principal module guards roundtrips with create-principal"
; true
; (tester2.g))
(expect
"validating principal module guards roundtrips with create-principal"
true
(tester2.g))

;; u: guard validation

; (expect
; "creating principal user guards creates u: guards with correct format"
; "u:tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI"
; (tester.j))
(expect
"creating principal user guards creates u: guards with correct format"
"u:tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI"
(tester.j))


; (expect
; "validating principal user guards roundtrips with create-principal"
; true
; (tester.k))
(expect
"validating principal user guards roundtrips with create-principal"
true
(tester.k))

;; p: guard validation

; (expect
; "creating principal pact guards creates p: guards with correct format"
; "p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:pact-guard"
; (tester.pact-test))
(expect
"creating principal pact guards creates p: guards with correct format"
"p:DldRwCblQ7Loqy6wYJnaodHl30d3j3eH-qtFzfEv46g:pact-guard"
(tester.pact-test))

; (expect
; "validating principal pact guards roundtrips with create-principal"
; true
; (continue-pact 1))
(expect
"validating principal pact guards roundtrips with create-principal"
true
(continue-pact 1))

(commit-tx)

0 comments on commit b9c13e7

Please sign in to comment.