Skip to content

Commit

Permalink
test-infra: pass block number of the first proper block to prop_general
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Feb 27, 2020
1 parent 9100b9b commit 48babe5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions ouroboros-consensus-byron/test/Test/ThreadNet/DualPBFT.hs
Expand Up @@ -84,6 +84,7 @@ prop_convergence setup = withMaxSuccess 10 $
Ref.Forked{} -> 1
_ -> 0)
(setupExpectedRejections setup)
1
(setupTestOutput setup)
where
cfg = setupConfig setup
Expand Down
37 changes: 37 additions & 0 deletions ouroboros-consensus-byron/test/Test/ThreadNet/RealPBFT.hs
Expand Up @@ -384,6 +384,42 @@ tests = testGroup "RealPBFT" $
, slotLengths = defaultSlotLengths
, initSeed = Seed {getSeed = (13428626417421372024,5113871799759534838,13943132470772613446,18226529569527889118,4309403968134095151)}
}
, testProperty "mkDelegationEnvironment uses currentSlot not latestSlot" $
-- After rekeying, node 2 continues to emit its dlg cert tx. This an ugly
-- implementation detail of rekeying, but as a nice surprise it found a
-- bug!
--
-- In slot 40, node 1 forged a block that included the now-/expired/ dlg
-- cert tx (cf @WrongEpoch@). This happened because the Byron transaction
-- validation logic was using the slot of the latest block (i.e. 39) as
-- the current slot (i.e. actually 40), so the transaction wasn't
-- identified as expired until it was already inside a block.
once $
let ncn = NumCoreNodes 3 in
prop_simple_real_pbft_convergence
NoEBBs
SecurityParam {maxRollbacks = 2}
TestConfig
{ numCoreNodes = ncn
, numSlots = NumSlots 41
, nodeJoinPlan = trivialNodeJoinPlan ncn
, nodeRestarts = NodeRestarts $ Map.singleton (SlotNo 30) $ Map.singleton (CoreNodeId 2) NodeRekey
, nodeTopology = meshNodeTopology ncn
, slotLengths = defaultSlotLengths
, initSeed = Seed (368401128646137767,7989071211759985580,4921478144180472393,11759221144888418607,7602439127562955319)
}
, testProperty "delayed message corner case" $
once $
let ncn = NumCoreNodes 2 in
prop_simple_real_pbft_convergence NoEBBs (SecurityParam 7) TestConfig
{ numCoreNodes = ncn
, numSlots = NumSlots 10
, nodeJoinPlan = NodeJoinPlan (Map.fromList [(CoreNodeId 0,SlotNo {unSlotNo = 0}),(CoreNodeId 1,SlotNo {unSlotNo = 1})])
, nodeRestarts = noRestarts
, nodeTopology = meshNodeTopology ncn
, slotLengths = defaultSlotLengths
, initSeed = Seed (11954171112552902178,1213614443200450055,13600682863893184545,15433529895532611662,2464843772450023204)
}
, testProperty "simple convergence" $
\produceEBBs ->
-- TODO k > 1 as a workaround for Issue #1511.
Expand Down Expand Up @@ -531,6 +567,7 @@ prop_simple_real_pbft_convergence produceEBBs k
Ref.Forked{} -> 1
_ -> 0)
(expectedBlockRejection k numCoreNodes nodeRestarts)
1
testOutput .&&.
not (all (Chain.null . snd) finalChains) .&&.
conjoin (map (hasAllEBBs k numSlots produceEBBs) finalChains)
Expand Down
Expand Up @@ -4,24 +4,47 @@ module Test.ThreadNet.BFT (
tests
) where

import qualified Data.Map as Map
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.QuickCheck

import Cardano.Slotting.Slot (SlotNo (..))

import Ouroboros.Consensus.BlockchainTime
import Ouroboros.Consensus.BlockchainTime.Mock
import Ouroboros.Consensus.Mock.Ledger
import Ouroboros.Consensus.Mock.Node ()
import Ouroboros.Consensus.Mock.Node.BFT
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Util.Random (Seed (..))

import Test.ThreadNet.General
import Test.ThreadNet.TxGen.Mock ()
import Test.ThreadNet.Util
import Test.ThreadNet.Util.NodeJoinPlan
import Test.ThreadNet.Util.NodeRestarts
import Test.ThreadNet.Util.NodeTopology

import Test.Util.Orphans.Arbitrary ()

tests :: TestTree
tests = testGroup "BFT" [
tests = testGroup "BFT"
[ testProperty "delayed message corner case" $
once $
let ncn = NumCoreNodes 2 in
prop_simple_bft_convergence (SecurityParam 3) TestConfig
{ numCoreNodes = ncn
, numSlots = NumSlots 3
, nodeJoinPlan = NodeJoinPlan (Map.fromList [(CoreNodeId 0,SlotNo {unSlotNo = 0}),(CoreNodeId 1,SlotNo {unSlotNo = 1})])
, nodeRestarts = noRestarts
, nodeTopology = meshNodeTopology ncn
, slotLengths = singletonSlotLengths (slotLengthFromSec 1)
, initSeed = Seed {getSeed = (12659702313441544615,9326820694273232011,15820857683988100572,2201554969601311572,4716411940989238571)}
}
,
testProperty "simple convergence" $ \tc ->
forAll (SecurityParam <$> elements [2 .. 10]) $ \k ->
prop_simple_bft_convergence k tc
Expand All @@ -40,6 +63,7 @@ prop_simple_bft_convergence k
(Just $ roundRobinLeaderSchedule numCoreNodes numSlots)
Nothing
(const False)
0
testOutput
where
testOutput =
Expand Down
Expand Up @@ -95,6 +95,7 @@ prop_simple_leader_schedule_convergence
(Just schedule)
Nothing
(const False)
0
testOutput
where
testOutput@TestOutput{testOutputNodes} =
Expand Down
Expand Up @@ -61,6 +61,7 @@ prop_simple_pbft_convergence
Ref.Forked{} -> 1
_ -> 0)
(expectedBlockRejection numCoreNodes)
0
testOutput
where
NumCoreNodes nn = numCoreNodes
Expand Down
Expand Up @@ -100,6 +100,7 @@ prop_simple_praos_convergence
Nothing
Nothing
(const False)
0
testOutput
where
testOutput@TestOutput{testOutputNodes} =
Expand Down
Expand Up @@ -280,10 +280,12 @@ prop_general ::
-> Maybe LeaderSchedule
-> Maybe NumBlocks
-> (BlockRejection blk -> Bool)
-> BlockNo
-- ^ block number of the first proper block after genesis
-> TestOutput blk
-> Property
prop_general countTxs k TestConfig{numSlots, nodeJoinPlan, nodeRestarts, nodeTopology}
mbSchedule mbMaxForkLength expectedBlockRejection
mbSchedule mbMaxForkLength expectedBlockRejection firstBlockNo
TestOutput{testOutputNodes, testOutputTipBlockNos} =
counterexample ("nodeChains: " <> unlines ("" : map (\x -> " " <> condense x) (Map.toList nodeChains))) $
counterexample ("nodeJoinPlan: " <> condense nodeJoinPlan) $
Expand Down Expand Up @@ -581,7 +583,7 @@ prop_general countTxs k TestConfig{numSlots, nodeJoinPlan, nodeRestarts, nodeTop
--
-- NOTE This predicate is more general than that specific scenario,
-- but we don't anticipate it wholly masking any interesting cases.
delayOK1 = 1 == bno
delayOK1 = firstBlockNo == bno

-- When a slot has multiple leaders, each node chooses one of the
-- mutually-exclusive forged blocks and won't fetch any of the
Expand Down

0 comments on commit 48babe5

Please sign in to comment.