From fab68d119f49bd6b7ed5c550c7915cfa7b1bcded Mon Sep 17 00:00:00 2001 From: ggobugi27 Date: Thu, 16 May 2024 19:25:06 +0900 Subject: [PATCH] add non-updatable-uri-policy into util-v1 --- .../non-fungible-policy-v1.repl | 2 + .../non-updatable-uri-policy-v1.repl | 37 +++++++++ pact/marmalade-util/util-v1.pact | 82 ++++++++++++++++--- pact/marmalade-util/util-v1.repl | 13 ++- pact/policy-manager/manager-init.pact | 2 +- 5 files changed, 118 insertions(+), 18 deletions(-) diff --git a/pact/concrete-policies/non-fungible-policy/non-fungible-policy-v1.repl b/pact/concrete-policies/non-fungible-policy/non-fungible-policy-v1.repl index 051f4c00..ac9d8c02 100644 --- a/pact/concrete-policies/non-fungible-policy/non-fungible-policy-v1.repl +++ b/pact/concrete-policies/non-fungible-policy/non-fungible-policy-v1.repl @@ -15,6 +15,7 @@ ,'royalty-policy: false ,'collection-policy:false ,'guard-policy: true + ,'non-updatable-uri-policy: false } ) ) @@ -67,6 +68,7 @@ [ {"name": "marmalade-v2.guard-policy-v1.GUARDS","params": [(read-msg 'token-id) {"burn-guard": GUARD_SUCCESS,"mint-guard": GUARD_SUCCESS,"sale-guard": GUARD_SUCCESS,"transfer-guard": GUARD_SUCCESS, "uri-guard": GUARD_SUCCESS}]} {"name": "marmalade-v2.ledger.TOKEN","params": [(read-msg 'token-id) 0 [marmalade-v2.non-fungible-policy-v1 marmalade-v2.guard-policy-v1] "test-non-fungible-uri" ALWAYS-TRUE]}] (map (remove "module-hash") (env-events true))) + (commit-tx) (begin-tx "Mint with a supply other then 1 fails ") diff --git a/pact/concrete-policies/non-updatable-uri-policy/non-updatable-uri-policy-v1.repl b/pact/concrete-policies/non-updatable-uri-policy/non-updatable-uri-policy-v1.repl index e4d6965d..543b3282 100644 --- a/pact/concrete-policies/non-updatable-uri-policy/non-updatable-uri-policy-v1.repl +++ b/pact/concrete-policies/non-updatable-uri-policy/non-updatable-uri-policy-v1.repl @@ -1,3 +1,40 @@ ;;load policy manager, ledger (load "../../policy-manager/policy-manager.repl") (typecheck "marmalade-v2.non-updatable-uri-policy-v1") + +(begin-tx "Create a non-updatable-uri token") + (use marmalade-v2.ledger) + (use marmalade-v2.util-v1) + (use marmalade-v2.guard-policy-v1) + (use marmalade-v2.util-v1 [DEFAULT_NON_UPDATABLE]) + (use mini-guard-utils) + + (env-data { + "token-id": (create-token-id { 'uri: "test-non-updatable-uri", 'precision: 0, 'policies: (create-policies DEFAULT_NON_UPDATABLE) } ALWAYS-TRUE) + ,"account": "k:e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3" + }) + + (expect "Create token with non-updatable-uri-policy" + true + (create-token (read-msg "token-id") 0 "test-non-updatable-uri" (create-policies DEFAULT_NON_UPDATABLE) ALWAYS-TRUE)) + + (expect "create-token events" + [ {"name": "marmalade-v2.guard-policy-v1.GUARDS","params": [(read-msg 'token-id) {"burn-guard": GUARD_SUCCESS,"mint-guard": GUARD_SUCCESS,"sale-guard": GUARD_SUCCESS,"transfer-guard": GUARD_SUCCESS, "uri-guard": GUARD_SUCCESS}]} + {"name": "marmalade-v2.ledger.TOKEN","params": [(read-msg 'token-id) 0 [marmalade-v2.non-fungible-policy-v1 marmalade-v2.guard-policy-v1 marmalade-v2.non-updatable-uri-policy-v1] "test-non-updatable-uri" ALWAYS-TRUE]}] + (map (remove "module-hash") (env-events true))) + +(commit-tx) + +(begin-tx "Update URI fails") + + (use marmalade-v2.ledger) + (env-sigs [ + { 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3 + ,'caps: [(marmalade-v2.ledger.UPDATE-URI (read-msg 'token-id ) "new-updatable-uri") ] + }]) + + (expect-failure "update-uri fails" + "Update URI Prohibited" + (update-uri (read-msg "token-id") "new-updatable-uri") ) + +(commit-tx) diff --git a/pact/marmalade-util/util-v1.pact b/pact/marmalade-util/util-v1.pact index aac0435b..08e439fa 100644 --- a/pact/marmalade-util/util-v1.pact +++ b/pact/marmalade-util/util-v1.pact @@ -21,6 +21,7 @@ royalty-policy:bool collection-policy:bool guard-policy:bool + non-updatable-uri-policy:bool ) (defconst DEFAULT:object{concrete-policy-bool} @@ -28,13 +29,32 @@ ,'royalty-policy: false ,'collection-policy:false ,'guard-policy: true - }) + ,'non-updatable-uri-policy: false + }) + + (defconst DEFAULT_NON_UPDATABLE:object{concrete-policy-bool} + { 'non-fungible-policy: true + ,'royalty-policy: false + ,'collection-policy:false + ,'guard-policy: true + ,'non-updatable-uri-policy: true + }) (defconst DEFAULT_ROYALTY:object{concrete-policy-bool} { 'non-fungible-policy: true ,'royalty-policy: true ,'collection-policy:false ,'guard-policy: true + ,'non-updatable-uri-policy: false + } + ) + + (defconst DEFAULT_ROYALTY_NON_UPDATABLE:object{concrete-policy-bool} + { 'non-fungible-policy: true + ,'royalty-policy: true + ,'collection-policy:false + ,'guard-policy: true + ,'non-updatable-uri-policy: true } ) @@ -43,6 +63,16 @@ ,'royalty-policy: false ,'collection-policy: true ,'guard-policy: true + ,'non-updatable-uri-policy: false + } + ) + + (defconst DEFAULT_COLLECTION_NON_UPDATABLE:object{concrete-policy-bool} + { 'non-fungible-policy: true + ,'royalty-policy: false + ,'collection-policy: true + ,'guard-policy: true + ,'non-updatable-uri-policy: true } ) @@ -51,6 +81,16 @@ ,'royalty-policy: true ,'collection-policy: true ,'guard-policy: true + ,'non-updatable-uri-policy: false + } + ) + + (defconst DEFAULT_COLLECTION_ROYALTY_NON_UPDATABLE:object{concrete-policy-bool} + { 'non-fungible-policy: true + ,'royalty-policy: true + ,'collection-policy: true + ,'guard-policy: true + ,'non-updatable-uri-policy: true } ) @@ -59,6 +99,7 @@ ,'royalty-policy: false ,'collection-policy:false ,'guard-policy: false + ,'non-updatable-uri-policy: false } ) @@ -73,6 +114,7 @@ ,'royalty-policy: (contains (get-concrete-policy ROYALTY_POLICY) policies) ,'collection-policy: (contains (get-concrete-policy COLLECTION_POLICY) policies) ,'guard-policy: (contains (get-concrete-policy GUARD_POLICY) policies) + ,'non-updatable-uri-policy: (contains (get-concrete-policy NON_UPDATABLE_URI_POLICY) policies) } ) @@ -111,8 +153,11 @@ ) (defun mint-basic-NFT (uri:string guard:guard) - @doc "Mints a NON-FUNGIBLE-TOKEN without any configuration" - (mint-NFT uri [(get-concrete-policy NON_FUNGIBLE_POLICY)] guard) + @doc "Mints a NON-FUNGIBLE-TOKEN without any configuration and upatability of URI" + (mint-NFT uri [ + (get-concrete-policy NON_FUNGIBLE_POLICY) + (get-concrete-policy NON_UPDATABLE_URI_POLICY) + ] guard) ) (defun create-token-with-mint-guard (uri:string precision:integer policies:[module{kip.token-policy-v2}]) @@ -120,25 +165,42 @@ (let* ( (mint-guard:guard (read-keyset "mint_guard")) (token-id:string (create-token-id {'uri: uri, 'precision: precision, 'policies: policies} mint-guard)) ) - (contains-concrete-policy GUARD_POLICY policies) + (enforce-mint-guard policies) (with-capability (UTIL-SIGN) (create-token token-id precision uri policies mint-guard) ) ) ) - (defun create-token-with-mint-guard (uri:string precision:integer policies:[module{kip.token-policy-v2}]) - @doc "Creates a token, enforce that MINT-GUARD is registered" - (let* ( (mint-guard:guard (read-keyset "mint_guard")) - (token-id:string (create-token-id {'uri: uri, 'precision: precision, 'policies: policies} mint-guard)) + (defun create-token-with-uri-guard (uri:string precision:integer policies:[module{kip.token-policy-v2}]) + @doc "Creates a token, enforce that URI-GUARD is registered" + (let* ( (uri-guard:guard (read-keyset "uri_guard")) + (token-id:string (create-token-id {'uri: uri, 'precision: precision, 'policies: policies} uri-guard)) ) - (contains-concrete-policy GUARD_POLICY policies) + (enforce-uri-guard policies) (with-capability (UTIL-SIGN) - (create-token token-id precision uri policies mint-guard) + (create-token token-id precision uri policies uri-guard) ) ) ) + (defun enforce-uri-guard (policies:[module{kip.token-policy-v2}]) + @doc "Helper function to enforce that a URI_GUARD is correctly registered with GUARD_POLICY" + (contains-concrete-policy GUARD_POLICY policies) + (read-keyset "uri_guard") + ) + + (defun enforce-mint-guard (policies:[module{kip.token-policy-v2}]) + @doc "Helper function to enforce that a URI_GUARD is correctly registered with GUARD_POLICY" + (contains-concrete-policy GUARD_POLICY policies) + (read-keyset "mint_guard") + ) + + (defun enforce-non-updatable-uri (policies:[module{kip.token-policy-v2}]) + @doc "Helper function to enforce that a NON_UPDATABLE_URI_POLICY is part of policies" + (contains-concrete-policy NON_UPDATABLE_URI_POLICY policies) + ) + ) (enforce-guard ADMIN-KS) diff --git a/pact/marmalade-util/util-v1.repl b/pact/marmalade-util/util-v1.repl index 1b077ce7..45a285fa 100644 --- a/pact/marmalade-util/util-v1.repl +++ b/pact/marmalade-util/util-v1.repl @@ -19,14 +19,13 @@ (mint-basic-NFT "uri" (read-keyset 'account-guard )) (expect "create-token, mint events" - [ {"name": "marmalade-v2.ledger.TOKEN","params": ["t:Ov0cEBLMvSo2E1ys7dWLgqGTT9OYOLyILf1ow9Gopek" 0 [marmalade-v2.non-fungible-policy-v1] "uri" (read-keyset 'account-guard)]} - {"name": "marmalade-v2.ledger.MINT","params": ["t:Ov0cEBLMvSo2E1ys7dWLgqGTT9OYOLyILf1ow9Gopek" (read-string 'account) 1.0]} - {"name": "marmalade-v2.ledger.ACCOUNT_GUARD","params": ["t:Ov0cEBLMvSo2E1ys7dWLgqGTT9OYOLyILf1ow9Gopek" (read-string 'account) (read-keyset 'account-guard)]} - {"name": "marmalade-v2.ledger.RECONCILE","params": ["t:Ov0cEBLMvSo2E1ys7dWLgqGTT9OYOLyILf1ow9Gopek" 1.0 {"account": "","current": 0.0,"previous": 0.0} {"account": (read-string 'account),"current": 1.0,"previous": 0.0}]} - {"name": "marmalade-v2.ledger.SUPPLY","params": ["t:Ov0cEBLMvSo2E1ys7dWLgqGTT9OYOLyILf1ow9Gopek" 1.0]}] + [ {"name": "marmalade-v2.ledger.TOKEN","params": ["t:U50F3xof5EnLQFPd0v2vt8PR3GJTAt8DJ2oWFj7eOgA" 0 [marmalade-v2.non-fungible-policy-v1 marmalade-v2.non-updatable-uri-policy-v1] "uri" (read-keyset 'account-guard)]} + {"name": "marmalade-v2.ledger.MINT","params": ["t:U50F3xof5EnLQFPd0v2vt8PR3GJTAt8DJ2oWFj7eOgA" (read-string 'account) 1.0]} + {"name": "marmalade-v2.ledger.ACCOUNT_GUARD","params": ["t:U50F3xof5EnLQFPd0v2vt8PR3GJTAt8DJ2oWFj7eOgA" (read-string 'account) (read-keyset 'account-guard)]} + {"name": "marmalade-v2.ledger.RECONCILE","params": ["t:U50F3xof5EnLQFPd0v2vt8PR3GJTAt8DJ2oWFj7eOgA" 1.0 {"account": "","current": 0.0,"previous": 0.0} {"account": (read-string 'account),"current": 1.0,"previous": 0.0}]} + {"name": "marmalade-v2.ledger.SUPPLY","params": ["t:U50F3xof5EnLQFPd0v2vt8PR3GJTAt8DJ2oWFj7eOgA" 1.0]}] (map (remove "module-hash") (env-events true)) ) - (commit-tx) (begin-tx "mint a NFT with policies") @@ -96,8 +95,8 @@ } ]) - (marmalade-v2.ledger.mint "t:L3Eh5k3RUJDiD2AWahQwaQPJJ6S3_L9tK2svspfpRPQ" (read-string 'account) (read-keyset 'account-guard ) 1.0) + (expect "mint, events" [ {"name": "marmalade-v2.ledger.MINT","params": ["t:L3Eh5k3RUJDiD2AWahQwaQPJJ6S3_L9tK2svspfpRPQ" (read-string 'account) 1.0]} {"name": "marmalade-v2.ledger.ACCOUNT_GUARD","params": ["t:L3Eh5k3RUJDiD2AWahQwaQPJJ6S3_L9tK2svspfpRPQ" (read-string 'account) (read-keyset 'account-guard)]} diff --git a/pact/policy-manager/manager-init.pact b/pact/policy-manager/manager-init.pact index 622c1514..40784c9d 100644 --- a/pact/policy-manager/manager-init.pact +++ b/pact/policy-manager/manager-init.pact @@ -6,4 +6,4 @@ (policy-manager.write-concrete-policy ROYALTY_POLICY royalty-policy-v1) (policy-manager.write-concrete-policy COLLECTION_POLICY collection-policy-v1) (policy-manager.write-concrete-policy GUARD_POLICY guard-policy-v1) -(policy-manager.write-concrete-policy NON_UPDATABLE_URI_POLICY guard-policy-v1) +(policy-manager.write-concrete-policy NON_UPDATABLE_URI_POLICY non-updatable-uri-policy-v1)