Skip to content

Commit

Permalink
Merge #3742
Browse files Browse the repository at this point in the history
3742: ChainSync client test: model pipelining behavior r=amesgen a=amesgen

Closes [CAD-4192](https://input-output.atlassian.net/browse/CAD-4192)

Co-authored-by: Alexander Esgen <alexander.esgen@iohk.io>
  • Loading branch information
iohk-bors[bot] and amesgen authored May 18, 2022
2 parents fde5329 + 50d8047 commit 370d90b
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 96 deletions.
15 changes: 10 additions & 5 deletions ouroboros-consensus-test/src/Test/Util/TestBlock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ module Test.Util.TestBlock (
, Header (..)
, StorageConfig (..)
, TestBlockError (..)
, TestBlockWith (tbPayload)
, TestBlockWith (tbPayload, tbValid)
, TestHash (TestHash)
, Validity (..)
, firstBlockWithPayload
, forkBlock
, modifyFork
Expand Down Expand Up @@ -182,6 +183,10 @@ instance Show TestHash where
instance Condense TestHash where
condense = condense . reverse . NE.toList . unTestHash

data Validity = Valid | Invalid
deriving stock (Show, Eq, Ord, Enum, Bounded, Generic)
deriving anyclass (Serialise, NoThunks, ToExpr)

-- | Test block parametrized on the payload type
--
-- For blocks without payload see the 'TestBlock' type alias.
Expand All @@ -197,7 +202,7 @@ data TestBlockWith ptype = TestBlockWith {
--
-- Note that when generating a 'TestBlock', you must make sure that
-- blocks with the same 'TestHash' have the same slot number.
, tbValid :: Bool
, tbValid :: Validity
-- ^ Note that when generating a 'TestBlock', you must make sure that
-- blocks with the same 'TestHash' have the same value for 'tbValid'.
, tbPayload :: ptype
Expand All @@ -211,7 +216,7 @@ firstBlockWithPayload :: Word64 -> ptype -> TestBlockWith ptype
firstBlockWithPayload forkNo payload = TestBlockWith
{ tbHash = TestHash (forkNo NE.:| [])
, tbSlot = 1
, tbValid = True
, tbValid = Valid
, tbPayload = payload
}

Expand All @@ -224,7 +229,7 @@ successorBlockWithPayload ::
successorBlockWithPayload hash slot payload = TestBlockWith
{ tbHash = TestHash (NE.cons 0 (unTestHash hash))
, tbSlot = succ slot
, tbValid = True
, tbValid = Valid
, tbPayload = payload
}

Expand Down Expand Up @@ -414,7 +419,7 @@ instance PayloadSemantics ptype
applyBlockLedgerResult _ tb@TestBlockWith{..} (TickedTestLedger TestLedger{..})
| blockPrevHash tb /= pointHash lastAppliedPoint
= throwError $ InvalidHash (pointHash lastAppliedPoint) (blockPrevHash tb)
| not tbValid
| tbValid == Invalid
= throwError $ InvalidBlock
| otherwise
= case applyPayload payloadDependentState tbPayload of
Expand Down
Loading

0 comments on commit 370d90b

Please sign in to comment.