Skip to content

Commit

Permalink
add non-updatable-uri-policy into util-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ggobugi27 committed May 16, 2024
1 parent 5e3cb53 commit fab68d1
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
,'royalty-policy: false
,'collection-policy:false
,'guard-policy: true
,'non-updatable-uri-policy: false
}
)
)
Expand Down Expand Up @@ -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 ")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
82 changes: 72 additions & 10 deletions pact/marmalade-util/util-v1.pact
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,40 @@
royalty-policy:bool
collection-policy:bool
guard-policy:bool
non-updatable-uri-policy:bool
)

(defconst DEFAULT:object{concrete-policy-bool}
{ 'non-fungible-policy: true
,'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
}
)

Expand All @@ -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
}
)

Expand All @@ -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
}
)

Expand All @@ -59,6 +99,7 @@
,'royalty-policy: false
,'collection-policy:false
,'guard-policy: false
,'non-updatable-uri-policy: false
}
)

Expand All @@ -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)
}
)

Expand Down Expand Up @@ -111,34 +153,54 @@
)

(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}])
@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))
)
(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)
13 changes: 6 additions & 7 deletions pact/marmalade-util/util-v1.repl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)]}
Expand Down
2 changes: 1 addition & 1 deletion pact/policy-manager/manager-init.pact
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit fab68d1

Please sign in to comment.