From 9155d43f0cdfee553859539543f23cfe34b3d4a9 Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Mon, 13 Nov 2023 11:53:22 -0600 Subject: [PATCH] Enable a part of principals tests that work thanks to having ns now! --- pact-core-tests/pact-tests/principals.repl | 448 ++++++++++----------- 1 file changed, 223 insertions(+), 225 deletions(-) diff --git a/pact-core-tests/pact-tests/principals.repl b/pact-core-tests/pact-tests/principals.repl index 376edbc82..28d52faf4 100644 --- a/pact-core-tests/pact-tests/principals.repl +++ b/pact-core-tests/pact-tests/principals.repl @@ -126,53 +126,52 @@ }) (env-keys ['k]) -; TODO namespaces -; (define-namespace 'ns (read-keyset 'ks3) (read-keyset 'ks3)) -; (namespace 'ns) -; (define-keyset "ns.ks3") -; -; (expect -; "creating principals using keyset references creates r: guards" -; "r:ns.ks3" -; (create-principal (keyset-ref-guard "ns.ks3"))) -; -; (expect -; "validating principals using created principal keyset refs passes" -; true -; (validate-principal -; (keyset-ref-guard "ns.ks3") -; "r:ns.ks3" -; )) -; -; (expect -; "validating principal keyset refs roundtrips for all created principals" -; true -; (validate-principal -; (keyset-ref-guard "ns.ks3") -; (create-principal (keyset-ref-guard "ns.ks3")) -; )) -; -; (expect -; "is-principal returns true for r: guards" -; true -; (is-principal (create-principal (keyset-ref-guard "ns.ks3"))) -; ) -; -; (expect -; "is-principal should be false for improper r: guards" -; false -; (is-principal "r:")) -; -; (expect -; "typeof-principal should return r: for r guards" -; "r:" -; (typeof-principal (create-principal (keyset-ref-guard "ns.ks3")))) -; -; (expect -; "typeof-principal should fail for r: guards: improper keylength - empty" -; "" -; (typeof-principal "r:")) -; +(define-namespace 'ns (read-keyset 'ks3) (read-keyset 'ks3)) +(namespace 'ns) +(define-keyset "ns.ks3") + +(expect + "creating principals using keyset references creates r: guards" + "r:ns.ks3" + (create-principal (keyset-ref-guard "ns.ks3"))) + +(expect + "validating principals using created principal keyset refs passes" + true + (validate-principal + (keyset-ref-guard "ns.ks3") + "r:ns.ks3" + )) + +(expect + "validating principal keyset refs roundtrips for all created principals" + true + (validate-principal + (keyset-ref-guard "ns.ks3") + (create-principal (keyset-ref-guard "ns.ks3")) + )) + +(expect + "is-principal returns true for r: guards" + true + (is-principal (create-principal (keyset-ref-guard "ns.ks3"))) + ) + +(expect + "is-principal should be false for improper r: guards" + false + (is-principal "r:")) + +(expect + "typeof-principal should return r: for r guards" + "r:" + (typeof-principal (create-principal (keyset-ref-guard "ns.ks3")))) + +(expect + "typeof-principal should fail for r: guards: improper keylength - empty" + "" + (typeof-principal "r:")) + (commit-tx) (begin-tx) @@ -192,60 +191,59 @@ , "keys3" ]) -; TODO namespaces -; (define-namespace 'test-ns (read-keyset 'ks1) (read-keyset 'ks1)) -; (namespace 'test-ns) -; -; (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)))) -; )) -; +(define-namespace 'test-ns (read-keyset 'ks1) (read-keyset 'ks1)) +(namespace 'test-ns) + +(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* @@ -265,131 +263,131 @@ ; (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 -; -; (expect -; "creating principals for autonomous module guards creates m: guards with same name" -; "m:test-ns.tester:tester" -; (test-ns.tester.g)) -; -; (expect -; "creating principal module guards for other modules creates m: guards that show provenance" -; "m:test-ns.tester2:tester" -; (test-ns.tester2.f)) -; -; (expect -; "validating principal module guards roundtrips with create-principal" -; true -; (test-ns.tester2.g)) -; -; (expect -; "is-principal returns true for m: guards" -; true -; (is-principal (test-ns.tester.g))) -; -; (expect -; "is-principal should be false for improper m: guards - empty module name" -; false -; (is-principal "m::tester")) -; -; (expect -; "is-principal should be false for improper m: guards - empty func name" -; false -; (is-principal "m:test-ns.tester:")) -; -; (expect -; "typeof-principal should return m: for m guards" -; "m:" -; (typeof-principal (test-ns.tester.g))) -; -; (expect -; "typeof-principal should fail for m: accounts: empty module name" -; "" -; (typeof-principal "m::tester")) -; -; (expect -; "typeof-principal should fail for m: accounts: empty func name" -; "" -; (typeof-principal "m:test-ns.tester:")) -; -; -; ;; u: guard validation -; -; (expect -; "creating principal user guards creates u: guards with correct format" -; "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI" -; (test-ns.tester.j)) -; -; -; (expect -; "validating principal user guards roundtrips with create-principal" -; true -; (test-ns.tester.k)) -; -; (expect -; "is-principal returns true for u: guards" -; true -; (is-principal (test-ns.tester.j))) -; -; (expect -; "is-principal should be false for improper u: guards - empty fqn" -; false -; (is-principal "u::tester")) -; -; (expect -; "is-principal should be false for improper u: guards - empty hash" -; false -; (is-principal "u:test-ns.tester.both-guard:")) -; -; (expect -; "typeof-principal should return u: for u guards" -; "u:" -; (typeof-principal (test-ns.tester.j))) -; -; (expect -; "typeof-principal should fail for u: accounts: empty fqn" -; "" -; (typeof-principal "u::aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI")) -; -; (expect -; "typeof-principal should fail for u: accounts: empty hash" -; "" -; (typeof-principal "u:test-ns.tester.both-guard:")) -; -; (expect -; "typeof-principal should fail for u: accounts: hash too big" -; "" -; (typeof-principal "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDIs")) -; -; (expect -; "typeof-principal should fail for u: accounts: hash too small" -; "" -; (typeof-principal "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQD")) -; +) + +(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 + +(expect + "creating principals for autonomous module guards creates m: guards with same name" + "m:test-ns.tester:tester" + (test-ns.tester.g)) + +(expect + "creating principal module guards for other modules creates m: guards that show provenance" + "m:test-ns.tester2:tester" + (test-ns.tester2.f)) + +(expect + "validating principal module guards roundtrips with create-principal" + true + (test-ns.tester2.g)) + +(expect + "is-principal returns true for m: guards" + true + (is-principal (test-ns.tester.g))) + +(expect + "is-principal should be false for improper m: guards - empty module name" + false + (is-principal "m::tester")) + +(expect + "is-principal should be false for improper m: guards - empty func name" + false + (is-principal "m:test-ns.tester:")) + +(expect + "typeof-principal should return m: for m guards" + "m:" + (typeof-principal (test-ns.tester.g))) + +(expect + "typeof-principal should fail for m: accounts: empty module name" + "" + (typeof-principal "m::tester")) + +(expect + "typeof-principal should fail for m: accounts: empty func name" + "" + (typeof-principal "m:test-ns.tester:")) + + +;; u: guard validation + +(expect + "creating principal user guards creates u: guards with correct format" + "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI" + (test-ns.tester.j)) + + +(expect + "validating principal user guards roundtrips with create-principal" + true + (test-ns.tester.k)) + +(expect + "is-principal returns true for u: guards" + true + (is-principal (test-ns.tester.j))) + +(expect + "is-principal should be false for improper u: guards - empty fqn" + false + (is-principal "u::tester")) + +(expect + "is-principal should be false for improper u: guards - empty hash" + false + (is-principal "u:test-ns.tester.both-guard:")) + +(expect + "typeof-principal should return u: for u guards" + "u:" + (typeof-principal (test-ns.tester.j))) + +(expect + "typeof-principal should fail for u: accounts: empty fqn" + "" + (typeof-principal "u::aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDI")) + +(expect + "typeof-principal should fail for u: accounts: empty hash" + "" + (typeof-principal "u:test-ns.tester.both-guard:")) + +(expect + "typeof-principal should fail for u: accounts: hash too big" + "" + (typeof-principal "u:test-ns.tester.both-guard:aqukm-5Jj6ITLeQfhNYydmtDccinqdJylD9CMlLKQDIs")) + +(expect + "typeof-principal should fail for u: accounts: hash too small" + "" + (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"