6
6
{-# LANGUAGE KindSignatures #-}
7
7
{-# LANGUAGE RankNTypes #-}
8
8
{-# LANGUAGE ScopedTypeVariables #-}
9
+ {-# LANGUAGE FlexibleInstances #-}
9
10
10
11
-- | Smoke tests for the object diffusion protocol. This uses a trivial object
11
12
-- pool and checks that a few objects can indeed be transferred from the
@@ -14,6 +15,7 @@ module Test.Consensus.MiniProtocol.ObjectDiffusion.Smoke
14
15
( tests
15
16
, WithId (.. )
16
17
, ListWithUniqueIds (.. )
18
+ , ProtocolConstants
17
19
, prop_smoke_object_diffusion
18
20
) where
19
21
@@ -164,21 +166,30 @@ mkMockPoolInterfaces objects = do
164
166
165
167
-- Protocol constants
166
168
167
- maxFifoSize :: NumObjectsOutstanding
168
- maxFifoSize = NumObjectsOutstanding 10
169
-
170
- maxIdsToReq :: NumObjectIdsReq
171
- maxIdsToReq = NumObjectIdsReq 3
172
-
173
- maxObjectsToReq :: NumObjectsReq
174
- maxObjectsToReq = NumObjectsReq 2
169
+ newtype ProtocolConstants
170
+ = ProtocolConstants (NumObjectsOutstanding , NumObjectIdsReq , NumObjectsReq )
171
+ deriving (Show )
172
+
173
+ instance Arbitrary ProtocolConstants
174
+ -- REVIEW: not sure about those constraints at all, and don't have the
175
+ -- brainspace right now to reason about them
176
+ arbitrary = do
177
+ maxFifoSize <- choose (5 , 20 )
178
+ maxIdsToReq <- choose (3 , maxFifoSize )
179
+ maxObjectsToReq <- choose (2 , maxIdsToReq )
180
+ pure $
181
+ ProtocolConstants
182
+ ( NumObjectsOutstanding maxFifoSize ,
183
+ NumObjectIdsReq maxIdsToReq ,
184
+ NumObjectsReq maxObjectsToReq
185
+ )
175
186
176
187
nodeToNodeVersion :: NodeToNodeVersion
177
188
nodeToNodeVersion = NodeToNodeV_14
178
189
179
- prop_smoke_init_inbound :: ListWithUniqueIds SmokeObject idTy -> Property
180
- prop_smoke_init_inbound (ListWithUniqueIds objects) =
181
- prop_smoke_object_diffusion objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
190
+ prop_smoke_init_inbound :: ProtocolConstants -> ListWithUniqueIds SmokeObject idTy -> Property
191
+ prop_smoke_init_inbound protocolConstants (ListWithUniqueIds objects) =
192
+ prop_smoke_object_diffusion protocolConstants objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
182
193
where
183
194
runOutboundPeer outbound outboundChannel tracer =
184
195
runPeer
@@ -196,9 +207,9 @@ prop_smoke_init_inbound (ListWithUniqueIds objects) =
196
207
(objectDiffusionInboundClientPeerPipelined inbound)
197
208
>> pure ()
198
209
199
- prop_smoke_init_outbound :: ListWithUniqueIds SmokeObject SmokeObjectId -> Property
200
- prop_smoke_init_outbound (ListWithUniqueIds objects) =
201
- prop_smoke_object_diffusion objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
210
+ prop_smoke_init_outbound :: ProtocolConstants -> ListWithUniqueIds SmokeObject SmokeObjectId -> Property
211
+ prop_smoke_init_outbound protocolConstants (ListWithUniqueIds objects) =
212
+ prop_smoke_object_diffusion protocolConstants objects runOutboundPeer runInboundPeer (mkMockPoolInterfaces objects)
202
213
where
203
214
runOutboundPeer outbound outboundChannel tracer =
204
215
runPeer
@@ -226,6 +237,7 @@ prop_smoke_object_diffusion ::
226
237
, NoThunks object
227
238
, Ord ticketNo
228
239
) =>
240
+ ProtocolConstants ->
229
241
[object ] ->
230
242
( forall m .
231
243
IOLike m =>
@@ -250,7 +262,10 @@ prop_smoke_object_diffusion ::
250
262
)
251
263
) ->
252
264
Property
253
- prop_smoke_object_diffusion objects runOutboundPeer runInboundPeer mkPoolInterfaces =
265
+ prop_smoke_object_diffusion
266
+ (ProtocolConstants (maxFifoSize, maxIdsToReq, maxObjectsToReq))
267
+ objects runOutboundPeer runInboundPeer mkPoolInterfaces
268
+ =
254
269
let
255
270
simulationResult = runSimStrictShutdown $ do
256
271
let tracer = nullTracer
0 commit comments