Skip to content

Commit e94acfe

Browse files
committed
ouroboros-network:api-tests - moved Test.Cardano.Network.Version
1 parent 6ba6d31 commit e94acfe

File tree

21 files changed

+77
-74
lines changed

21 files changed

+77
-74
lines changed

ouroboros-network/mock/Ouroboros/Network/Mock/Chain.hs renamed to ouroboros-network/api/tests-lib/Ouroboros/Network/Mock/Chain.hs

File renamed without changes.

ouroboros-network/protocols/tests-lib/Test/ChainGenerators.hs renamed to ouroboros-network/api/tests-lib/Ouroboros/Network/Mock/ChainGenerators.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
-- | Arbitrary generators for chains, headers and blocks
1414
--
15-
module Test.ChainGenerators
15+
module Ouroboros.Network.Mock.ChainGenerators
1616
( -- * Arbitrary chains generators
1717
-- These generators are used to test various scenarios that require
1818
-- a chain: e.g. appending a block to chain, arbitrary updates
@@ -25,6 +25,7 @@ module Test.ChainGenerators
2525
, TestChainAndRange (..)
2626
, TestChainAndPoints (..)
2727
, TestChainFork (..)
28+
, TestChainRange (..)
2829
-- * Utility functions
2930
, genNonNegative
3031
, genSlotGap
@@ -48,7 +49,6 @@ import Ouroboros.Network.Mock.Chain qualified as Chain
4849
import Ouroboros.Network.Mock.ConcreteBlock
4950
import Ouroboros.Network.Point (WithOrigin (..), block, blockPointHash,
5051
blockPointSlot, fromWithOrigin, origin)
51-
import Ouroboros.Network.Protocol.BlockFetch.Type (ChainRange (..))
5252

5353
import Data.List (scanl')
5454
import Test.Cardano.Slotting.Arbitrary ()
@@ -130,15 +130,17 @@ instance Arbitrary (Point Block) where
130130
. shrink
131131
. (castPoint :: Point Block -> Point BlockHeader)
132132

133-
instance Arbitrary (ChainRange (Point Block)) where
133+
data TestChainRange = TestChainRange (Point Block) (Point Block)
134+
135+
instance Arbitrary TestChainRange where
134136
arbitrary = do
135137
low <- arbitrary
136138
high <- arbitrary `suchThat` (\high -> pointSlot low <= pointSlot high)
137-
return (ChainRange low high)
139+
return (TestChainRange low high)
138140

139-
shrink (ChainRange low high) = [ ChainRange low' high'
140-
| (low', high') <- shrink (low, high)
141-
, pointSlot low <= pointSlot high ]
141+
shrink (TestChainRange low high) = [ TestChainRange low' high'
142+
| (low', high') <- shrink (low, high)
143+
, pointSlot low <= pointSlot high ]
142144

143145
instance Arbitrary BlockBody where
144146
arbitrary =

ouroboros-network/mock/Ouroboros/Network/Mock/ConcreteBlock.hs renamed to ouroboros-network/api/tests-lib/Ouroboros/Network/Mock/ConcreteBlock.hs

File renamed without changes.

ouroboros-network/api/tests/Main.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ module Main (main) where
33
import Main.Utf8 (withUtf8)
44
import Test.Tasty
55

6+
import Test.Cardano.Network.Version qualified as Version
67
import Test.Cardano.Network.NodeToClient.Version qualified as NodeToClient.Version
78
import Test.Cardano.Network.NodeToNode.Version qualified as NodeToNode.Version
9+
import Test.Ouroboros.Network.AnchoredFragment qualified as AnchoredFragment
10+
import Test.Ouroboros.Network.Chain qualified as Chain
811
import Test.Ouroboros.Network.PeerSelection.RelayAccessPoint qualified as RelayAccessPoint
912

1013
main :: IO ()
@@ -13,7 +16,10 @@ main = withUtf8 $ defaultMain tests
1316
tests :: TestTree
1417
tests =
1518
testGroup "ouroboros-network-api"
16-
[ NodeToClient.Version.tests
19+
[ AnchoredFragment.tests
20+
, Chain.tests
21+
, Version.tests
22+
, NodeToClient.Version.tests
1723
, NodeToNode.Version.tests
1824
, RelayAccessPoint.tests
1925
]

ouroboros-network/tests/lib/Test/Cardano/Network/Version.hs renamed to ouroboros-network/api/tests/Test/Cardano/Network/Version.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
--
55
module Test.Cardano.Network.Version (tests) where
66

7-
import Cardano.Network.NodeToClient (NodeToClientVersion (..),
7+
import Cardano.Network.NodeToClient.Version (NodeToClientVersion (..),
88
nodeToClientVersionCodec)
9-
import Cardano.Network.NodeToNode (NodeToNodeVersion (..),
9+
import Cardano.Network.NodeToNode.Version (NodeToNodeVersion (..),
1010
nodeToNodeVersionCodec)
1111
import Ouroboros.Network.CodecCBORTerm
1212

@@ -56,8 +56,8 @@ roundTripPropAll
5656
, Enum a
5757
, Bounded a
5858
, Show a
59-
, Eq failure
6059
, Show failure
60+
, Eq failure
6161
)
6262
=> CodecCBORTerm failure a -> Assertion
6363
roundTripPropAll codec =
@@ -68,8 +68,6 @@ crossFailureProp
6868
:: forall failure a b.
6969
( Show a
7070
, Show b
71-
, Eq failure
72-
, Show failure
7371
)
7472
=> CodecCBORTerm failure a
7573
-> CodecCBORTerm failure b
@@ -85,8 +83,6 @@ crossFailurePropAll
8583
:: forall failure a b.
8684
( Show a
8785
, Show b
88-
, Eq failure
89-
, Show failure
9086
)
9187
=> CodecCBORTerm failure a
9288
-> CodecCBORTerm failure b

ouroboros-network/protocols/tests/Test/AnchoredFragment.hs renamed to ouroboros-network/api/tests/Test/Ouroboros/Network/AnchoredFragment.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{-# OPTIONS_GHC -Wno-x-partial #-}
1111
#endif
1212

13-
module Test.AnchoredFragment
13+
module Test.Ouroboros.Network.AnchoredFragment
1414
( tests
1515
, TestBlockAnchoredFragment (..)
1616
) where
@@ -29,10 +29,11 @@ import Ouroboros.Network.AnchoredFragment (AnchoredFragment,
2929
import Ouroboros.Network.AnchoredFragment qualified as AF
3030
import Ouroboros.Network.Block
3131
import Ouroboros.Network.Mock.Chain qualified as Chain
32+
import Ouroboros.Network.Mock.ChainGenerators (TestBlockChain (..),
33+
TestChainAndRange (..), addSlotGap, genChainAnchor, genNonNegative,
34+
genSlotGap)
3235
import Ouroboros.Network.Mock.ConcreteBlock
3336
import Ouroboros.Network.Point (WithOrigin (..), withOrigin)
34-
import Test.ChainGenerators (TestBlockChain (..), TestChainAndRange (..),
35-
addSlotGap, genChainAnchor, genNonNegative, genSlotGap)
3637

3738

3839
--

ouroboros-network/protocols/tests/Test/Chain.hs renamed to ouroboros-network/api/tests/Test/Ouroboros/Network/Chain.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
88

9-
module Test.Chain (tests) where
9+
module Test.Ouroboros.Network.Chain (tests) where
1010

1111
import Data.List qualified as L
1212
import Data.Maybe (listToMaybe)
@@ -18,8 +18,8 @@ import Test.Tasty.QuickCheck (testProperty)
1818
import Ouroboros.Network.Block (blockPrevHash, pattern GenesisPoint, pointHash)
1919
import Ouroboros.Network.Mock.Chain (Chain (..))
2020
import Ouroboros.Network.Mock.Chain qualified as Chain
21+
import Ouroboros.Network.Mock.ChainGenerators hiding (tests)
2122

22-
import Test.ChainGenerators hiding (tests)
2323
import Test.Ouroboros.Network.Serialise (prop_serialise)
2424

2525

ouroboros-network/ouroboros-network.cabal

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,37 @@ library api
125125
text >=1.2 && <2.2,
126126
typed-protocols ^>=1.1,
127127

128+
library api-tests-lib
129+
import: ghc-options
130+
hs-source-dirs: api/tests-lib
131+
exposed-modules:
132+
Ouroboros.Network.Mock.ConcreteBlock
133+
Ouroboros.Network.Mock.Chain
134+
Ouroboros.Network.Mock.ChainGenerators
135+
build-depends:
136+
QuickCheck,
137+
base,
138+
bytestring,
139+
cardano-slotting:testlib ^>=0.2.0,
140+
cborg,
141+
hashable,
142+
nothunks,
143+
ouroboros-network:api,
144+
quickcheck-instances,
145+
serialise,
146+
tasty,
147+
tasty-quickcheck,
148+
time,
149+
128150
test-suite api-tests
129151
import: ghc-options
130152
type: exitcode-stdio-1.0
131153
main-is: Main.hs
132154
hs-source-dirs: api/tests
133-
default-language: Haskell2010
134-
default-extensions: ImportQualifiedPost
135155
other-modules:
156+
Test.Ouroboros.Network.AnchoredFragment
157+
Test.Ouroboros.Network.Chain
158+
Test.Cardano.Network.Version
136159
Test.Cardano.Network.NodeToClient.Version
137160
Test.Cardano.Network.NodeToNode.Version
138161
Test.Ouroboros.Network.PeerSelection.RelayAccessPoint
@@ -145,8 +168,9 @@ test-suite api-tests
145168
cardano-binary,
146169
cborg,
147170
iproute,
148-
ouroboros-network:api,
171+
ouroboros-network:{api, api-tests-lib, tests-lib},
149172
tasty,
173+
tasty-hunit,
150174
tasty-quickcheck,
151175
with-utf8,
152176

@@ -833,7 +857,6 @@ library protocols-tests-lib
833857
Ouroboros.Network.Protocol.TxSubmission2.Direct
834858
Ouroboros.Network.Protocol.TxSubmission2.Examples
835859
Ouroboros.Network.Protocol.TxSubmission2.Test
836-
Test.ChainGenerators
837860
Test.ChainProducerState
838861
Test.Data.CDDL
839862
Test.Data.PipeliningDepth
@@ -843,7 +866,6 @@ library protocols-tests-lib
843866
QuickCheck,
844867
base >=4.14 && <4.22,
845868
bytestring,
846-
cardano-slotting:testlib ^>=0.2.0,
847869
cardano-strict-containers,
848870
cborg,
849871
containers,
@@ -853,7 +875,7 @@ library protocols-tests-lib
853875
io-sim,
854876
network,
855877
network-mux,
856-
ouroboros-network:{api, framework, mock, protocols, tests-lib},
878+
ouroboros-network:{api, api-tests-lib, framework, mock, protocols, tests-lib},
857879
pipes,
858880
quickcheck-instances,
859881
serialise,
@@ -867,17 +889,11 @@ test-suite protocols-tests
867889
type: exitcode-stdio-1.0
868890
hs-source-dirs: protocols/tests
869891
main-is: Main.hs
870-
-- TODO: these two tests should be moved to `ouroboros-network:mock`
871-
other-modules:
872-
Test.AnchoredFragment
873-
Test.Chain
874892

875893
build-depends:
876-
QuickCheck ^>=2.16,
877894
base >=4.14 && <4.22,
878-
ouroboros-network:{api, mock, protocols-tests-lib, tests-lib},
895+
ouroboros-network:{protocols-tests-lib},
879896
tasty,
880-
tasty-quickcheck,
881897

882898
ghc-options:
883899
-threaded
@@ -906,7 +922,7 @@ test-suite protocols-cddl
906922
filepath,
907923
mtl,
908924
network,
909-
ouroboros-network:{api, framework, mock, protocols, protocols-tests-lib},
925+
ouroboros-network:{api, api-tests-lib, framework, protocols, protocols-tests-lib},
910926
process-extras,
911927
quickcheck-instances,
912928
serialise,
@@ -916,6 +932,7 @@ test-suite protocols-cddl
916932
temporary,
917933
text,
918934
typed-protocols:{typed-protocols, stateful},
935+
tasty-quickcheck,
919936

920937
ghc-options:
921938
-threaded
@@ -955,20 +972,12 @@ library mock
955972
visibility: public
956973
hs-source-dirs: mock
957974
exposed-modules:
958-
Ouroboros.Network.Mock.Chain
959-
Ouroboros.Network.Mock.ConcreteBlock
960975
Ouroboros.Network.Mock.ProducerState
961976

962977
build-depends:
963978
base >=4.14 && <4.22,
964-
bytestring,
965-
cborg,
966979
containers,
967-
hashable,
968-
nothunks,
969-
ouroboros-network:api,
970-
serialise,
971-
time,
980+
ouroboros-network:{api, api-tests-lib},
972981

973982
-- Simulation Test Library
974983
library ouroboros-network-tests-lib
@@ -997,7 +1006,7 @@ library ouroboros-network-tests-lib
9971006
network,
9981007
network-mux,
9991008
nothunks,
1000-
ouroboros-network:{ouroboros-network, api, cardano-diffusion, framework, framework-tests-lib, mock, orphan-instances, protocols, protocols-tests-lib, tests-lib},
1009+
ouroboros-network:{ouroboros-network, api, api-tests-lib, cardano-diffusion, framework, framework-tests-lib, mock, orphan-instances, protocols, protocols-tests-lib, tests-lib},
10011010
pipes,
10021011
pretty-simple,
10031012
psqueues,
@@ -1015,7 +1024,6 @@ library ouroboros-network-tests-lib
10151024
Ouroboros.Network.BlockFetch.Examples
10161025
Ouroboros.Network.MockNode
10171026
Test.Cardano.Network.OrphanInstances.Tests
1018-
Test.Cardano.Network.Version
10191027
Test.Ouroboros.Network.BlockFetch
10201028
Test.Ouroboros.Network.Diffusion.Node
10211029
Test.Ouroboros.Network.Diffusion.Node.ChainDB
@@ -1092,7 +1100,7 @@ test-suite ouroboros-network-io-tests
10921100
monoidal-synchronisation,
10931101
network,
10941102
network-mux,
1095-
ouroboros-network:{api, cardano-diffusion, framework, mock, protocols, protocols-tests-lib, tests-lib},
1103+
ouroboros-network:{api, api-tests-lib, cardano-diffusion, framework, mock, protocols, protocols-tests-lib, tests-lib},
10961104
serialise,
10971105
tasty,
10981106
tasty-quickcheck,
@@ -1127,7 +1135,7 @@ executable demo-chain-sync
11271135
io-classes:{si-timers, strict-stm},
11281136
network-mux,
11291137
optparse-applicative,
1130-
ouroboros-network:{ouroboros-network, api, cardano-diffusion, framework, mock, protocols},
1138+
ouroboros-network:{ouroboros-network, api, api-tests-lib, cardano-diffusion, framework, protocols},
11311139
random,
11321140
serialise,
11331141
typed-protocols,

ouroboros-network/protocols/cddl/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import Ouroboros.Network.Block (Point, SlotNo, Tip, decodeTip, encodeTip,
5959
unwrapCBORinCBOR, wrapCBORinCBOR)
6060
import Ouroboros.Network.CodecCBORTerm
6161
import Ouroboros.Network.Magic
62-
import Ouroboros.Network.Mock.ConcreteBlock qualified as Concrete (Block)
6362

6463
import Cardano.Network.NodeToClient.Version (NodeToClientVersion,
6564
NodeToClientVersionData (..), nodeToClientCodecCBORTerm)
@@ -113,7 +112,8 @@ import Ouroboros.Network.Protocol.PeerSharing.Codec (codecPeerSharing)
113112
import Ouroboros.Network.Protocol.PeerSharing.Test ()
114113
import Ouroboros.Network.Protocol.PeerSharing.Type qualified as PeerSharing
115114

116-
import Test.ChainGenerators ()
115+
import Ouroboros.Network.Mock.ChainGenerators ()
116+
import Ouroboros.Network.Mock.ConcreteBlock qualified as Concrete (Block)
117117
import Test.Data.CDDL (Any (..))
118118

119119
import Ouroboros.Network.PeerSelection.PeerSharing.Codec (decodeRemoteAddress,

ouroboros-network/protocols/tests-lib/Ouroboros/Network/Protocol/BlockFetch/Test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Ouroboros.Network.Block (Serialised (..), genesisPoint, unwrapCBORinCBOR,
3535

3636
import Ouroboros.Network.Mock.Chain (Chain, Point)
3737
import Ouroboros.Network.Mock.Chain qualified as Chain
38+
import Ouroboros.Network.Mock.ChainGenerators (TestChainAndPoints (..))
3839
import Ouroboros.Network.Mock.ConcreteBlock (Block)
3940

4041
import Ouroboros.Network.Protocol.BlockFetch.Client
@@ -45,7 +46,6 @@ import Ouroboros.Network.Protocol.BlockFetch.Server
4546
import Ouroboros.Network.Protocol.BlockFetch.Type
4647
import Test.Data.PipeliningDepth (PipeliningDepth (..))
4748

48-
import Test.ChainGenerators (TestChainAndPoints (..))
4949
import Test.Ouroboros.Network.Protocol.Utils (prop_codec_cborM,
5050
prop_codec_valid_cbor_encoding, splits2, splits3)
5151

0 commit comments

Comments
 (0)