{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Test.Cardano.Ledger.Api.State.QuerySpec (spec) where
import Cardano.Ledger.Api.State.Query (
CommitteeMemberState (..),
CommitteeMembersState (..),
HotCredAuthStatus (..),
MemberStatus (..),
NextEpochChange (..),
filterStakePoolDelegsAndRewards,
getNextEpochCommitteeMembers,
queryCommitteeMembersState,
)
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.CertState
import Cardano.Ledger.Coin (CompactForm (CompactCoin))
import Cardano.Ledger.Conway (Conway)
import Cardano.Ledger.Conway.Governance (
Committee (..),
ConwayEraGov (..),
ConwayGovState,
DRepPulsingState (..),
RatifyState (..),
ensCommitteeL,
newEpochStateDRepPulsingStateL,
rsEnactStateL,
)
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Keys (KeyRole (..))
import Cardano.Ledger.PoolDistr
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.UMap (UMap)
import Data.Default (Default (..))
import Data.Foldable (foldMap')
import qualified Data.Map.Strict as Map
import Data.Maybe (isNothing)
import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro ((&), (.~), (^.))
import Test.Cardano.Ledger.Api.Arbitrary ()
import Test.Cardano.Ledger.Api.State.Query
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary (genValidUMapWithCreds)
import Test.Cardano.Ledger.Shelley.Arbitrary ()
import Test.Cardano.Slotting.Numeric ()
spec :: Spec
spec :: Spec
spec = do
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"GetFilteredDelegationsAndRewardAccounts" forall a b. (a -> b) -> a -> b
$ do
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"filterStakePoolDelegsAndRewards same as getFilteredDelegationsAndRewardAccounts" forall a b. (a -> b) -> a -> b
$
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (UMap StandardCrypto, Set (Credential 'Staking StandardCrypto))
genValidUMapWithCreds forall a b. (a -> b) -> a -> b
$ \(UMap StandardCrypto
umap :: UMap StandardCrypto, Set (Credential 'Staking StandardCrypto)
creds) ->
forall c.
UMap c
-> Set (Credential 'Staking c)
-> (Map (Credential 'Staking c) (KeyHash 'StakePool c),
Map (Credential 'Staking c) Coin)
filterStakePoolDelegsAndRewards UMap StandardCrypto
umap Set (Credential 'Staking StandardCrypto)
creds
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` forall c.
UMap c
-> Set (Credential 'Staking c)
-> (Map (Credential 'Staking c) (KeyHash 'StakePool c),
Map (Credential 'Staking c) Coin)
getFilteredDelegationsAndRewardAccounts UMap StandardCrypto
umap Set (Credential 'Staking StandardCrypto)
creds
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"GetCommitteeMembersState" forall a b. (a -> b) -> a -> b
$ do
forall era.
(ConwayEraGov era, EraTxOut era, Default (EpochState era),
Default (StashedAVVMAddresses era),
GovState era ~ ConwayGovState era) =>
Spec
committeeMembersStateSpec @Conway
committeeMembersStateSpec ::
forall era.
( ConwayEraGov era
, EraTxOut era
, Default (EpochState era)
, Default (StashedAVVMAddresses era)
, GovState era ~ ConwayGovState era
) =>
Spec
=
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"CommitteeMembersState Query" forall a b. (a -> b) -> a -> b
$ \Set MemberStatus
statusFilter -> do
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll forall era. Era era => Gen (Maybe (Committee era))
genCommittee forall a b. (a -> b) -> a -> b
$ \Maybe (Committee era)
committee ->
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era.
EraTxOut era =>
Maybe (Committee era) -> Gen (Maybe (Committee era))
genNextCommittee @era Maybe (Committee era)
committee) forall a b. (a -> b) -> a -> b
$ \Maybe (Committee era)
nextCommittee ->
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era.
EraTxOut era =>
Maybe (Committee era)
-> Maybe (Committee era) -> Gen (CommitteeState era)
genRelevantCommitteeState @era Maybe (Committee era)
committee Maybe (Committee era)
nextCommittee) forall a b. (a -> b) -> a -> b
$ \CommitteeState era
committeeState -> do
let nes :: NewEpochState era
nes =
NewEpochState era
defNewEpochState
forall a b. a -> (a -> b) -> b
& forall era. Lens' (NewEpochState era) (EpochState era)
nesEpochStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EpochState era) (LedgerState era)
esLStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (LedgerState era) (CertState era)
lsCertStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (CertState era) (VState era)
certVStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (VState era) (CommitteeState era)
vsCommitteeStateL
forall s t a b. ASetter s t a b -> b -> s -> t
.~ CommitteeState era
committeeState
forall a b. a -> (a -> b) -> b
& forall era.
ConwayEraGov era =>
Lens' (NewEpochState era) (DRepPulsingState era)
newEpochStateDRepPulsingStateL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall era.
PulsingSnapshot era -> RatifyState era -> DRepPulsingState era
DRComplete forall a. Default a => a
def RatifyState era
nextRatifyState
forall a b. a -> (a -> b) -> b
& forall era. Lens' (NewEpochState era) (EpochState era)
nesEpochStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EpochState era) (LedgerState era)
esLStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (LedgerState era) (UTxOState era)
lsUTxOStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (UTxOState era) (GovState era)
utxosGovStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era.
ConwayEraGov era =>
Lens' (GovState era) (StrictMaybe (Committee era))
committeeGovStateL
forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe Maybe (Committee era)
committee
nextRatifyState :: RatifyState era
nextRatifyState =
(forall a. Default a => a
def @(RatifyState era))
forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) (EnactState era)
rsEnactStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EnactState era) (StrictMaybe (Committee era))
ensCommitteeL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe Maybe (Committee era)
nextCommittee
defNewEpochState :: NewEpochState era
defNewEpochState =
forall era.
EpochNo
-> BlocksMade (EraCrypto era)
-> BlocksMade (EraCrypto era)
-> EpochState era
-> StrictMaybe (PulsingRewUpdate (EraCrypto era))
-> PoolDistr (EraCrypto era)
-> StashedAVVMAddresses era
-> NewEpochState era
NewEpochState @era
(Word64 -> EpochNo
EpochNo Word64
0)
(forall c. Map (KeyHash 'StakePool c) Natural -> BlocksMade c
BlocksMade forall a. Default a => a
def)
(forall c. Map (KeyHash 'StakePool c) Natural -> BlocksMade c
BlocksMade forall a. Default a => a
def)
forall a. Default a => a
def
forall a. Default a => a
def
(forall c.
Map (KeyHash 'StakePool c) (IndividualPoolStake c)
-> CompactForm Coin -> PoolDistr c
PoolDistr forall a. Default a => a
def forall a b. (a -> b) -> a -> b
$ Word64 -> CompactForm Coin
CompactCoin Word64
1)
forall a. Default a => a
def
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era.
EraTxOut era =>
Maybe (Committee era)
-> CommitteeState era
-> Gen (Set (Credential 'ColdCommitteeRole (EraCrypto era)))
genRelevantColdCredsFilter Maybe (Committee era)
committee CommitteeState era
committeeState) forall a b. (a -> b) -> a -> b
$ \Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter ->
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era.
EraTxOut era =>
CommitteeState era
-> Gen (Set (Credential 'HotCommitteeRole (EraCrypto era)))
genRelevantHotCredsFilter CommitteeState era
committeeState) forall a b. (a -> b) -> a -> b
$ \Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter -> do
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propEmpty NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propComplete NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propAuthorized NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propActiveAuthorized NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNotAuthorized NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propResigned NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propUnrecognized NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNextEpoch NewEpochState era
nes
forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNoExpiration NewEpochState era
nes
forall era.
ConwayEraGov era =>
Set (Credential 'ColdCommitteeRole (EraCrypto era))
-> Set (Credential 'HotCommitteeRole (EraCrypto era))
-> Set MemberStatus
-> NewEpochState era
-> Expectation
propFilters Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes
propEmpty ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propEmpty :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propEmpty NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers CommitteeMembersState (EraCrypto era)
noFilterResult -> do
forall k a. Map k a -> Bool
Map.null (forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` (forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers Bool -> Bool -> Bool
&& forall k a. Map k a -> Bool
Map.null Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers Bool -> Bool -> Bool
&& forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers)
propComplete ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propComplete :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propComplete NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers CommitteeMembersState (EraCrypto era)
noFilterResult -> do
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers, forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers, forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers]
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` forall k a. Map k a -> Set k
Map.keysSet (forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
propNotAuthorized ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propNotAuthorized :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNotAuthorized NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let notAuthorized :: Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
notAuthorized =
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
( \case
CommitteeMemberState HotCredAuthStatus (EraCrypto era)
MemberNotAuthorized MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_ -> Bool
True
CommitteeMemberState (EraCrypto era)
_ -> Bool
False
)
(forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
notAuthorized forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` forall k a. Map k a
Map.empty
propAuthorized ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propAuthorized :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propAuthorized NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let ckHk :: [(Credential 'ColdCommitteeRole (EraCrypto era),
Credential 'HotCommitteeRole (EraCrypto era))]
ckHk =
[ (Credential 'ColdCommitteeRole (EraCrypto era)
ck, Credential 'HotCommitteeRole (EraCrypto era)
hk)
| (Credential 'ColdCommitteeRole (EraCrypto era)
ck, CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole (EraCrypto era)
hk) MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_) <- forall k a. Map k a -> [(k, a)]
Map.toList (forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
]
[(Credential 'ColdCommitteeRole (EraCrypto era),
Credential 'HotCommitteeRole (EraCrypto era))]
ckHk forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [(Credential 'ColdCommitteeRole (EraCrypto era)
ck, Credential 'HotCommitteeRole (EraCrypto era)
hk) | (Credential 'ColdCommitteeRole (EraCrypto era)
ck, CommitteeHotCredential Credential 'HotCommitteeRole (EraCrypto era)
hk) <- forall k a. Map k a -> [(k, a)]
Map.toList Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers]
propResigned ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propResigned :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propResigned NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let resigned :: [Credential 'ColdCommitteeRole (EraCrypto era)]
resigned =
[ Credential 'ColdCommitteeRole (EraCrypto era)
ck
| (Credential 'ColdCommitteeRole (EraCrypto era)
ck, CommitteeMemberState (MemberResigned Maybe (Anchor (EraCrypto era))
_) MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_) <- forall k a. Map k a -> [(k, a)]
Map.toList (forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
]
[Credential 'ColdCommitteeRole (EraCrypto era)]
resigned forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Credential 'ColdCommitteeRole (EraCrypto era)
ck | (Credential 'ColdCommitteeRole (EraCrypto era)
ck, CommitteeMemberResigned StrictMaybe (Anchor (EraCrypto era))
_) <- forall k a. Map k a -> [(k, a)]
Map.toList Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers]
propUnrecognized ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propUnrecognized :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propUnrecognized NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers' CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let unrecognized :: Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized =
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
( \case
CommitteeMemberState HotCredAuthStatus (EraCrypto era)
_ MemberStatus
Unrecognized Maybe EpochNo
_ NextEpochChange
_ -> Bool
True
CommitteeMemberState (EraCrypto era)
_ -> Bool
False
)
(forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
let nextComMembers :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers = forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers'
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` forall k a. Map k a
Map.empty
forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` (forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers))
forall a. Ord a => [a] -> Set a
Set.fromList (forall c. CommitteeMemberState c -> NextEpochChange
cmsNextEpochChange forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Map k a -> [a]
Map.elems Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized)
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` forall a. Ord a => [a] -> Set a
Set.fromList [NextEpochChange
ToBeEnacted, NextEpochChange
ToBeRemoved])
forall k a. Map k a -> Set k
Map.keysSet (forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (\CommitteeMemberState (EraCrypto era)
x -> forall c. CommitteeMemberState c -> NextEpochChange
cmsNextEpochChange CommitteeMemberState (EraCrypto era)
x forall a. Eq a => a -> a -> Bool
== NextEpochChange
ToBeEnacted) Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized)
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers)
forall k a. Map k a -> Set k
Map.keysSet (forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (\CommitteeMemberState (EraCrypto era)
x -> forall c. CommitteeMemberState c -> NextEpochChange
cmsNextEpochChange CommitteeMemberState (EraCrypto era)
x forall a. Eq a => a -> a -> Bool
== NextEpochChange
ToBeRemoved) Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
unrecognized)
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Set (Credential 'ColdCommitteeRole (EraCrypto era))
s -> forall a. Set a -> Bool
Set.null Set (Credential 'ColdCommitteeRole (EraCrypto era))
s Bool -> Bool -> Bool
|| Bool -> Bool
not (Set (Credential 'ColdCommitteeRole (EraCrypto era))
s forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers))
propActiveAuthorized ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propActiveAuthorized :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propActiveAuthorized NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let activeAuthorized :: Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(Credential 'HotCommitteeRole (EraCrypto era))
activeAuthorized =
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe
( \case
CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole (EraCrypto era)
hk) MemberStatus
Active Maybe EpochNo
_ NextEpochChange
_ -> forall a. a -> Maybe a
Just Credential 'HotCommitteeRole (EraCrypto era)
hk
CommitteeMemberState (EraCrypto era)
_ -> forall a. Maybe a
Nothing
)
(forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
let epochNo :: EpochNo
epochNo = NewEpochState era
nes forall s a. s -> Getting a s a -> a
^. forall era. Lens' (NewEpochState era) EpochNo
nesELL
forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(Credential 'HotCommitteeRole (EraCrypto era))
activeAuthorized
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers)
forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(Credential 'HotCommitteeRole (EraCrypto era))
activeAuthorized
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers)
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(Credential 'HotCommitteeRole (EraCrypto era))
activeAuthorized
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
>= EpochNo
epochNo)
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(Credential 'HotCommitteeRole (EraCrypto era))
activeAuthorized
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all
( \case
CommitteeHotCredential Credential 'HotCommitteeRole (EraCrypto era)
_ -> Bool
True
CommitteeAuthorization (EraCrypto era)
_ -> Bool
False
)
forall c. CommitteeMembersState c -> EpochNo
csEpochNo CommitteeMembersState (EraCrypto era)
noFilterResult forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` EpochNo
epochNo
propFilters ::
forall era.
ConwayEraGov era =>
Set (Credential 'ColdCommitteeRole (EraCrypto era)) ->
Set (Credential 'HotCommitteeRole (EraCrypto era)) ->
Set MemberStatus ->
NewEpochState era ->
Expectation
propFilters :: forall era.
ConwayEraGov era =>
Set (Credential 'ColdCommitteeRole (EraCrypto era))
-> Set (Credential 'HotCommitteeRole (EraCrypto era))
-> Set MemberStatus
-> NewEpochState era
-> Expectation
propFilters Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes = do
let (CommitteeMembersState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result Maybe UnitInterval
_ EpochNo
_) = forall era.
ConwayEraGov era =>
Set (Credential 'ColdCommitteeRole (EraCrypto era))
-> Set (Credential 'HotCommitteeRole (EraCrypto era))
-> Set MemberStatus
-> NewEpochState era
-> CommitteeMembersState (EraCrypto era)
queryCommitteeMembersState @era Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes
let allCks :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
allCks = forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result
let (Set (Credential 'HotCommitteeRole (EraCrypto era))
allHks, Set MemberStatus
allMemberStatuses) =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap'
( \case
CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole (EraCrypto era)
hk) MemberStatus
ms Maybe EpochNo
_ NextEpochChange
_ -> (forall a. a -> Set a
Set.singleton Credential 'HotCommitteeRole (EraCrypto era)
hk, forall a. a -> Set a
Set.singleton MemberStatus
ms)
CommitteeMemberState HotCredAuthStatus (EraCrypto era)
_ MemberStatus
ms Maybe EpochNo
_ NextEpochChange
_ -> (forall a. Set a
Set.empty, forall a. a -> Set a
Set.singleton MemberStatus
ms)
)
Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Set a -> Bool
Set.null Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter) forall a b. (a -> b) -> a -> b
$
Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall a b. a -> b -> a
const (Set (Credential 'ColdCommitteeRole (EraCrypto era))
allCks forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole (EraCrypto era))
ckFilter)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Set a -> Bool
Set.null Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter) forall a b. (a -> b) -> a -> b
$
Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall a b. a -> b -> a
const (Set (Credential 'HotCommitteeRole (EraCrypto era))
allHks forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'HotCommitteeRole (EraCrypto era))
hkFilter)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Set a -> Bool
Set.null Set MemberStatus
statusFilter) forall a b. (a -> b) -> a -> b
$
Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
result forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall a b. a -> b -> a
const (Set MemberStatus
allMemberStatuses forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set MemberStatus
statusFilter)
propNextEpoch ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propNextEpoch :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNextEpoch NewEpochState era
nes = do
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers' (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers') Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers' CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let comMembers :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
comMembers = forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers'
let comStateMembers :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
comStateMembers = forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers'
let nextComMembers :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers = forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers'
forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
ToBeEnacted CommitteeMembersState (EraCrypto era)
noFilterResult
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
res -> forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
res forall a. Eq a => a -> a -> Bool
== Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set (Credential 'ColdCommitteeRole (EraCrypto era))
comMembers)
forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
ToBeRemoved CommitteeMembersState (EraCrypto era)
noFilterResult
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
res -> forall k a. Map k a -> Set k
Map.keysSet Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
res forall a. Eq a => a -> a -> Bool
== (Set (Credential 'ColdCommitteeRole (EraCrypto era))
comMembers forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set (Credential 'ColdCommitteeRole (EraCrypto era))
comStateMembers) forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
[ forall k a. Map k a -> Set k
Map.keysSet (forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
NoChangeExpected CommitteeMembersState (EraCrypto era)
noFilterResult)
, forall k a. Map k a -> Set k
Map.keysSet (forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
ToBeExpired CommitteeMembersState (EraCrypto era)
noFilterResult)
, forall k a. Map k a -> Set k
Map.keysSet (forall {c}.
CommitteeMembersState c
-> Map
(Credential 'ColdCommitteeRole c) (Credential 'ColdCommitteeRole c)
termAdjusted CommitteeMembersState (EraCrypto era)
noFilterResult)
]
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Eq a => a -> a -> Bool
== (Set (Credential 'ColdCommitteeRole (EraCrypto era))
comMembers forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set (Credential 'ColdCommitteeRole (EraCrypto era))
nextComMembers))
let currentEpoch :: EpochNo
currentEpoch = forall c. CommitteeMembersState c -> EpochNo
csEpochNo CommitteeMembersState (EraCrypto era)
noFilterResult
let expiring :: Set (Credential 'ColdCommitteeRole (EraCrypto era))
expiring =
forall k a. Map k a -> Set k
Map.keysSet forall a b. (a -> b) -> a -> b
$
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union
(forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (forall a. Eq a => a -> a -> Bool
== EpochNo
currentEpoch) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers')
(forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (forall a. Eq a => a -> a -> Bool
== EpochNo
currentEpoch) Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers')
forall k a. Map k a -> Set k
Map.keysSet (forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
ToBeExpired CommitteeMembersState (EraCrypto era)
noFilterResult)
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole (EraCrypto era))
expiring)
forall c. CommitteeMemberState c -> Maybe EpochNo
cmsExpiration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall {c}.
NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
NoChangeExpected CommitteeMembersState (EraCrypto era)
noFilterResult
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
>= EpochNo
currentEpoch forall a. Num a => a -> a -> a
+ EpochNo
1))
where
filterNext :: NextEpochChange
-> CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
filterNext NextEpochChange
nextEpochChange CommitteeMembersState c
cms =
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
( \case
CommitteeMemberState HotCredAuthStatus c
_ MemberStatus
_ Maybe EpochNo
_ NextEpochChange
nextEpochChange' ->
NextEpochChange
nextEpochChange forall a. Eq a => a -> a -> Bool
== NextEpochChange
nextEpochChange'
)
(forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState c
cms)
termAdjusted :: CommitteeMembersState c
-> Map
(Credential 'ColdCommitteeRole c) (Credential 'ColdCommitteeRole c)
termAdjusted CommitteeMembersState c
cms =
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey
( \Credential 'ColdCommitteeRole c
k CommitteeMemberState c
cm ->
case CommitteeMemberState c
cm of
CommitteeMemberState HotCredAuthStatus c
_ MemberStatus
_ Maybe EpochNo
_ (TermAdjusted EpochNo
_) -> forall a. a -> Maybe a
Just Credential 'ColdCommitteeRole c
k
CommitteeMemberState c
_ -> forall a. Maybe a
Nothing
)
(forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState c
cms)
propNoExpiration ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
Expectation
propNoExpiration :: forall era. ConwayEraGov era => NewEpochState era -> Expectation
propNoExpiration NewEpochState era
nes =
forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes forall a b. (a -> b) -> a -> b
$
\Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeState era
_ Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
_ CommitteeMembersState (EraCrypto era)
noFilterResult -> do
let noExpiration :: Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
noExpiration = forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (forall a. Maybe a -> Bool
isNothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. CommitteeMemberState c -> Maybe EpochNo
cmsExpiration) (forall c.
CommitteeMembersState c
-> Map (Credential 'ColdCommitteeRole c) (CommitteeMemberState c)
csCommittee CommitteeMembersState (EraCrypto era)
noFilterResult)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall k a. Map k a -> Bool
Map.null Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
noExpiration) forall a b. (a -> b) -> a -> b
$
forall a. Ord a => [a] -> Set a
Set.fromList (forall c. CommitteeMemberState c -> MemberStatus
cmsStatus forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Map k a -> [a]
Map.elems Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeMemberState (EraCrypto era))
noExpiration) forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` forall a. a -> Set a
Set.singleton MemberStatus
Unrecognized
genCommittee ::
forall era.
Era era =>
Gen (Maybe (Committee era))
genCommittee :: forall era. Era era => Gen (Maybe (Committee era))
genCommittee = forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency [(Int
1, forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing), (Int
9, forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall era.
Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
-> Gen (Committee era)
genCommittee' forall a. Arbitrary a => Gen a
arbitrary)]
genRelevantCommitteeState ::
forall era.
EraTxOut era =>
Maybe (Committee era) ->
Maybe (Committee era) ->
Gen (CommitteeState era)
genRelevantCommitteeState :: forall era.
EraTxOut era =>
Maybe (Committee era)
-> Maybe (Committee era) -> Gen (CommitteeState era)
genRelevantCommitteeState Maybe (Committee era)
maybeCm Maybe (Committee era)
maybeNextCm = do
[Credential 'ColdCommitteeRole (EraCrypto era)]
membersRetaining <-
forall a. [a] -> [a] -> [a]
(++)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall era.
EraTxOut era =>
Maybe (Committee era)
-> Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining Maybe (Committee era)
maybeCm
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall era.
EraTxOut era =>
Maybe (Committee era)
-> Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining Maybe (Committee era)
maybeNextCm
[(Credential 'ColdCommitteeRole (EraCrypto era),
CommitteeAuthorization (EraCrypto era))]
pairs <- forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'ColdCommitteeRole (EraCrypto era)]
membersRetaining forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall era.
Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
-> CommitteeState era
CommitteeState forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Credential 'ColdCommitteeRole (EraCrypto era),
CommitteeAuthorization (EraCrypto era))]
pairs
genNextCommittee ::
forall era.
EraTxOut era =>
Maybe (Committee era) ->
Gen (Maybe (Committee era))
genNextCommittee :: forall era.
EraTxOut era =>
Maybe (Committee era) -> Gen (Maybe (Committee era))
genNextCommittee Maybe (Committee era)
maybeCm =
forall a. HasCallStack => [Gen a] -> Gen a
oneof [forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing, forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall era.
Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
-> Gen (Committee era)
genCommittee' (forall era.
EraTxOut era =>
Maybe (Committee era)
-> Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining Maybe (Committee era)
maybeCm)]
genCommittee' :: Gen [Credential 'ColdCommitteeRole (EraCrypto era)] -> Gen (Committee era)
genCommittee' :: forall era.
Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
-> Gen (Committee era)
genCommittee' Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genCreds = do
[Credential 'ColdCommitteeRole (EraCrypto era)]
creds <- Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genCreds
[(Credential 'ColdCommitteeRole (EraCrypto era), EpochNo)]
m <- forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'ColdCommitteeRole (EraCrypto era)]
creds forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Gen a -> Gen [a]
listOf (Word64 -> EpochNo
EpochNo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (Bounded a, Integral a) => (a, a) -> Gen a
chooseBoundedIntegral (Word64
0, Word64
20))
forall era.
Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> UnitInterval -> Committee era
Committee (forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Credential 'ColdCommitteeRole (EraCrypto era), EpochNo)]
m) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
genRelevantColdCredsFilter ::
forall era.
EraTxOut era =>
Maybe (Committee era) ->
CommitteeState era ->
Gen (Set.Set (Credential 'ColdCommitteeRole (EraCrypto era)))
genRelevantColdCredsFilter :: forall era.
EraTxOut era =>
Maybe (Committee era)
-> CommitteeState era
-> Gen (Set (Credential 'ColdCommitteeRole (EraCrypto era)))
genRelevantColdCredsFilter Maybe (Committee era)
maybeCm (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) = do
[Credential 'ColdCommitteeRole (EraCrypto era)]
creds <-
forall a. [a] -> [a] -> [a]
(++)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall era.
EraTxOut era =>
Maybe (Committee era)
-> Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining Maybe (Committee era)
maybeCm
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => [a] -> Gen [a]
genRetaining (forall k a. Map k a -> [k]
Map.keys Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> Set a
Set.fromList [Credential 'ColdCommitteeRole (EraCrypto era)]
creds
genRelevantHotCredsFilter ::
forall era.
EraTxOut era =>
CommitteeState era ->
Gen (Set.Set (Credential 'HotCommitteeRole (EraCrypto era)))
genRelevantHotCredsFilter :: forall era.
EraTxOut era =>
CommitteeState era
-> Gen (Set (Credential 'HotCommitteeRole (EraCrypto era)))
genRelevantHotCredsFilter (CommitteeState Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers) =
forall a. Ord a => [a] -> Set a
Set.fromList
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => [a] -> Gen [a]
genRetaining
[Credential 'HotCommitteeRole (EraCrypto era)
hk | (Credential 'ColdCommitteeRole (EraCrypto era)
_, CommitteeHotCredential Credential 'HotCommitteeRole (EraCrypto era)
hk) <- forall k a. Map k a -> [(k, a)]
Map.toList Map
(Credential 'ColdCommitteeRole (EraCrypto era))
(CommitteeAuthorization (EraCrypto era))
comStateMembers]
genMembersRetaining ::
forall era.
EraTxOut era =>
Maybe (Committee era) ->
Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining :: forall era.
EraTxOut era =>
Maybe (Committee era)
-> Gen [Credential 'ColdCommitteeRole (EraCrypto era)]
genMembersRetaining Maybe (Committee era)
maybeCm =
forall a. Arbitrary a => [a] -> Gen [a]
genRetaining forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
Map.keys forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' forall era.
Committee era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
committeeMembers Maybe (Committee era)
maybeCm
genRetaining :: Arbitrary a => [a] -> Gen [a]
genRetaining :: forall a. Arbitrary a => [a] -> Gen [a]
genRetaining [a]
ret = do
Int
retSize <- forall a. Random a => (a, a) -> Gen a
choose (Int
0, forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ret)
[a]
new <- forall a. Arbitrary a => Gen a
arbitrary
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [a]
new forall a. Semigroup a => a -> a -> a
<> forall a. Int -> [a] -> [a]
take Int
retSize [a]
ret
withCommitteeInfo ::
ConwayEraGov era =>
NewEpochState era ->
( Map.Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo ->
CommitteeState era ->
Map.Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo ->
CommitteeMembersState (EraCrypto era) ->
Expectation
) ->
Expectation
withCommitteeInfo :: forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation
expectation = Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
-> CommitteeMembersState (EraCrypto era)
-> Expectation
expectation Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers CommitteeState era
comState Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers CommitteeMembersState (EraCrypto era)
noFilterQueryResult
where
noFilterQueryResult :: CommitteeMembersState (EraCrypto era)
noFilterQueryResult = forall era.
ConwayEraGov era =>
NewEpochState era -> CommitteeMembersState (EraCrypto era)
queryCommitteeMembersStateNoFilters NewEpochState era
nes
(Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers, CommitteeState era
comState, Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextComMembers) = forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo,
CommitteeState era,
Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo)
committeeInfo NewEpochState era
nes
committeeInfo ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
( Map.Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
, CommitteeState era
, Map.Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
)
committeeInfo :: forall era.
ConwayEraGov era =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo,
CommitteeState era,
Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo)
committeeInfo NewEpochState era
nes =
let ledgerState :: LedgerState era
ledgerState = NewEpochState era
nes forall s a. s -> Getting a s a -> a
^. forall era. Lens' (NewEpochState era) (EpochState era)
nesEpochStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EpochState era) (LedgerState era)
esLStateL
govState :: GovState era
govState = LedgerState era
ledgerState forall s a. s -> Getting a s a -> a
^. forall era. Lens' (LedgerState era) (UTxOState era)
lsUTxOStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (UTxOState era) (GovState era)
utxosGovStateL
comMembers :: Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' forall era.
Committee era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
committeeMembers forall a b. (a -> b) -> a -> b
$
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe (GovState era
govState forall s a. s -> Getting a s a -> a
^. forall era.
ConwayEraGov era =>
Lens' (GovState era) (StrictMaybe (Committee era))
committeeGovStateL)
comState :: CommitteeState era
comState = LedgerState era
ledgerState forall s a. s -> Getting a s a -> a
^. forall era. Lens' (LedgerState era) (CertState era)
lsCertStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (CertState era) (VState era)
certVStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (VState era) (CommitteeState era)
vsCommitteeStateL
nextCommitteeMembers :: Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextCommitteeMembers = forall era.
ConwayEraGov era =>
NewEpochState era
-> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
getNextEpochCommitteeMembers NewEpochState era
nes
in (Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
comMembers, CommitteeState era
comState, Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo
nextCommitteeMembers)
queryCommitteeMembersStateNoFilters ::
forall era.
ConwayEraGov era =>
NewEpochState era ->
CommitteeMembersState (EraCrypto era)
=
forall era.
ConwayEraGov era =>
Set (Credential 'ColdCommitteeRole (EraCrypto era))
-> Set (Credential 'HotCommitteeRole (EraCrypto era))
-> Set MemberStatus
-> NewEpochState era
-> CommitteeMembersState (EraCrypto era)
queryCommitteeMembersState @era
forall a. Set a
Set.empty
forall a. Set a
Set.empty
forall a. Set a
Set.empty