Skip to content

Commit c4959e2

Browse files
committed
fixup! Add tests for PerasWeightSnapshot
1 parent 28e845e commit c4959e2

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ prop_perasWeightSnapshot testSetup =
5151
| pt <- tsPoints
5252
]
5353
, conjoin
54-
[ counterexample ("Incorrect weight for " <> condense frag) $
55-
weightBoostOfFragmentReference frag =:= weightBoostOfFragment snap frag
54+
[ conjoin
55+
[ counterexample ("Incorrect weight for " <> condense frag) $
56+
weightBoostOfFragmentReference frag =:= weightBoostOfFragment snap frag
57+
, counterexample ("Weight not inductively consistent for " <> condense frag) $
58+
prop_fragmentInduction snap frag
59+
]
5660
| frag <- tsFragments
5761
]
5862
]
@@ -74,6 +78,31 @@ prop_perasWeightSnapshot testSetup =
7478
(weightBoostOfPointReference . blockPoint)
7579
(AF.toOldestFirst frag)
7680

81+
-- | Test that the weight of a fragment is equal to the weight of its
82+
-- first\/last point plus the weight of the remaining suffix\/infix.
83+
prop_fragmentInduction ::
84+
PerasWeightSnapshot TestBlock ->
85+
AnchoredFragment TestBlock ->
86+
Property
87+
prop_fragmentInduction snap =
88+
\frag -> fromLeft frag .&&. fromRight frag
89+
where
90+
fromLeft :: AnchoredFragment TestBlock -> Property
91+
fromLeft frag = case frag of
92+
AF.Empty _ ->
93+
weightBoostOfFragment snap frag === mempty
94+
b AF.:< frag' ->
95+
weightBoostOfFragment snap frag
96+
=== weightBoostOfPoint snap (blockPoint b) <> weightBoostOfFragment snap frag'
97+
98+
fromRight :: AnchoredFragment TestBlock -> Property
99+
fromRight frag = case frag of
100+
AF.Empty _ ->
101+
weightBoostOfFragment snap frag === mempty
102+
frag' AF.:> b ->
103+
weightBoostOfFragment snap frag
104+
=== weightBoostOfPoint snap (blockPoint b) <> weightBoostOfFragment snap frag'
105+
77106
data TestSetup = TestSetup
78107
{ tsWeights :: Map (Point TestBlock) PerasWeight
79108
, tsPoints :: [Point TestBlock]

0 commit comments

Comments
 (0)