Skip to content

Commit

Permalink
Actually generate honest peers in CSJ happy path
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols authored and nbacquey committed May 7, 2024
1 parent 5b76f54 commit 27e877f
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Test.Consensus.Genesis.Tests.CSJ (tests) where

import Control.Monad (replicateM)
import Data.Containers.ListUtils (nubOrd)
import Data.Functor (($>))
import Data.List (nub)
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe)
Expand Down Expand Up @@ -63,14 +62,8 @@ tests =
prop_happyPath :: Bool -> Property
prop_happyPath synchronized =
forAllGenesisTest
( do
gt <- genChains $ pure 0
honest <- genHonestSchedule gt
numOthers <- choose (1, 3)
otherHonests <- if synchronized
then pure $ replicate numOthers honest
else replicateM numOthers (genHonestSchedule gt)
pure $ gt $> peers' [honest] otherHonests
( genChains (pure 0) `enrichedWith`
((=<< choose (2, 4)) . genHonestSchedules)
)
( defaultSchedulerConfig
{ scEnableCSJ = True
Expand Down Expand Up @@ -119,10 +112,17 @@ prop_happyPath synchronized =
-- | 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)
genHonestSchedules :: GenesisTest TestBlock () -> Int -> Gen (PeersSchedule TestBlock)
genHonestSchedules gt numberOfPeers = do
schedule <- genHonestSchedule gt
otherSchedules <- if synchronized
then pure $ replicate numberOfPeers schedule
else replicateM numberOfPeers (genHonestSchedule gt)
pure $ peers' (schedule : otherSchedules) []

genHonestSchedule gt = do
ps <- genUniformSchedulePoints gt
pure $ honestPeers ps Map.! 1
Peers {honestPeers} <- genUniformSchedulePoints gt
pure $ honestPeers Map.! 1

isNewerThanJumpSizeFromTip :: GenesisTestFull TestBlock -> Header TestBlock -> Bool
isNewerThanJumpSizeFromTip gt hdr =
Expand Down

0 comments on commit 27e877f

Please sign in to comment.