Skip to content

Commit fbab925

Browse files
committed
Generate protocol parameters randomly
1 parent 9af2c9c commit fbab925

File tree

2 files changed

+34
-18
lines changed
  • ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion

2 files changed

+34
-18
lines changed

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion/PerasCert/Smoke.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Ouroboros.Network.Protocol.ObjectDiffusion.Inbound
3333
import Ouroboros.Network.Protocol.ObjectDiffusion.Outbound (objectDiffusionOutboundClientPeer)
3434
import Test.Consensus.MiniProtocol.ObjectDiffusion.Smoke
3535
( ListWithUniqueIds (..)
36+
, ProtocolConstants
3637
, WithId
3738
, getId
3839
, prop_smoke_object_diffusion
@@ -85,9 +86,9 @@ newCertDB certs = do
8586
certs
8687
pure db
8788

88-
prop_smoke :: ListWithUniqueIds (PerasCert TestBlock) PerasRoundNo -> Property
89-
prop_smoke (ListWithUniqueIds certs) =
90-
prop_smoke_object_diffusion certs runOutboundPeer runInboundPeer mkPoolInterfaces
89+
prop_smoke :: ProtocolConstants -> ListWithUniqueIds (PerasCert TestBlock) PerasRoundNo -> Property
90+
prop_smoke protocolConstants (ListWithUniqueIds certs) =
91+
prop_smoke_object_diffusion protocolConstants certs runOutboundPeer runInboundPeer mkPoolInterfaces
9192
where
9293
runOutboundPeer outbound outboundChannel tracer =
9394
runPeer

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion/Smoke.hs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE KindSignatures #-}
77
{-# LANGUAGE RankNTypes #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
9+
{-# LANGUAGE FlexibleInstances #-}
910

1011
-- | Smoke tests for the object diffusion protocol. This uses a trivial object
1112
-- pool and checks that a few objects can indeed be transferred from the
@@ -14,6 +15,7 @@ module Test.Consensus.MiniProtocol.ObjectDiffusion.Smoke
1415
( tests
1516
, WithId (..)
1617
, ListWithUniqueIds (..)
18+
, ProtocolConstants
1719
, prop_smoke_object_diffusion
1820
) where
1921

@@ -164,21 +166,30 @@ mkMockPoolInterfaces objects = do
164166

165167
-- Protocol constants
166168

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+
)
175186

176187
nodeToNodeVersion :: NodeToNodeVersion
177188
nodeToNodeVersion = NodeToNodeV_14
178189

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)
182193
where
183194
runOutboundPeer outbound outboundChannel tracer =
184195
runPeer
@@ -196,9 +207,9 @@ prop_smoke_init_inbound (ListWithUniqueIds objects) =
196207
(objectDiffusionInboundClientPeerPipelined inbound)
197208
>> pure ()
198209

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)
202213
where
203214
runOutboundPeer outbound outboundChannel tracer =
204215
runPeer
@@ -226,6 +237,7 @@ prop_smoke_object_diffusion ::
226237
, NoThunks object
227238
, Ord ticketNo
228239
) =>
240+
ProtocolConstants ->
229241
[object] ->
230242
( forall m.
231243
IOLike m =>
@@ -250,7 +262,10 @@ prop_smoke_object_diffusion ::
250262
)
251263
) ->
252264
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+
=
254269
let
255270
simulationResult = runSimStrictShutdown $ do
256271
let tracer = nullTracer

0 commit comments

Comments
 (0)