Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jose/obj-tables' into gr/fix-typ…
Browse files Browse the repository at this point in the history
…ed-core
  • Loading branch information
0xd34df00d committed Oct 11, 2023
2 parents bf8274c + a63a2ff commit a17837f
Show file tree
Hide file tree
Showing 39 changed files with 3,841 additions and 1,799 deletions.
11 changes: 10 additions & 1 deletion pact-core-tests/Pact/Core/Test/LexerParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ parsedNameGen = Gen.choice [qn, bn]
mn <- moduleNameGen
let qname = QualifiedName name mn
pure (QN qname)
parsedTyNameGen :: Gen ParsedTyName
parsedTyNameGen = Gen.choice [qn, bn]
where
bn = TBN . BareName <$> identGen
qn = do
name <- identGen
mn <- moduleNameGen
let qname = QualifiedName name mn
pure (TQN qname)

moduleNameGen :: Gen ModuleName
moduleNameGen = do
Expand Down Expand Up @@ -175,7 +184,7 @@ exprGen = Gen.recursive Gen.choice
,Lisp.TyModRef <$> moduleNameGen
,pure Lisp.TyGuard
,pure Lisp.TyKeyset
,Lisp.TyObject <$> parsedNameGen
,Lisp.TyObject <$> parsedTyNameGen
,pure Lisp.TyTime
,pure Lisp.TyPolyObject]

Expand Down
14 changes: 11 additions & 3 deletions pact-core-tests/Pact/Core/Test/ReplTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Test.Tasty.HUnit

import Control.Monad(when)
import Data.IORef
import Data.Default
import Data.ByteString(ByteString)
import Data.Foldable(traverse_)
import Data.Text.Encoding(decodeUtf8)
Expand All @@ -17,11 +18,14 @@ import qualified Data.ByteString as B
import Pact.Core.Gas
import Pact.Core.Literal
import Pact.Core.Persistence
import Pact.Core.Interpreter

import Pact.Core.Repl.Utils
import Pact.Core.Compile
import Pact.Core.Repl.Compile
import Pact.Core.PactValue
import Pact.Core.Environment
import Pact.Core.Hash
import Pact.Core.Errors (PactError(..), EvalError (..))

tests :: IO TestTree
Expand All @@ -45,14 +49,18 @@ runReplTest file src = do
gasRef <- newIORef (Gas 0)
gasLog <- newIORef Nothing
pdb <- mockPactDb
let ee = EvalEnv mempty pdb (EnvData mempty) (Hash "default") def
let rstate = ReplState
{ _replFlags = mempty
, _replLoaded = mempty
, _replEvalState = def
, _replPactDb = pdb
, _replGas = gasRef
, _replEvalLog = gasLog }
, _replEvalLog = gasLog
, _replCurrSource = SourceCode mempty
, _replEvalEnv = ee
}
stateRef <- newIORef rstate
runReplT stateRef (interpretReplProgram src) >>= \case
runReplT stateRef (interpretReplProgram (SourceCode src)) >>= \case
Left e -> let
rendered = replError (ReplSource (T.pack file) (decodeUtf8 src)) e
in assertFailure (T.unpack rendered)
Expand Down
8 changes: 4 additions & 4 deletions pact-core-tests/PactCoreTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module Main where

import Test.Tasty

-- import qualified Pact.Core.Test.ReplTests as ReplTests
import qualified Pact.Core.Test.ReplTests as ReplTests
import qualified Pact.Core.Test.LexerParserTests as LexerParserTests
import qualified Pact.Core.Test.LexerTests as LexerTests

main :: IO ()
main = do
-- replTests <- ReplTests.tests
replTests <- ReplTests.tests
defaultMain $ testGroup "pactTests"
-- [ replTests
[ LexerTests.tests
[ replTests
, LexerTests.tests
, LexerParserTests.tests
]
28 changes: 14 additions & 14 deletions pact-core-tests/pact-tests/lists.repl
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@

; distinct tests

; (expect
; "distinct: remove duplicates"
; [1 2 3]
; (distinct [1 1 2 2 3 3]))

; (expect
; "distinct: preserve original order"
; [3 1 2]
; (distinct [3 1 3 2 2 1 3]))

; (expect
; "distinct: work on empty list"
; []
; (distinct []))
(expect
"distinct: remove duplicates"
[1 2 3]
(distinct [1 1 2 2 3 3]))

(expect
"distinct: preserve original order"
[3 1 2]
(distinct [3 1 3 2 2 1 3]))

(expect
"distinct: work on empty list"
[]
(distinct []))

(expect
"zip combines properly"
Expand Down
58 changes: 29 additions & 29 deletions pact-core-tests/pact-tests/ops.repl
Original file line number Diff line number Diff line change
Expand Up @@ -441,31 +441,31 @@
(expect "not != object object" false (!= { "a": 1 } { "a": 1 }))
(expect "!= object object" true (!= { "a": 1 } { "a": 1, "b": 2 }))

; "===== keyset equality"
; (env-data { "k1": ["k1"], "k2": ["k2"] })
; (expect "= keyset keyset" true (= (read-keyset "k1") (read-keyset "k1")))
; (expect "not = keyset keyset" false (= (read-keyset "k1") (read-keyset "k2")))
; (expect "not != keyset keyset" false (!= (read-keyset "k1") (read-keyset "k1")))
; (expect "!= keyset keyset" true (!= (read-keyset "k1") (read-keyset "k2")))

; "===== keyset ref equality"
"===== keyset equality"
(env-data { "k1": ["k1"], "k2": ["k2"] })
(expect "= keyset keyset" true (= (read-keyset "k1") (read-keyset "k1")))
(expect "not = keyset keyset" false (= (read-keyset "k1") (read-keyset "k2")))
(expect "not != keyset keyset" false (!= (read-keyset "k1") (read-keyset "k1")))
(expect "!= keyset keyset" true (!= (read-keyset "k1") (read-keyset "k2")))

"===== keyset ref equality"
; (env-exec-config ["DisablePact44"])
; (env-data { "k1": ["k1"], "k2": ["k2"] })
; (env-keys ["k1" "k2"])
; (define-keyset 'k1 (read-keyset "k1"))
; (define-keyset 'k2 (read-keyset "k2"))
; (expect "= keysetRef keysetRef" true (= (keyset-ref-guard "k1") (keyset-ref-guard "k1")))
; (expect "not = keysetRef keysetRef" false (= (keyset-ref-guard "k1") (keyset-ref-guard "k2")))
; (expect "not != keysetRef keysetRef" false (!= (keyset-ref-guard "k1") (keyset-ref-guard "k1")))
; (expect "!= keysetRef keysetRef" true (!= (keyset-ref-guard "k1") (keyset-ref-guard "k2")))

; (module tm G
; (defcap G () true)
; (defun mk (id) (create-module-guard id))
; (defpact p (id1 id2)
; (step [(create-pact-guard id1) (create-pact-guard id2)]))
; (defun ug (id) true)
; )
(env-data { "k1": ["k1"], "k2": ["k2"] })
(env-keys ["k1" "k2"])
(define-keyset 'k1 (read-keyset "k1"))
(define-keyset 'k2 (read-keyset "k2"))
(expect "= keysetRef keysetRef" true (= (keyset-ref-guard "k1") (keyset-ref-guard "k1")))
(expect "not = keysetRef keysetRef" false (= (keyset-ref-guard "k1") (keyset-ref-guard "k2")))
(expect "not != keysetRef keysetRef" false (!= (keyset-ref-guard "k1") (keyset-ref-guard "k1")))
(expect "!= keysetRef keysetRef" true (!= (keyset-ref-guard "k1") (keyset-ref-guard "k2")))

(module tm G
(defcap G () true)
; (defun mk (id) (create-module-guard id))
; (defpact p (id1 id2)
; (step [(create-pact-guard id1) (create-pact-guard id2)]))
(defun ug (id) true)
)

; "===== module guard equality"
; (expect "= moduleGuard moduleGuard" true (= (tm.mk "1") (tm.mk "1")))
Expand All @@ -483,11 +483,11 @@
; )


; "===== userGuard equality"
; (expect "= userGuard userGuard" true (= (create-user-guard (tm.ug "1")) (create-user-guard (tm.ug "1"))))
; (expect "not = userGuard userGuard" false (= (create-user-guard (tm.ug "2")) (create-user-guard (tm.ug "1"))))
; (expect "not != userGuard userGuard" false (!= (create-user-guard (tm.ug "1")) (create-user-guard (tm.ug "1"))))
; (expect "!= userGuard userGuard" true (!= (create-user-guard (tm.ug "2")) (create-user-guard (tm.ug "1"))))
"===== userGuard equality"
(expect "= userGuard userGuard" true (= (create-user-guard (tm.ug "1")) (create-user-guard (tm.ug "1"))))
(expect "not = userGuard userGuard" false (= (create-user-guard (tm.ug "2")) (create-user-guard (tm.ug "1"))))
(expect "not != userGuard userGuard" false (!= (create-user-guard (tm.ug "1")) (create-user-guard (tm.ug "1"))))
(expect "!= userGuard userGuard" true (!= (create-user-guard (tm.ug "2")) (create-user-guard (tm.ug "1"))))


"===== bitwise"
Expand Down
2 changes: 2 additions & 0 deletions pact-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ library
Pact.Core.Debug
Pact.Core.Capabilities
Pact.Core.ModRefs
Pact.Core.Interpreter
Pact.Core.Environment

-- Syntax modules
Pact.Core.Syntax.ParseTree
Expand Down
Loading

0 comments on commit a17837f

Please sign in to comment.