-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Tests/CSJ.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module Test.Consensus.Genesis.Tests.CSJ (tests) where | ||
|
||
import Control.Monad (replicateM) | ||
import Data.Functor (($>)) | ||
import Test.Consensus.Genesis.Setup | ||
import Test.Consensus.Genesis.Tests.Uniform (genUniformSchedulePoints) | ||
import Test.Consensus.PeerSimulator.Run (SchedulerConfig (..), | ||
defaultSchedulerConfig) | ||
import Test.Consensus.PeerSimulator.StateView | ||
import Test.Consensus.PointSchedule | ||
import Test.Consensus.PointSchedule.Peers (Peers (..), Peer(..), mkPeers) | ||
import Test.Consensus.PointSchedule.Shrinking (shrinkPeerSchedules) | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import Test.Util.Orphans.IOLike () | ||
import Test.Util.TestBlock (TestBlock) | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup | ||
"CSJ" | ||
[ testProperty "\"Happy Path\" synchronous scenario only speaks to one peer" $ prop_happyPath True | ||
, testProperty "\"Happy Path\" asynchronous scenario only speaks to one peer" $ prop_happyPath False | ||
] | ||
|
||
prop_happyPath :: Bool -> Property | ||
prop_happyPath synchronized = | ||
forAllGenesisTest | ||
( do | ||
gt <- genChains $ pure 0 | ||
honest <- genHonestSchedule gt | ||
numOthers <- choose (0, 3) | ||
otherHonests <- if synchronized | ||
then pure $ replicate numOthers honest | ||
else replicateM numOthers (genHonestSchedule gt) | ||
pure $ gt $> mkPeers honest otherHonests | ||
) | ||
( defaultSchedulerConfig | ||
{ scEnableCSJ = True | ||
, scEnableLoE = True | ||
, scEnableLoP = True | ||
} | ||
) | ||
shrinkPeerSchedules | ||
( \_ stateView -> (undefined :: Bool) -- do magic | ||
) | ||
where | ||
-- | This might seem wasteful, as we discard generated adversarial schedules. | ||
-- It actually isn't, since we call it on trees that have no branches besides | ||
-- the trunk, so no adversaries are generated. | ||
genHonestSchedule :: GenesisTest TestBlock () -> Gen (PeerSchedule TestBlock) | ||
genHonestSchedule gt = do | ||
ps <- genUniformSchedulePoints gt | ||
pure $ value $ honest ps | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters