Skip to content

Commit 8ca8cb1

Browse files
committed
Hooking up Haskell code in tests
1 parent 9a95f16 commit 8ca8cb1

File tree

7 files changed

+33
-45
lines changed

7 files changed

+33
-45
lines changed

formal-spec/Everything.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ module Everything where
33
open import Leios.Simplified
44
open import Leios.Short
55
open import Leios.Network
6+
open import Leios.Foreign.Export

formal-spec/Leios/Foreign/Export.agda

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ record IBHeaderHs : Type where
2525
producerID : Int
2626

2727
{-# FOREIGN GHC
28-
data IBHeaderHs = IBHeaderHs Integer Integer
28+
data IBHeaderHs = IBHeaderHs Integer Integer
29+
deriving (Show, Eq, Generic)
2930
#-}
3031

3132
{-# COMPILE GHC IBHeaderHs = data IBHeaderHs (IBHeaderHs) #-}
@@ -70,6 +71,7 @@ record EndorserBlockHs : Type where
7071

7172
{-# FOREIGN GHC
7273
data EndorserBlockHs = EndorserBlockHs Integer Integer [Integer]
74+
deriving (Show, Eq, Generic)
7375
#-}
7476

7577
{-# COMPILE GHC EndorserBlockHs = data EndorserBlockHs (EndorserBlockHs) #-}
@@ -95,4 +97,3 @@ instance
9597

9698
HsTy-LeiosState = autoHsType LeiosState
9799
Conv-LeiosState = autoConvert LeiosState
98-

formal-spec/hs-src/leios-spec.cabal

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,11 @@ common globalOptions
2727
PatternSynonyms DeriveGeneric
2828
ghc-options:
2929
-Wno-overlapping-patterns
30-
31-
test-suite test
32-
import: globalOptions
33-
hs-source-dirs: test
34-
main-is: Spec.hs
35-
other-modules:
36-
UtxowSpec
37-
build-depends:
38-
leios-spec,
39-
hspec,
40-
HUnit,
41-
text
42-
build-tool-depends: hspec-discover:hspec-discover
43-
type: exitcode-stdio-1.0
44-
ghc-options:
45-
-Wall
46-
-threaded -rtsopts -with-rtsopts=-N
47-
-fno-warn-type-defaults
48-
49-
executable leios-spec
50-
import: globalOptions
51-
hs-source-dirs: exe
52-
main-is: Main.hs
53-
build-depends:
54-
text,
55-
ieee,
56-
leios-spec
57-
5830
library
5931
import: globalOptions
6032
hs-source-dirs: src
6133
exposed-modules:
34+
Lib
6235
build-depends:
6336
text,
6437
ieee

leios-conformance/leios-conformance.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ library
3030
, bytestring
3131
, containers
3232
, data-default
33+
, leios-spec
3334
, mtl
3435
, pretty
3536
, QuickCheck

leios-conformance/src/Leios/Conformance/Model.hs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
{-# LANGUAGE DeriveGeneric #-}
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE RecordWildCards #-}
4-
module Leios.Conformance.Model where
5-
6-
import Data.Aeson (FromJSON, ToJSON)
4+
{-# LANGUAGE FlexibleContexts #-}
5+
{-# LANGUAGE UndecidableInstances #-}
6+
{-# OPTIONS_GHC -Wno-orphans #-}
7+
module Leios.Conformance.Model
8+
( module Leios.Conformance.Model
9+
, module Lib
10+
) where
11+
12+
import Data.Aeson (FromJSON(..), ToJSON(..))
713
import Data.Maybe (maybeToList)
814
import GHC.Generics (Generic)
915
import Text.PrettyPrint.HughesPJClass (Pretty (pPrint))
1016

17+
import Lib
18+
1119
data EnvAction
1220
= Tick
1321
| NewIB InputBlock
1422
| NewEB EndorserBlock
1523
| NewVote Vote
1624
deriving (Eq, Show)
1725

18-
-- TODO: use InputBlock extracted from Agda
19-
data InputBlock = InputBlock
20-
deriving (Show, Eq, Generic)
26+
instance FromJSON InputBlock where
27+
parseJSON = undefined
28+
29+
instance ToJSON InputBlock where
30+
toJSON = undefined
2131

22-
instance FromJSON InputBlock
23-
instance ToJSON InputBlock
2432
instance Pretty InputBlock where
25-
pPrint InputBlock = "InputBlock"
33+
pPrint (InputBlock _ _) = "InputBlock"
2634

2735
-- TODO: use EndorserBlock extracted from Agda
2836
data EndorserBlock = EndorserBlock
@@ -44,7 +52,7 @@ instance Pretty Vote where
4452

4553
-- TODO: use LeiosState extracted from Agda
4654
data NodeModel = NodeModel
47-
{ slot :: Integer
55+
{ currentSlot :: Integer
4856
, ibs :: [InputBlock]
4957
, ebs :: [EndorserBlock]
5058
, votes :: [Vote]

leios-conformance/src/Leios/Conformance/Test.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Leios.Conformance.Test where
1111

1212
import Data.Maybe (isJust)
1313
import Test.QuickCheck (
14-
frequency
14+
frequency, Arbitrary (..)
1515
)
1616
import Test.QuickCheck.DynamicLogic (DynLogicModel)
1717
import Test.QuickCheck.StateModel (
@@ -65,6 +65,10 @@ instance Pretty EnvAction where
6565
pPrint (NewEB eb) = "NewEB" <+> pPrint eb
6666
pPrint (NewVote v) = "NewVote" <+> pPrint v
6767

68+
instance Arbitrary InputBlock where
69+
70+
instance Arbitrary EndorserBlock where
71+
6872
instance StateModel NetworkModel where
6973
data Action NetworkModel a where
7074
Step :: EnvAction -> Action NetworkModel ([InputBlock], [EndorserBlock], [Vote])
@@ -78,8 +82,8 @@ instance StateModel NetworkModel where
7882
arbitraryAction _ _ =
7983
fmap (Some . Step) . frequency $
8084
[(1, pure Tick)]
81-
++ fmap (1,) (pure . NewIB <$> [InputBlock])
82-
++ fmap (1,) (pure . NewEB <$> [EndorserBlock])
85+
++ fmap (1,) [NewIB <$> arbitrary]
86+
++ fmap (1,) [NewEB <$> arbitrary]
8387

8488
shrinkAction _ _ (Step Tick) = []
8589
shrinkAction _ _ Step{} = [Some (Step Tick)]

leios-conformance/src/Leios/Conformance/Test/External.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ instance Realized IO ([InputBlock], [EndorserBlock], [Vote]) ~ ([InputBlock], [E
133133
let (expectedIBs, expectedEBs, expectedVotes) = maybe (mempty, mempty, mempty) fst $ transition s a
134134
let ok = (ibs, ebs) == (expectedIBs, expectedEBs)
135135
monitorPost . counterexample . show $ " action $" <+> pPrint a
136-
when (a == Tick && slot s == slot s' + 1) $
137-
monitorPost . counterexample $ " -- new slot: " ++ show (slot s')
136+
when (a == Tick && currentSlot s == currentSlot s' + 1) $
137+
monitorPost . counterexample $ " -- new slot: " ++ show (currentSlot s')
138138
unless (null ibs) $
139139
monitorPost . counterexample . show $ " -- got InputBlocks:" <+> pPrint ibs
140140
when (ibs /= expectedIBs) $

0 commit comments

Comments
 (0)