Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Nov 30, 2023
1 parent 146cc19 commit a22710f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 92 deletions.
2 changes: 0 additions & 2 deletions pact-core-tests/Pact/Core/Test/LegacySerialiseTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Test.Tasty.HUnit (assertBool, testCase)
import Data.Maybe
import Pact.Core.Serialise.LegacyPact
import Pact.Core.Guards
import Data.Text (Text)
import qualified Data.Text.IO as T

tests :: TestTree
tests = testGroup "Legacy Serialisation"
Expand Down
65 changes: 5 additions & 60 deletions pact-core-tests/Pact/Core/Test/ReplTests.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}

module Pact.Core.Test.ReplTests where
Expand All @@ -11,7 +10,6 @@ import Control.Monad(when)
import Data.IORef
import Data.Default
import Data.ByteString(ByteString)
import qualified Data.ByteString.Char8 as BSC
import Data.Foldable(traverse_)
import Data.Text.Encoding(decodeUtf8)
import System.Directory
Expand All @@ -22,28 +20,21 @@ import qualified Data.ByteString as B

import Pact.Core.Gas
import Pact.Core.Literal
-- import Pact.Core.Persistence
import Pact.Core.Persistence.MockPersistence
import Pact.Core.Interpreter

import Pact.Core.Repl.Utils
import Pact.Core.Persistence (PactDb(..), Domain(..), readKeySet, readModule, ModuleData(..), readNamespace, readDefPacts
,writeKeySet, writeNamespace, writeDefPacts, writeModule)
import Pact.Core.Persistence (PactDb(..), ModuleData(..))
import Pact.Core.Persistence.SQLite (withSqlitePactDb)
import Pact.Core.Serialise (PactSerialise(..), serialisePact, Document(LegacyDocument))

import Pact.Core.Info (SpanInfo)
import Pact.Core.Compile
import Pact.Core.IR.Term (Module(..), EvalModule)
import Pact.Core.Builtin (ReplBuiltin)
import Pact.Core.Repl.Compile
import Pact.Core.PactValue
import Pact.Core.Environment
import Pact.Core.Builtin
import Pact.Core.Errors
import Pact.Core.Guards
import Pact.Core.Names
import Pact.Core.IR.Term (EvalModule, Module(..), EvalDef, Def(..))

tests :: IO TestTree
tests = do
Expand All @@ -56,13 +47,13 @@ tests = do

enhanceModuleData :: ModuleData RawBuiltin () -> ModuleData ReplRawBuiltin SpanInfo
enhanceModuleData = \case
ModuleData em defs -> undefined
InterfaceData ifd defs -> undefined
ModuleData _em _defs -> undefined
InterfaceData _ifd _defs -> undefined

stripModuleData :: ModuleData ReplRawBuiltin SpanInfo -> ModuleData RawBuiltin ()
stripModuleData = \case
ModuleData em defs -> undefined
InterfaceData ifd defs -> undefined
ModuleData _em _defs -> undefined
InterfaceData _ifd _defs -> undefined

enhanceEvalModule :: EvalModule RawBuiltin () -> EvalModule ReplRawBuiltin SpanInfo
enhanceEvalModule Module
Expand Down Expand Up @@ -98,52 +89,6 @@ runFileReplTest mkPactDb file = testCase file $ do
pdb <- mkPactDb
B.readFile (replTestDir </> file) >>= runReplTest pdb file

-- enhance :: PactDb RawBuiltin () -> PactDb ReplRawBuiltin SpanInfo
-- enhance pdb = PactDb
-- { _pdbPurity = _pdbPurity pdb
-- , _pdbRead = \case
-- (DUserTables tbl) -> _pdbRead pdb (DUserTables tbl)
-- DKeySets -> readKeySet pdb
-- DModules -> \k -> fmap enhanceModule <$> readModule pdb k
-- DNamespaces -> readNamespace pdb
-- DDefPacts -> readDefPacts pdb
-- , _pdbWrite = \wt -> \case
-- (DUserTables tbl) -> _pdbWrite pdb wt (DUserTables tbl)
-- DKeySets -> writeKeySet pdb wt
-- DModules -> \k v -> writeModule pdb wt k (stripModule v)
-- DNamespaces -> writeNamespace pdb wt
-- DDefPacts -> writeDefPacts pdb wt
-- , _pdbKeys = undefined
-- , _pdbCreateUserTable = _pdbCreateUserTable pdb
-- , _pdbBeginTx = _pdbBeginTx pdb
-- , _pdbCommitTx = _pdbCommitTx pdb
-- , _pdbRollbackTx = _pdbRollbackTx pdb
-- , _pdbTxIds = _pdbTxIds pdb
-- , _pdbGetTxLog = _pdbGetTxLog pdb
-- , _pdbTxId = _pdbTxId pdb
-- }
-- where
-- enhanceModule :: ModuleData RawBuiltin () -> ModuleData ReplRawBuiltin SpanInfo
-- enhanceModule m = m
-- & moduleDataBuiltin %~ RBuiltinWrap
-- & moduleDataInfo %~ const def

-- stripModule :: ModuleData ReplRawBuiltin SpanInfo -> ModuleData RawBuiltin ()
-- stripModule m = m
-- & moduleDataInfo %~ const ()
-- & moduleDataBuiltin %~ \(RBuiltinWrap b) -> b

-- deriving instance Read (ModuleData ReplRawBuiltin SpanInfo)
-- deriving instance Read (EvalDef ReplRawBuiltin SpanInfo)
-- deriving instance Read (EvalModule ReplRawBuiltin SpanInfo)
-- deriving instance Read (Governance Name)

-- sillySerialise :: PactSerialise ReplRawBuiltin SpanInfo
-- sillySerialise = serialisePact
-- { _encodeModuleData = BSC.pack . show
-- , _decodeModuleData = Just . LegacyDocument . read . BSC.unpack
-- }

runFileReplTestSqlite :: TestName -> TestTree
runFileReplTestSqlite file = testCase file $ do
ctnt <- B.readFile (replTestDir </> file)
Expand Down
31 changes: 1 addition & 30 deletions pact-core/Pact/Core/Serialise/LegacyPact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString.Short as SB
import qualified Data.Text.Encoding as T
import Control.Applicative ((<|>))
import Data.Foldable (toList)
import Data.Maybe (fromMaybe)
import Data.Text (Text)

import Pact.Core.ChainData
import Pact.Core.Hash
import Pact.Core.Parser
import Pact.Core.ModRefs
-- import Pact.Core.Guards
import Pact.Core.Literal
import Data.Decimal
import Pact.Core.Info
import Pact.Time
import qualified Data.Attoparsec.Text as AP
import qualified Pact.JSON.Decode as JD
Expand All @@ -44,23 +40,6 @@ import Text.Read (readMaybe)
decodeModuleData :: ByteString -> Maybe (ModuleData RawBuiltin ())
decodeModuleData = JD.decodeStrict'

instance JD.FromJSON (ModuleData ReplRawBuiltin SpanInfo) where
parseJSON = JD.withObject "ModuleData" $ \o -> do
key :: Text <- o JD..: "key"
value <- o JD..: "value"
case key of
"ModuleData" -> parseModuleDataCtor value
"InterfaceData" -> parseInterfaceDataCtor value
where
parseModuleDataCtor = JD.withArray "ModuleData" $ \arr -> case toList arr of
[e1, e2] -> undefined
_ -> undefined
parseInterfaceDataCtor = undefined


decodeModuleData_Repl_Info :: ByteString -> Maybe (ModuleData ReplRawBuiltin SpanInfo)
decodeModuleData_Repl_Info = JD.decodeStrict'

decodeKeySet :: ByteString -> Maybe (KeySet FullyQualifiedName)
decodeKeySet = JD.decodeStrict'

Expand Down Expand Up @@ -106,7 +85,7 @@ instance JD.FromJSON Namespace where
<*> v JD..: "admin"

instance JD.FromJSON (ModuleData RawBuiltin ()) where
parseJSON = undefined
parseJSON = error "unimplemented"

instance JD.FromJSON DefPactExec where
parseJSON = JD.withObject "PactExec" $ \o ->
Expand Down Expand Up @@ -188,14 +167,6 @@ instance JD.FromJSON ModRef where
<*> o JD..: "refSpec"
<*> pure Nothing

-- instance JD.FromJSON Literal where
-- -- parseJSON n@Number{} = LDecimal <$> decoder decimalCodec n
-- parseJSON (LString s) = pure $ LString s
-- parseJSON (LBool b) = pure $ LBool b
-- parseJSON (LInteger i) = undefined --decoder integerCodec i
-- (LDecimal <$> decoder decimalCodec o)
-- parseJSON _t = fail "Literal parse failed"

instance JD.FromJSON Field where
parseJSON = JD.withText "Field" (pure . Field)

Expand Down

0 comments on commit a22710f

Please sign in to comment.