-
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.
Share partial accessor functions used in tests
- Loading branch information
Showing
5 changed files
with
41 additions
and
35 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
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
32 changes: 32 additions & 0 deletions
32
ouroboros-consensus-diffusion/test/consensus-test/Test/Util/PartialAccessors.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,32 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
-- | Helpers to access particular parts of trees and schedules | ||
-- Those functions are partial, and are designed to only be used in tests. | ||
-- We know they won't fail there, because we generated the structures | ||
-- with the correct properties. | ||
module Test.Util.PartialAccessors ( | ||
getOnlyBranch | ||
, getOnlyBranchTip | ||
, getTrunkTip | ||
) where | ||
|
||
import qualified Ouroboros.Network.AnchoredFragment as AF | ||
import Ouroboros.Network.Block (HasHeader) | ||
import Test.Consensus.BlockTree | ||
|
||
getOnlyBranch :: BlockTree blk -> BlockTreeBranch blk | ||
getOnlyBranch BlockTree {btBranches} = case btBranches of | ||
[branch] -> branch | ||
_ -> error "tree must have exactly one alternate branch" | ||
|
||
getTrunkTip :: HasHeader blk => BlockTree blk -> blk | ||
getTrunkTip tree = case btTrunk tree of | ||
(AF.Empty _) -> error "tree must have at least one block" | ||
(_ AF.:> tipBlock) -> tipBlock | ||
|
||
getOnlyBranchTip :: HasHeader blk => BlockTree blk -> blk | ||
getOnlyBranchTip BlockTree {btBranches} = case btBranches of | ||
[branch] -> case btbFull branch of | ||
(AF.Empty _) -> error "alternate branch must have at least one block" | ||
(_ AF.:> tipBlock) -> tipBlock | ||
_ -> error "tree must have exactly one alternate branch" |