Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed May 20, 2019
1 parent cef5d9c commit baa5fe1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 52 deletions.
29 changes: 15 additions & 14 deletions pact.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -258,32 +258,33 @@ test-suite hspec
ghc-options: -Wall -threaded -rtsopts -O2 -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints
build-depends:
base
, bound
, Decimal
, deepseq
, exceptions
, hspec
, HUnit
, pact
, aeson
, base16-bytestring >=0.1.1.6 && < 0.2
, bound
, bytestring
, containers
, data-default
, deepseq
, directory
, errors >= 2.3
, exceptions
, filepath
, mmorph
, data-default
, hedgehog == 0.6.*
, hspec
, hw-hspec-hedgehog == 0.1.*
, intervals
, lens
, unordered-containers
, mmorph
, mtl
, pact
, prettyprinter
, prettyprinter-ansi-terminal
, prettyprinter-convert-ansi-wl-pprint
, bytestring
, base16-bytestring >=0.1.1.6 && < 0.2
, mtl
, text
, transformers
, hedgehog == 0.6.*
, hw-hspec-hedgehog == 0.1.*
, intervals
, unordered-containers
, vector
other-modules:
Blake2Spec
Expand Down
35 changes: 19 additions & 16 deletions tests/RemoteVerifySpec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -9,6 +10,8 @@ import Control.Concurrent
import Control.Exception (finally)
import Control.Lens
import Control.Monad.State.Strict
import Control.Monad.Trans.Except
import Data.Bifunctor (first)
import Data.Either
import qualified Data.Text as T
import NeatInterpolation (text)
Expand Down Expand Up @@ -88,8 +91,22 @@ testSingleModule = do

testUnsortedModules :: Spec
testUnsortedModules = do
eReplState0 <- runIO $ loadCode
[text|
replState0 <- runIO $ either (error . show) id <$> loadCode code

it "loads when topologically sorted locally" $ do
stateModuleData "mod2" replState0 >>= (`shouldSatisfy` isRight)

resp <- runIO . runExceptT $ do
ModuleData mod1 _refs <- ExceptT $ stateModuleData "mod1" replState0
ModuleData mod2 _refs <- ExceptT $ stateModuleData "mod2" replState0
ExceptT . fmap (first show) . serveAndRequest 3001 $
Remote.Request [derefDef <$> mod2, derefDef <$> mod1] "mod2"

it "verifies over the network" $
fmap (view Remote.responseLines) resp `shouldBe`
(Right ["Property proven valid",""])
where
code = [text|
(env-keys ["admin"])
(env-data { "keyset": { "keys": ["admin"], "pred": "=" } })
(begin-tx)
Expand All @@ -110,17 +127,3 @@ testUnsortedModules = do
2))
(commit-tx)
|]

it "loads when topologically sorted locally" $ do
Right replState0 <- pure eReplState0
stateModuleData "mod2" replState0 >>= (`shouldSatisfy` isRight)

Right replState0 <- pure eReplState0
Right (ModuleData mod1 _refs) <- runIO $ stateModuleData "mod1" replState0
Right (ModuleData mod2 _refs) <- runIO $ stateModuleData "mod2" replState0

resp <- runIO $ serveAndRequest 3001 $ Remote.Request [derefDef <$> mod2, derefDef <$> mod1] "mod2"

it "verifies over the network" $
fmap (view Remote.responseLines) resp `shouldBe`
(Right ["Property proven valid",""])
52 changes: 30 additions & 22 deletions tests/SignatureSpec.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module SignatureSpec (spec) where

import Test.Hspec

import Control.Monad (forM_)
import Control.Error.Util (failWith, hoistEither)
import Control.Monad (forM_, void)
import Control.Monad.Trans.Except
import Data.Bifunctor (first)
import Data.Default (def)
import qualified Data.HashMap.Strict as HM


import Pact.Repl
import Pact.Repl.Types
import Pact.Types.Exp
import Pact.Types.Info (Info(..))
import Pact.Types.Runtime
import Pact.Types.Term (Module(..), Interface(..), ModuleName(..), ModuleDef(..),
Meta(..), Term(..), Ref'(..), Ref, Def(..))
import Pact.Types.Term
(Def(..), Interface(..), Meta(..), Module(..), ModuleDef(..),
ModuleName(..), Ref, Ref'(..), Term(..))


spec :: Spec
Expand All @@ -24,26 +28,30 @@ spec = compareModelSpec
compareModelSpec :: Spec
compareModelSpec = describe "Module models" $ do
(r,s) <- runIO $ execScript' Quiet "tests/pact/signatures.repl"
case r of
Left e -> it "loaded script" $ expectationFailure e
Right _ -> return ()
Right (rs,_) <- runIO $ replGetModules s
Just md <- return $ HM.lookup (ModuleName "model-test1-impl" Nothing) rs
Just ifd <- return $ HM.lookup (ModuleName "model-test1" Nothing) rs

let mModels = case _mdModule md of
MDModule m -> _mModel $ _mMeta m
_ -> def
iModels = case _mdModule ifd of
MDInterface i -> _mModel $ _interfaceMeta i
_ -> def
mfunModels = aggregateFunctionModels md
ifunModels = aggregateFunctionModels ifd
eres <- runIO . runExceptT $ do
void $ hoistEither r
(rs,_) <- ExceptT . fmap (first show) $ replGetModules s
md <- failWith "Map lookup failed" $ HM.lookup (ModuleName "model-test1-impl" Nothing) rs
ifd <- failWith "Map lookup failed" $ HM.lookup (ModuleName "model-test1" Nothing) rs
pure (md, ifd)

case eres of
Left e -> it "script loading + lookups" $ expectationFailure e
Right (md, ifd) -> do
let mModels = case _mdModule md of
MDModule m -> _mModel $ _mMeta m
_ -> def
iModels = case _mdModule ifd of
MDInterface i -> _mModel $ _interfaceMeta i
_ -> def
mfunModels = aggregateFunctionModels md
ifunModels = aggregateFunctionModels ifd

-- test toplevel models
hasAllExps mModels iModels
-- test function models
hasAllExps mfunModels ifunModels
-- test toplevel models
hasAllExps mModels iModels
-- test function modules
hasAllExps mfunModels ifunModels

hasAllExps :: [Exp Info] -> [Exp Info] -> Spec
hasAllExps mexps iexps = forM_ iexps $ \e ->
Expand Down

0 comments on commit baa5fe1

Please sign in to comment.