module Test.ThreadNet.Util.Tests (tests) where

import           Ouroboros.Consensus.Config.SecurityParam
import           Ouroboros.Consensus.Node.ProtocolInfo (NumCoreNodes (..))
import           Test.Tasty
import           Test.Tasty.QuickCheck
import           Test.ThreadNet.Util
import           Test.ThreadNet.Util.NodeJoinPlan (trivialNodeJoinPlan)
import           Test.Util.Orphans.Arbitrary ()
import           Test.Util.Slots (NumSlots (..))

tests :: TestTree
tests :: TestTree
tests = TestName -> [TestTree] -> TestTree
testGroup TestName
"Test.ThreadNet.Util.Tests" ([TestTree] -> TestTree) -> [TestTree] -> TestTree
forall a b. (a -> b) -> a -> b
$
    [ TestName -> (NumCoreNodes -> NumSlots -> Property) -> TestTree
forall a. Testable a => TestName -> a -> TestTree
testProperty TestName
"0 = determineForkLength roundRobinLeaderSchedule" ((NumCoreNodes -> NumSlots -> Property) -> TestTree)
-> (NumCoreNodes -> NumSlots -> Property) -> TestTree
forall a b. (a -> b) -> a -> b
$
          SecurityParam -> NumCoreNodes -> NumSlots -> Property
prop_roundRobin_forkLength SecurityParam
securityParam
    ]
  where
    securityParam :: SecurityParam
securityParam = Word64 -> SecurityParam
SecurityParam Word64
5

-- | A round-robin schedule should reach consensus
prop_roundRobin_forkLength ::
    SecurityParam -> NumCoreNodes -> NumSlots -> Property
prop_roundRobin_forkLength :: SecurityParam -> NumCoreNodes -> NumSlots -> Property
prop_roundRobin_forkLength SecurityParam
k NumCoreNodes
numCoreNodes NumSlots
numSlots =
  SecurityParam -> NodeJoinPlan -> LeaderSchedule -> NumBlocks
determineForkLength SecurityParam
k NodeJoinPlan
nodeJoinPlan LeaderSchedule
schedule NumBlocks -> NumBlocks -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Word64 -> NumBlocks
NumBlocks Word64
0
  where
    nodeJoinPlan :: NodeJoinPlan
nodeJoinPlan = NumCoreNodes -> NodeJoinPlan
trivialNodeJoinPlan NumCoreNodes
numCoreNodes
    schedule :: LeaderSchedule
schedule = NumCoreNodes -> NumSlots -> LeaderSchedule
roundRobinLeaderSchedule NumCoreNodes
numCoreNodes NumSlots
numSlots