Skip to content

Commit

Permalink
namespace tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Oct 26, 2023
1 parent 8c6b314 commit 2362939
Show file tree
Hide file tree
Showing 12 changed files with 631 additions and 550 deletions.
120 changes: 120 additions & 0 deletions pact-core-tests/pact-tests/fqns.repl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(env-data {"keyset": { "keys": ["bob"], "pred": "keys-any" }})
(env-keys ["bob"])
(begin-tx)
(define-namespace 'free (read-keyset 'keyset) (read-keyset 'keyset))
(commit-tx)

(begin-tx)
(namespace 'free)
(module modA G
(defcap G () true)
(defun func (x) (+ 1 x))
(defconst test:string "hi")
)
(module modB G
(defcap G () true)
(defun chain () (modA.func 10))
(defconst test:string "hello")
(defun get-test() test)
)

(expect "ns-scoped module call works fully qualified" (free.modB.chain) 11)

(namespace 'free)

(expect "ns-scoped module call works within namespace scope" (modB.chain) 11)

(expect "selects correct test" (modB.get-test) "hello")
(commit-tx)

; works across different txs
(begin-tx)
(namespace 'free)
(module modA G
(defcap G () true)
(defun func (x) (+ 1 x))
(defconst test:string "hi")
)
(commit-tx)
(begin-tx)
(namespace 'free)
(module modB G
(defcap G () true)
(defun chain () (modA.func 10))
(defconst test:string "hello")
(defun get-test() test)
)

(expect "ns-scoped module call works fully qualified" (free.modB.chain) 11)

(namespace 'free)

(expect "ns-scoped module call works within namespace scope" (modB.chain) 11)

(expect "selects correct test" (modB.get-test) "hello")
(commit-tx)

;;
;; Module redeploy name resolution
;;

; In the following tests, we define a module `test-mod-redeploy-ref`, and then
; redeploy the same module with the change to one capability: `test`.
; In the old version, the `test` capability fails, in the new one it passes.

(begin-tx)
; First, demonstrate the behavior prior to pact-4.8.
; (env-exec-config ["DisablePact48"])

(namespace 'free)
(module test-mod-redeploy-ref g
(defcap g () true)

(defcap test ()
(enforce false "boom"))

(defun f ()
(with-capability (test)
1))
)
; Before pact-4.8, the updated capability will be ignored, and calls to a function
; requiring that capability will fail.
(expect-failure "Demonstrate defcap resolution." (f))

(commit-tx)

(begin-tx)
(namespace 'free)
(module test-mod-redeploy-ref g
(defcap g () true)

(defcap test ()
(enforce false "boom"))

(defun f ()
(with-capability (test)
1))
)
(commit-tx)

(begin-tx)
(namespace 'free)
(env-exec-config []) ; reset

(module test-mod-redeploy-ref g
(defcap g () true)
(defcap test ()
true)
(defun f ()
(with-capability (free.test-mod-redeploy-ref.test)
1))

(defun f1 ()
(with-capability (test-mod-redeploy-ref.test)
1))
)
; These tests show that f now references the updated version of the capability.
(expect "Demonstrate correct resolution with fully-qualified reference." 1 (f))
(expect "Demonstrate correct resolution with non-namespace-qualified reference." 1 (f1))

(commit-tx)
Loading

0 comments on commit 2362939

Please sign in to comment.