Skip to content

Commit

Permalink
Add check for managed cap manager fn
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Feb 14, 2025
1 parent ed950a5 commit 6ccef98
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
13 changes: 13 additions & 0 deletions pact-tests/Pact/Core/Test/TransitiveDependencyTests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Pact.Core.Test.TransitiveDependencyTests where

-- import Pact.Core.Names
-- import Pact.Core.Hash

-- fooModuleHash :: ModuleHash
-- fooModuleHash = ModuleHash $ hash "foo"

-- barModuleHash :: ModuleHash
-- barModuleHash = ModuleHash $ hash "bar"

-- bazModuleHash :: ModuleHash
-- bazModuleHash = ModuleHash $ hash "baz"
1 change: 1 addition & 0 deletions pact-tests/constructor-tag-goldens/DesugarError.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
{"conName":"DuplicateDefinition","conIndex":"17"}
{"conName":"InvalidBlessedHash","conIndex":"18"}
{"conName":"InvalidNativeShadowing","conIndex":"19"}
{"conName":"InvalidManagerFun","conIndex":"1a"}

22 changes: 0 additions & 22 deletions pact-tests/pact-tests/db.repl
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,6 @@
"Module admin necessary for operation but has not been acquired:dbtest"
(create-table persons2))

;; test nested commits

; (begin-tx)
; (env-enable-repl-natives true)
; (module nested-tx G
; (defcap G () true)
; (defschema s x:integer)
; (deftable t:{s})
; (defun test-nested-tx ()
; (begin-tx)
; (insert t "a" { 'x: 1 })
; (commit-tx)
; (begin-tx)
; (insert t "b" { 'x: 2 })
; (rollback-tx)
; (expect "2nd insert rolled back" ["a"]
; (keys t))))

; (create-table t)
; (commit-tx)

; (nested-tx.test-nested-tx)

;; fold-db tests + key sort guarantees
(env-exec-config [])
Expand Down
2 changes: 1 addition & 1 deletion pact-tests/pact-tests/transitive.repl
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@

(begin-tx)
(expect "calls-baz succeeds" 1 (baz.calls-baz))
(commit-tx)
(commit-tx)
1 change: 1 addition & 0 deletions pact-tng.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,6 @@ test-suite core-tests
, Pact.Core.Test.PactContinuationTest
, Pact.Core.Test.ClientTests
, Pact.Core.Test.ServerUtils
, Pact.Core.Test.TransitiveDependencyTests
if (flag(with-crypto))
build-depends: pact-tng:pact-crypto
1 change: 0 additions & 1 deletion pact/Pact/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Pact.Core.Compile

import Control.Lens
import Control.Monad
import Control.Monad.State.Strict
import Data.Text(Text)
import Data.Maybe(mapMaybe)
import Codec.Serialise(Serialise)
Expand Down
7 changes: 7 additions & 0 deletions pact/Pact/Core/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ data DesugarError
| InvalidBlessedHash Text
-- ^ Blessed hash has invalid format
| InvalidNativeShadowing Text
-- ^ Name shadows an existing native
| InvalidManagerFun QualifiedName
-- ^ Manager function is an invalid ref
deriving (Eq, Show, Generic)

instance NFData DesugarError
Expand Down Expand Up @@ -415,6 +418,8 @@ instance Pretty DesugarError where
"Invalid blessed hash, incorrect format:" <+> pretty hs
InvalidNativeShadowing t ->
"Variable" <+> pretty t <+> "shadows native with the same name"
InvalidManagerFun qn ->
pretty qn <+> "is not a valid managed capability manager function." <+> pretty qn <+> "must be a defun"

-- | Argument type mismatch meant for errors
-- that does not force you to show the whole PactValue
Expand Down Expand Up @@ -1769,6 +1774,8 @@ desugarErrorToBoundedText = mkBoundedText . \case
thsep ["Invalid blessed hash, incorrect format:", hs]
InvalidNativeShadowing t ->
thsep ["Variable", t, "shadows native with same name"]
InvalidManagerFun qn ->
thsep [renderQualName qn, "is not a valid managed capability manager function.", renderQualName qn, "must be a defun"]

-- | NOTE: Do _not_ change this function post mainnet release just to improve an error.
-- This will fork the chain, these messages will make it into outputs.
Expand Down
5 changes: 4 additions & 1 deletion pact/Pact/Core/IR/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import Pact.Core.Persistence hiding (loaded)
import Pact.Core.Capabilities
import Pact.Core.Errors
import Pact.Core.IR.Term
import Pact.Core.IR.Eval.Runtime.Utils
import Pact.Core.Guards
import Pact.Core.Imports
import Pact.Core.Environment
Expand Down Expand Up @@ -1237,8 +1238,10 @@ resolveMeta _ DefEvent = pure DefEvent
resolveMeta _ Unmanaged = pure Unmanaged
resolveMeta _ (DefManaged AutoManagedMeta) = pure (DefManaged AutoManagedMeta)
resolveMeta info (DefManaged (DefManagedMeta i (FQParsed pn))) = do
(name', _) <- resolveName info pn
(name', dk) <- resolveName info pn
fqn <- expectedFree info name'
lift $ unlessExecutionFlagSet FlagDisablePact51 $ when (dk /= Just DKDefun) $
throwError $ PEDesugarError (InvalidManagerFun (fqnToQualName fqn)) info
pure (DefManaged (DefManagedMeta i (FQName fqn)))

expectedFree
Expand Down

0 comments on commit 6ccef98

Please sign in to comment.