1
1
{-# LANGUAGE LambdaCase #-}
2
+ {-# LANGUAGE NamedFieldPuns #-}
2
3
{-# LANGUAGE ScopedTypeVariables #-}
3
4
4
5
module Test.Cardano.Ledger.Conway.Proposals where
@@ -10,6 +11,7 @@ import Control.Exception (AssertionFailed (..), evaluate)
10
11
import Data.Either (isRight )
11
12
import Data.Foldable as F (foldl' , toList )
12
13
import qualified Data.Map.Strict as Map
14
+ import Data.MapExtras (fromElems )
13
15
import Data.Maybe (fromMaybe )
14
16
import Data.Sequence (fromList )
15
17
import qualified Data.Sequence as Seq
@@ -51,33 +53,50 @@ spec = do
51
53
`shouldThrow` \ AssertionFailed {} -> True
52
54
describe " Enactment" $ do
53
55
prop " Adding votes preserves consistency" $
54
- \ (ProposalsForEnactment ps gass _ :: ProposalsForEnactment Conway , voter :: Voter era , vote :: Vote ) -> do
55
- case gass of
56
- gas Seq. :<| _gass -> isRight . toGovRelationTreeEither $ proposalsAddVote voter vote (gasId gas) ps
57
- _ -> True
56
+ \ ( ProposalsForEnactment {pfeProposals, pfeToEnact} :: ProposalsForEnactment Conway
57
+ , voter :: Voter era
58
+ , vote :: Vote
59
+ ) -> do
60
+ case pfeToEnact of
61
+ gas Seq. :<| _gass -> isRight . toGovRelationTreeEither $ proposalsAddVote voter vote (gasId gas) pfeProposals
62
+ _ -> True
58
63
prop " Enacting exhaustive lineages reduces Proposals to their roots" $
59
- \ (ProposalsForEnactment ps gass _ :: ProposalsForEnactment Conway ) -> do
60
- let toEnact = Set. fromList $ toList gass
61
- (_ps', enactedRemoved, expiredRemoved) = proposalsApplyEnactment gass Set. empty ps
62
- expiredRemoved `shouldSatisfy` Map. null
63
- toEnact `shouldSatisfy` (`Set.isSubsetOf` Set. fromList (Map. elems enactedRemoved))
64
+ \ ( ProposalsForEnactment {pfeProposals, pfeToEnact, pfeToRemove, pfeToRetain} ::
65
+ ProposalsForEnactment Conway
66
+ ) -> do
67
+ let (ps', enacted, removedDueToEnactment, expiredRemoved) = proposalsApplyEnactment pfeToEnact Set. empty pfeProposals
68
+ expiredRemoved `shouldSatisfy` Map. null
69
+ enacted `shouldBe` fromElems gasId pfeToEnact
70
+ Map. keysSet removedDueToEnactment `shouldBe` pfeToRemove
71
+ proposalsSize ps' `shouldBe` Set. size pfeToRetain
64
72
prop " Enacting non-member nodes throws an AssertionFailure" $
65
73
\ (ProposalsNewActions ps actions :: ProposalsNewActions Conway ) ->
66
74
(evaluate . force) (proposalsApplyEnactment (fromList actions) Set. empty ps)
67
75
`shouldThrow` \ AssertionFailed {} -> True
68
76
prop " Expiring compliments of exhaustive lineages keeps proposals consistent" $
69
- \ (ProposalsForEnactment ps _ gais :: ProposalsForEnactment Conway ) -> do
70
- let (_ps', enactedRemoved, expiredRemoved) = proposalsApplyEnactment Seq. Empty gais ps
71
- enactedRemoved `shouldSatisfy` Map. null
72
- gais `shouldSatisfy` (`Set.isSubsetOf` Map. keysSet expiredRemoved)
77
+ \ ( ProposalsForEnactment {pfeProposals, pfeToEnact, pfeToRemove, pfeToRetain} ::
78
+ ProposalsForEnactment Conway
79
+ ) -> do
80
+ let (ps', enacted, removedDueToEnactment, expiredRemoved) =
81
+ proposalsApplyEnactment Seq. Empty pfeToRemove pfeProposals
82
+ enacted `shouldBe` mempty
83
+ removedDueToEnactment `shouldBe` mempty
84
+ Map. keysSet expiredRemoved `shouldBe` pfeToRemove
85
+ ps' `shouldBe` fst (proposalsRemoveWithDescendants pfeToRemove pfeProposals)
86
+ let enactMap = fromElems gasId pfeToEnact
87
+ let (emptyProposals, enactedMap) = proposalsRemoveWithDescendants (Map. keysSet enactMap) ps'
88
+ proposalsSize emptyProposals `shouldBe` Set. size pfeToRetain
89
+ enactedMap `shouldBe` enactMap
73
90
prop " Expiring non-member nodes throws an AssertionFailure" $
74
91
\ (ProposalsNewActions ps actions :: ProposalsNewActions Conway ) ->
75
92
(evaluate . force) (proposalsApplyEnactment Seq. Empty (Set. fromList $ gasId <$> actions) ps)
76
93
`shouldThrow` \ AssertionFailed {} -> True
77
- prop " Enacting and expiring exhaustive lineages reduces Proposals to their roots" $
78
- \ (ProposalsForEnactment ps toEnact toExpire :: ProposalsForEnactment Conway ) -> do
79
- let (ps', enactedRemoved, expiredRemoved) = proposalsApplyEnactment toEnact toExpire ps
80
- Set. fromList (toList toEnact)
81
- `shouldSatisfy` (`Set.isSubsetOf` Set. fromList (Map. elems enactedRemoved))
82
- Set. fromList (toList toExpire) `shouldSatisfy` (`Set.isSubsetOf` Map. keysSet expiredRemoved)
83
- proposalsSize ps' `shouldBe` 0
94
+ prop " Enacting and expiring conflicting proposals does not lead to removal due to enactment" $
95
+ \ ( ProposalsForEnactment {pfeProposals, pfeToEnact, pfeToRemove, pfeToRetain} ::
96
+ ProposalsForEnactment Conway
97
+ ) -> do
98
+ let (ps', enacted, enactedRemoved, expiredRemoved) = proposalsApplyEnactment pfeToEnact pfeToRemove pfeProposals
99
+ Map. keysSet expiredRemoved `shouldBe` pfeToRemove
100
+ enactedRemoved `shouldBe` mempty
101
+ enacted `shouldBe` fromElems gasId pfeToEnact
102
+ proposalsSize ps' `shouldBe` Set. size pfeToRetain
0 commit comments