{-# 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.Coin (CompactForm (CompactCoin))
import Cardano.Ledger.Conway (ConwayEra)
import Cardano.Ledger.Conway.Governance (
  Committee (..),
  ConwayEraGov (..),
  ConwayGovState,
  DRepPulsingState (..),
  RatifyState (..),
  ensCommitteeL,
  newEpochStateDRepPulsingStateL,
  rsEnactStateL,
 )
import Cardano.Ledger.Conway.State (
  ConwayEraCertState (..),
  vsCommitteeStateL,
 )
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.State
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
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"GetFilteredDelegationsAndRewardAccounts" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Property -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"filterStakePoolDelegsAndRewards same as getFilteredDelegationsAndRewardAccounts" (Property -> Spec) -> Property -> Spec
forall a b. (a -> b) -> a -> b
$
      Gen (UMap, Set (Credential 'Staking))
-> ((UMap, Set (Credential 'Staking)) -> Expectation) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (UMap, Set (Credential 'Staking))
genValidUMapWithCreds (((UMap, Set (Credential 'Staking)) -> Expectation) -> Property)
-> ((UMap, Set (Credential 'Staking)) -> Expectation) -> Property
forall a b. (a -> b) -> a -> b
$ \(UMap
umap :: UMap, Set (Credential 'Staking)
creds) ->
        UMap
-> Set (Credential 'Staking)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
filterStakePoolDelegsAndRewards UMap
umap Set (Credential 'Staking)
creds
          (Map (Credential 'Staking) (KeyHash 'StakePool),
 Map (Credential 'Staking) Coin)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
-> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` UMap
-> Set (Credential 'Staking)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
getFilteredDelegationsAndRewardAccounts UMap
umap Set (Credential 'Staking)
creds

  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"GetCommitteeMembersState" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    forall era.
(ConwayEraGov era, Default (EpochState era),
 Default (StashedAVVMAddresses era),
 GovState era ~ ConwayGovState era, ConwayEraCertState era) =>
Spec
committeeMembersStateSpec @ConwayEra

committeeMembersStateSpec ::
  forall era.
  ( ConwayEraGov era
  , Default (EpochState era)
  , Default (StashedAVVMAddresses era)
  , GovState era ~ ConwayGovState era
  , ConwayEraCertState era
  ) =>
  Spec
committeeMembersStateSpec :: forall era.
(ConwayEraGov era, Default (EpochState era),
 Default (StashedAVVMAddresses era),
 GovState era ~ ConwayGovState era, ConwayEraCertState era) =>
Spec
committeeMembersStateSpec =
  String -> (Set MemberStatus -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"CommitteeMembersState Query" ((Set MemberStatus -> Property) -> Spec)
-> (Set MemberStatus -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \Set MemberStatus
statusFilter -> do
    Gen (Maybe (Committee era))
-> (Maybe (Committee era) -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (Maybe (Committee era))
forall era. Gen (Maybe (Committee era))
genCommittee ((Maybe (Committee era) -> Property) -> Property)
-> (Maybe (Committee era) -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \Maybe (Committee era)
committee ->
      -- half of the committee members in the next epoch will overlap with the current ones
      Gen (Maybe (Committee era))
-> (Maybe (Committee era) -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era. Maybe (Committee era) -> Gen (Maybe (Committee era))
genNextCommittee @era Maybe (Committee era)
committee) ((Maybe (Committee era) -> Property) -> Property)
-> (Maybe (Committee era) -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \Maybe (Committee era)
nextCommittee ->
        -- replace some arbitrary number of cold keys from the committeeState with the
        -- ones from the committee so we can have Active members
        Gen (CommitteeState era)
-> (CommitteeState era -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (forall era.
Maybe (Committee era)
-> Maybe (Committee era) -> Gen (CommitteeState era)
genRelevantCommitteeState @era Maybe (Committee era)
committee Maybe (Committee era)
nextCommittee) ((CommitteeState era -> Property) -> Property)
-> (CommitteeState era -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \CommitteeState era
committeeState -> do
          let nes :: NewEpochState era
nes =
                NewEpochState era
defNewEpochState
                  NewEpochState era
-> (NewEpochState era -> NewEpochState era) -> NewEpochState era
forall a b. a -> (a -> b) -> b
& (EpochState era -> Identity (EpochState era))
-> NewEpochState era -> Identity (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEpochStateL ((EpochState era -> Identity (EpochState era))
 -> NewEpochState era -> Identity (NewEpochState era))
-> ((CommitteeState era -> Identity (CommitteeState era))
    -> EpochState era -> Identity (EpochState era))
-> (CommitteeState era -> Identity (CommitteeState era))
-> NewEpochState era
-> Identity (NewEpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Identity (LedgerState era))
-> EpochState era -> Identity (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Identity (LedgerState era))
 -> EpochState era -> Identity (EpochState era))
-> ((CommitteeState era -> Identity (CommitteeState era))
    -> LedgerState era -> Identity (LedgerState era))
-> (CommitteeState era -> Identity (CommitteeState era))
-> EpochState era
-> Identity (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era -> Identity (CertState era))
-> LedgerState era -> Identity (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Identity (CertState era))
 -> LedgerState era -> Identity (LedgerState era))
-> ((CommitteeState era -> Identity (CommitteeState era))
    -> CertState era -> Identity (CertState era))
-> (CommitteeState era -> Identity (CommitteeState era))
-> LedgerState era
-> Identity (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era -> Identity (VState era))
-> CertState era -> Identity (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL ((VState era -> Identity (VState era))
 -> CertState era -> Identity (CertState era))
-> ((CommitteeState era -> Identity (CommitteeState era))
    -> VState era -> Identity (VState era))
-> (CommitteeState era -> Identity (CommitteeState era))
-> CertState era
-> Identity (CertState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CommitteeState era -> Identity (CommitteeState era))
-> VState era -> Identity (VState era)
forall era (f :: * -> *).
Functor f =>
(CommitteeState era -> f (CommitteeState era))
-> VState era -> f (VState era)
vsCommitteeStateL
                    ((CommitteeState era -> Identity (CommitteeState era))
 -> NewEpochState era -> Identity (NewEpochState era))
-> CommitteeState era -> NewEpochState era -> NewEpochState era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ CommitteeState era
committeeState
                  NewEpochState era
-> (NewEpochState era -> NewEpochState era) -> NewEpochState era
forall a b. a -> (a -> b) -> b
& (DRepPulsingState era -> Identity (DRepPulsingState era))
-> NewEpochState era -> Identity (NewEpochState era)
forall era.
ConwayEraGov era =>
Lens' (NewEpochState era) (DRepPulsingState era)
Lens' (NewEpochState era) (DRepPulsingState era)
newEpochStateDRepPulsingStateL ((DRepPulsingState era -> Identity (DRepPulsingState era))
 -> NewEpochState era -> Identity (NewEpochState era))
-> DRepPulsingState era -> NewEpochState era -> NewEpochState era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PulsingSnapshot era -> RatifyState era -> DRepPulsingState era
forall era.
PulsingSnapshot era -> RatifyState era -> DRepPulsingState era
DRComplete PulsingSnapshot era
forall a. Default a => a
def RatifyState era
nextRatifyState
                  NewEpochState era
-> (NewEpochState era -> NewEpochState era) -> NewEpochState era
forall a b. a -> (a -> b) -> b
& (EpochState era -> Identity (EpochState era))
-> NewEpochState era -> Identity (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEpochStateL ((EpochState era -> Identity (EpochState era))
 -> NewEpochState era -> Identity (NewEpochState era))
-> ((StrictMaybe (Committee era)
     -> Identity (StrictMaybe (Committee era)))
    -> EpochState era -> Identity (EpochState era))
-> (StrictMaybe (Committee era)
    -> Identity (StrictMaybe (Committee era)))
-> NewEpochState era
-> Identity (NewEpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Identity (LedgerState era))
-> EpochState era -> Identity (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Identity (LedgerState era))
 -> EpochState era -> Identity (EpochState era))
-> ((StrictMaybe (Committee era)
     -> Identity (StrictMaybe (Committee era)))
    -> LedgerState era -> Identity (LedgerState era))
-> (StrictMaybe (Committee era)
    -> Identity (StrictMaybe (Committee era)))
-> EpochState era
-> Identity (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UTxOState era -> Identity (UTxOState era))
-> LedgerState era -> Identity (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(UTxOState era -> f (UTxOState era))
-> LedgerState era -> f (LedgerState era)
lsUTxOStateL ((UTxOState era -> Identity (UTxOState era))
 -> LedgerState era -> Identity (LedgerState era))
-> ((StrictMaybe (Committee era)
     -> Identity (StrictMaybe (Committee era)))
    -> UTxOState era -> Identity (UTxOState era))
-> (StrictMaybe (Committee era)
    -> Identity (StrictMaybe (Committee era)))
-> LedgerState era
-> Identity (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GovState era -> Identity (GovState era))
-> UTxOState era -> Identity (UTxOState era)
(ConwayGovState era -> Identity (ConwayGovState era))
-> UTxOState era -> Identity (UTxOState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> UTxOState era -> f (UTxOState era)
utxosGovStateL ((ConwayGovState era -> Identity (ConwayGovState era))
 -> UTxOState era -> Identity (UTxOState era))
-> ((StrictMaybe (Committee era)
     -> Identity (StrictMaybe (Committee era)))
    -> ConwayGovState era -> Identity (ConwayGovState era))
-> (StrictMaybe (Committee era)
    -> Identity (StrictMaybe (Committee era)))
-> UTxOState era
-> Identity (UTxOState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe (Committee era)
 -> Identity (StrictMaybe (Committee era)))
-> GovState era -> Identity (GovState era)
(StrictMaybe (Committee era)
 -> Identity (StrictMaybe (Committee era)))
-> ConwayGovState era -> Identity (ConwayGovState era)
forall era.
ConwayEraGov era =>
Lens' (GovState era) (StrictMaybe (Committee era))
Lens' (GovState era) (StrictMaybe (Committee era))
committeeGovStateL
                    ((StrictMaybe (Committee era)
  -> Identity (StrictMaybe (Committee era)))
 -> NewEpochState era -> Identity (NewEpochState era))
-> StrictMaybe (Committee era)
-> NewEpochState era
-> NewEpochState era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe (Committee era) -> StrictMaybe (Committee era)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe Maybe (Committee era)
committee
              nextRatifyState :: RatifyState era
nextRatifyState =
                (forall a. Default a => a
def @(RatifyState era))
                  RatifyState era
-> (RatifyState era -> RatifyState era) -> RatifyState era
forall a b. a -> (a -> b) -> b
& (EnactState era -> Identity (EnactState era))
-> RatifyState era -> Identity (RatifyState era)
forall era (f :: * -> *).
Functor f =>
(EnactState era -> f (EnactState era))
-> RatifyState era -> f (RatifyState era)
rsEnactStateL ((EnactState era -> Identity (EnactState era))
 -> RatifyState era -> Identity (RatifyState era))
-> ((StrictMaybe (Committee era)
     -> Identity (StrictMaybe (Committee era)))
    -> EnactState era -> Identity (EnactState era))
-> (StrictMaybe (Committee era)
    -> Identity (StrictMaybe (Committee era)))
-> RatifyState era
-> Identity (RatifyState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe (Committee era)
 -> Identity (StrictMaybe (Committee era)))
-> EnactState era -> Identity (EnactState era)
forall era (f :: * -> *).
Functor f =>
(StrictMaybe (Committee era) -> f (StrictMaybe (Committee era)))
-> EnactState era -> f (EnactState era)
ensCommitteeL ((StrictMaybe (Committee era)
  -> Identity (StrictMaybe (Committee era)))
 -> RatifyState era -> Identity (RatifyState era))
-> StrictMaybe (Committee era)
-> RatifyState era
-> RatifyState era
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe (Committee era) -> StrictMaybe (Committee era)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe Maybe (Committee era)
nextCommittee
              defNewEpochState :: NewEpochState era
defNewEpochState =
                forall era.
EpochNo
-> BlocksMade
-> BlocksMade
-> EpochState era
-> StrictMaybe PulsingRewUpdate
-> PoolDistr
-> StashedAVVMAddresses era
-> NewEpochState era
NewEpochState @era
                  (Word64 -> EpochNo
EpochNo Word64
0)
                  (Map (KeyHash 'StakePool) Natural -> BlocksMade
BlocksMade Map (KeyHash 'StakePool) Natural
forall a. Default a => a
def)
                  (Map (KeyHash 'StakePool) Natural -> BlocksMade
BlocksMade Map (KeyHash 'StakePool) Natural
forall a. Default a => a
def)
                  EpochState era
forall a. Default a => a
def
                  StrictMaybe PulsingRewUpdate
forall a. Default a => a
def
                  (Map (KeyHash 'StakePool) IndividualPoolStake
-> CompactForm Coin -> PoolDistr
PoolDistr Map (KeyHash 'StakePool) IndividualPoolStake
forall a. Default a => a
def (CompactForm Coin -> PoolDistr) -> CompactForm Coin -> PoolDistr
forall a b. (a -> b) -> a -> b
$ Word64 -> CompactForm Coin
CompactCoin Word64
1)
                  StashedAVVMAddresses era
forall a. Default a => a
def
          -- replace some cold and hot keys from the filter with known ones from both
          -- committee and committeeState
          Gen (Set (Credential 'ColdCommitteeRole))
-> (Set (Credential 'ColdCommitteeRole) -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (Maybe (Committee era)
-> CommitteeState era -> Gen (Set (Credential 'ColdCommitteeRole))
forall era.
Maybe (Committee era)
-> CommitteeState era -> Gen (Set (Credential 'ColdCommitteeRole))
genRelevantColdCredsFilter Maybe (Committee era)
committee CommitteeState era
committeeState) ((Set (Credential 'ColdCommitteeRole) -> Property) -> Property)
-> (Set (Credential 'ColdCommitteeRole) -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \Set (Credential 'ColdCommitteeRole)
ckFilter ->
            Gen (Set (Credential 'HotCommitteeRole))
-> (Set (Credential 'HotCommitteeRole) -> Expectation) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll (CommitteeState era -> Gen (Set (Credential 'HotCommitteeRole))
forall era.
CommitteeState era -> Gen (Set (Credential 'HotCommitteeRole))
genRelevantHotCredsFilter CommitteeState era
committeeState) ((Set (Credential 'HotCommitteeRole) -> Expectation) -> Property)
-> (Set (Credential 'HotCommitteeRole) -> Expectation) -> Property
forall a b. (a -> b) -> a -> b
$ \Set (Credential 'HotCommitteeRole)
hkFilter -> do
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propEmpty NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propComplete NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propAuthorized NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propActiveAuthorized NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNotAuthorized NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propResigned NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propUnrecognized NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNextEpoch NewEpochState era
nes
              NewEpochState era -> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNoExpiration NewEpochState era
nes
              Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> Expectation
propFilters Set (Credential 'ColdCommitteeRole)
ckFilter Set (Credential 'HotCommitteeRole)
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes

propEmpty ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propEmpty :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propEmpty NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
comMembers (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers CommitteeMembersState
noFilterResult -> do
      Map (Credential 'ColdCommitteeRole) CommitteeMemberState -> Bool
forall k a. Map k a -> Bool
Map.null (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
        Bool -> Bool -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` (Map (Credential 'ColdCommitteeRole) EpochNo -> Bool
forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole) EpochNo
comMembers Bool -> Bool -> Bool
&& Map (Credential 'ColdCommitteeRole) CommitteeAuthorization -> Bool
forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers Bool -> Bool -> Bool
&& Map (Credential 'ColdCommitteeRole) EpochNo -> Bool
forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers)

propComplete ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propComplete :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propComplete NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
comMembers (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers CommitteeMembersState
noFilterResult -> do
      -- if a credential appears in either Committee or CommitteeState, it should appear
      -- in the result
      [Set (Credential 'ColdCommitteeRole)]
-> Set (Credential 'ColdCommitteeRole)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
comMembers, Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers, Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers]
        Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)

propNotAuthorized ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propNotAuthorized :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNotAuthorized NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
_ (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeMembersState
noFilterResult -> do
      let notAuthorized :: Map (Credential 'ColdCommitteeRole) CommitteeMemberState
notAuthorized =
            (CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
              ( \case
                  CommitteeMemberState HotCredAuthStatus
MemberNotAuthorized MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_ -> Bool
True
                  CommitteeMemberState
_ -> Bool
False
              )
              (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
      -- if the member is NotAuthorized, it should not have an associated hot credential in the committeeState
      Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers Map (Credential 'ColdCommitteeRole) CommitteeMemberState
notAuthorized Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall k a. Map k a
Map.empty

propAuthorized ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propAuthorized :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propAuthorized NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
_ (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeMembersState
noFilterResult -> do
      let ckHk :: [(Credential 'ColdCommitteeRole, Credential 'HotCommitteeRole)]
ckHk =
            [ (Credential 'ColdCommitteeRole
ck, Credential 'HotCommitteeRole
hk)
            | (Credential 'ColdCommitteeRole
ck, CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole
hk) MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_) <- Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> [(Credential 'ColdCommitteeRole, CommitteeMemberState)]
forall k a. Map k a -> [(k, a)]
Map.toList (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
            ]
      -- if the member is Authorized, it should appear in the committeeState
      [(Credential 'ColdCommitteeRole, Credential 'HotCommitteeRole)]
ckHk [(Credential 'ColdCommitteeRole, Credential 'HotCommitteeRole)]
-> [(Credential 'ColdCommitteeRole, Credential 'HotCommitteeRole)]
-> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [(Credential 'ColdCommitteeRole
ck, Credential 'HotCommitteeRole
hk) | (Credential 'ColdCommitteeRole
ck, CommitteeHotCredential Credential 'HotCommitteeRole
hk) <- Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers]

propResigned ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propResigned :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propResigned NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
_ (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeMembersState
noFilterResult -> do
      let resigned :: [Credential 'ColdCommitteeRole]
resigned =
            [ Credential 'ColdCommitteeRole
ck
            | (Credential 'ColdCommitteeRole
ck, CommitteeMemberState (MemberResigned Maybe Anchor
_) MemberStatus
_ Maybe EpochNo
_ NextEpochChange
_) <- Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> [(Credential 'ColdCommitteeRole, CommitteeMemberState)]
forall k a. Map k a -> [(k, a)]
Map.toList (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
            ]
      -- if the member is Resignd, it should appear in the committeeState as Nothing
      [Credential 'ColdCommitteeRole]
resigned [Credential 'ColdCommitteeRole]
-> [Credential 'ColdCommitteeRole] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Credential 'ColdCommitteeRole
ck | (Credential 'ColdCommitteeRole
ck, CommitteeMemberResigned StrictMaybe Anchor
_) <- Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers]

propUnrecognized ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propUnrecognized :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propUnrecognized NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
comMembers (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers' CommitteeMembersState
noFilterResult -> do
      let unrecognized :: Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized =
            (CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
              ( \case
                  CommitteeMemberState HotCredAuthStatus
_ MemberStatus
Unrecognized Maybe EpochNo
_ NextEpochChange
_ -> Bool
True
                  CommitteeMemberState
_ -> Bool
False
              )
              (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
      let nextComMembers :: Set (Credential 'ColdCommitteeRole)
nextComMembers = Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers'
      -- if the member is Unrecognized, it should not be in the committe, but it should be
      -- in the committeeState or in the nextCommittee
      Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole) EpochNo
comMembers Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) EpochNo -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Map (Credential 'ColdCommitteeRole) EpochNo
forall k a. Map k a
Map.empty
      Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` (Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set (Credential 'ColdCommitteeRole)
nextComMembers))
      -- all Unrecognized members will be either enacted or removed in the next epoch
      [NextEpochChange] -> Set NextEpochChange
forall a. Ord a => [a] -> Set a
Set.fromList (CommitteeMemberState -> NextEpochChange
cmsNextEpochChange (CommitteeMemberState -> NextEpochChange)
-> [CommitteeMemberState] -> [NextEpochChange]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> [CommitteeMemberState]
forall k a. Map k a -> [a]
Map.elems Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized)
        Set NextEpochChange -> (Set NextEpochChange -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set NextEpochChange -> Set NextEpochChange -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` [NextEpochChange] -> Set NextEpochChange
forall a. Ord a => [a] -> Set a
Set.fromList [NextEpochChange
ToBeEnacted, NextEpochChange
ToBeRemoved])
      Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet ((CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (\CommitteeMemberState
x -> CommitteeMemberState -> NextEpochChange
cmsNextEpochChange CommitteeMemberState
x NextEpochChange -> NextEpochChange -> Bool
forall a. Eq a => a -> a -> Bool
== NextEpochChange
ToBeEnacted) Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized)
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole)
nextComMembers)
      Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet ((CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (\CommitteeMemberState
x -> CommitteeMemberState -> NextEpochChange
cmsNextEpochChange CommitteeMemberState
x NextEpochChange -> NextEpochChange -> Bool
forall a. Eq a => a -> a -> Bool
== NextEpochChange
ToBeRemoved) Map (Credential 'ColdCommitteeRole) CommitteeMemberState
unrecognized)
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Set (Credential 'ColdCommitteeRole)
s -> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Set a -> Bool
Set.null Set (Credential 'ColdCommitteeRole)
s Bool -> Bool -> Bool
|| Bool -> Bool
not (Set (Credential 'ColdCommitteeRole)
s Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole)
nextComMembers))

propActiveAuthorized ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propActiveAuthorized :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propActiveAuthorized NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
comMembers (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeMembersState
noFilterResult -> do
      let activeAuthorized :: Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
activeAuthorized =
            (CommitteeMemberState -> Maybe (Credential 'HotCommitteeRole))
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe
              ( \case
                  CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole
hk) MemberStatus
Active Maybe EpochNo
_ NextEpochChange
_ -> Credential 'HotCommitteeRole
-> Maybe (Credential 'HotCommitteeRole)
forall a. a -> Maybe a
Just Credential 'HotCommitteeRole
hk
                  CommitteeMemberState
_ -> Maybe (Credential 'HotCommitteeRole)
forall a. Maybe a
Nothing
              )
              (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
      let epochNo :: EpochNo
epochNo = NewEpochState era
nes NewEpochState era
-> Getting EpochNo (NewEpochState era) EpochNo -> EpochNo
forall s a. s -> Getting a s a -> a
^. Getting EpochNo (NewEpochState era) EpochNo
forall era (f :: * -> *).
Functor f =>
(EpochNo -> f EpochNo)
-> NewEpochState era -> f (NewEpochState era)
nesELL

      -- if a member is active and authorized, then it should be:
      --   - in Committee and not expired
      --   - in CommitteeState, not empty
      Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
activeAuthorized
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
comMembers)
      Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
activeAuthorized
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers)
      Map (Credential 'ColdCommitteeRole) EpochNo
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole) EpochNo
comMembers Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
activeAuthorized
        Map (Credential 'ColdCommitteeRole) EpochNo
-> (Map (Credential 'ColdCommitteeRole) EpochNo -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (EpochNo -> Bool)
-> Map (Credential 'ColdCommitteeRole) EpochNo -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (EpochNo -> EpochNo -> Bool
forall a. Ord a => a -> a -> Bool
>= EpochNo
epochNo)
      Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers Map (Credential 'ColdCommitteeRole) (Credential 'HotCommitteeRole)
activeAuthorized
        Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> (Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (CommitteeAuthorization -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all
          ( \case
              CommitteeHotCredential Credential 'HotCommitteeRole
_ -> Bool
True
              CommitteeAuthorization
_ -> Bool
False
          )

      CommitteeMembersState -> EpochNo
csEpochNo CommitteeMembersState
noFilterResult EpochNo -> EpochNo -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` EpochNo
epochNo

propFilters ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  Set (Credential 'ColdCommitteeRole) ->
  Set (Credential 'HotCommitteeRole) ->
  Set MemberStatus ->
  NewEpochState era ->
  Expectation
propFilters :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> Expectation
propFilters Set (Credential 'ColdCommitteeRole)
ckFilter Set (Credential 'HotCommitteeRole)
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes = do
  let (CommitteeMembersState Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result Maybe UnitInterval
_ EpochNo
_) = forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> CommitteeMembersState
queryCommitteeMembersState @era Set (Credential 'ColdCommitteeRole)
ckFilter Set (Credential 'HotCommitteeRole)
hkFilter Set MemberStatus
statusFilter NewEpochState era
nes
  let allCks :: Set (Credential 'ColdCommitteeRole)
allCks = Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result
  let (Set (Credential 'HotCommitteeRole)
allHks, Set MemberStatus
allMemberStatuses) =
        (CommitteeMemberState
 -> (Set (Credential 'HotCommitteeRole), Set MemberStatus))
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Set (Credential 'HotCommitteeRole), Set MemberStatus)
forall m a.
Monoid m =>
(a -> m) -> Map (Credential 'ColdCommitteeRole) a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap'
          ( \case
              CommitteeMemberState (MemberAuthorized Credential 'HotCommitteeRole
hk) MemberStatus
ms Maybe EpochNo
_ NextEpochChange
_ -> (Credential 'HotCommitteeRole -> Set (Credential 'HotCommitteeRole)
forall a. a -> Set a
Set.singleton Credential 'HotCommitteeRole
hk, MemberStatus -> Set MemberStatus
forall a. a -> Set a
Set.singleton MemberStatus
ms)
              CommitteeMemberState HotCredAuthStatus
_ MemberStatus
ms Maybe EpochNo
_ NextEpochChange
_ -> (Set (Credential 'HotCommitteeRole)
forall a. Set a
Set.empty, MemberStatus -> Set MemberStatus
forall a. a -> Set a
Set.singleton MemberStatus
ms)
          )
          Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result
  Bool -> Expectation -> Expectation
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Set a -> Bool
Set.null Set (Credential 'ColdCommitteeRole)
ckFilter) (Expectation -> Expectation) -> Expectation -> Expectation
forall a b. (a -> b) -> a -> b
$
    Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Map (Credential 'ColdCommitteeRole) CommitteeMemberState
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` Bool
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState -> Bool
forall a b. a -> b -> a
const (Set (Credential 'ColdCommitteeRole)
allCks Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole)
ckFilter)
  Bool -> Expectation -> Expectation
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set (Credential 'HotCommitteeRole) -> Bool
forall a. Set a -> Bool
Set.null Set (Credential 'HotCommitteeRole)
hkFilter) (Expectation -> Expectation) -> Expectation -> Expectation
forall a b. (a -> b) -> a -> b
$
    Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Map (Credential 'ColdCommitteeRole) CommitteeMemberState
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` Bool
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState -> Bool
forall a b. a -> b -> a
const (Set (Credential 'HotCommitteeRole)
allHks Set (Credential 'HotCommitteeRole)
-> Set (Credential 'HotCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'HotCommitteeRole)
hkFilter)
  Bool -> Expectation -> Expectation
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set MemberStatus -> Bool
forall a. Set a -> Bool
Set.null Set MemberStatus
statusFilter) (Expectation -> Expectation) -> Expectation -> Expectation
forall a b. (a -> b) -> a -> b
$
    Map (Credential 'ColdCommitteeRole) CommitteeMemberState
result Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Map (Credential 'ColdCommitteeRole) CommitteeMemberState
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` Bool
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState -> Bool
forall a b. a -> b -> a
const (Set MemberStatus
allMemberStatuses Set MemberStatus -> Set MemberStatus -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set MemberStatus
statusFilter)

propNextEpoch ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propNextEpoch :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNextEpoch NewEpochState era
nes = do
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
comMembers' (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers') Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers' CommitteeMembersState
noFilterResult -> do
      let comMembers :: Set (Credential 'ColdCommitteeRole)
comMembers = Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
comMembers'
      let comStateMembers :: Set (Credential 'ColdCommitteeRole)
comStateMembers = Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers'
      let nextComMembers :: Set (Credential 'ColdCommitteeRole)
nextComMembers = Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers'

      NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
ToBeEnacted CommitteeMembersState
noFilterResult
        Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Map (Credential 'ColdCommitteeRole) CommitteeMemberState
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Map (Credential 'ColdCommitteeRole) CommitteeMemberState
res -> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeMemberState
res Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Eq a => a -> a -> Bool
== Set (Credential 'ColdCommitteeRole)
nextComMembers Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set (Credential 'ColdCommitteeRole)
comMembers)

      NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
ToBeRemoved CommitteeMembersState
noFilterResult
        Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> (Map (Credential 'ColdCommitteeRole) CommitteeMemberState
    -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (\Map (Credential 'ColdCommitteeRole) CommitteeMemberState
res -> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeMemberState
res Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Eq a => a -> a -> Bool
== (Set (Credential 'ColdCommitteeRole)
comMembers Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set (Credential 'ColdCommitteeRole)
comStateMembers) Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set (Credential 'ColdCommitteeRole)
nextComMembers)

      -- members who are both in current and nextCommittee are either ToBeExpired, TermAdjusted or NoChangeExpected
      [Set (Credential 'ColdCommitteeRole)]
-> Set (Credential 'ColdCommitteeRole)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
        [ Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
NoChangeExpected CommitteeMembersState
noFilterResult)
        , Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
ToBeExpired CommitteeMembersState
noFilterResult)
        , Map (Credential 'ColdCommitteeRole) (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (CommitteeMembersState
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'ColdCommitteeRole)
termAdjusted CommitteeMembersState
noFilterResult)
        ]
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Eq a => a -> a -> Bool
== (Set (Credential 'ColdCommitteeRole)
comMembers Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set (Credential 'ColdCommitteeRole)
nextComMembers))

      let currentEpoch :: EpochNo
currentEpoch = CommitteeMembersState -> EpochNo
csEpochNo CommitteeMembersState
noFilterResult
      let expiring :: Set (Credential 'ColdCommitteeRole)
expiring =
            Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (Map (Credential 'ColdCommitteeRole) EpochNo
 -> Set (Credential 'ColdCommitteeRole))
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall a b. (a -> b) -> a -> b
$
              Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union
                ((EpochNo -> Bool)
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (EpochNo -> EpochNo -> Bool
forall a. Eq a => a -> a -> Bool
== EpochNo
currentEpoch) Map (Credential 'ColdCommitteeRole) EpochNo
comMembers')
                ((EpochNo -> Bool)
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (EpochNo -> EpochNo -> Bool
forall a. Eq a => a -> a -> Bool
== EpochNo
currentEpoch) Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers')

      -- members ToBeExpired have the expiry set to currentEpoch, either in the current committee or in the next one
      Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet (NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
ToBeExpired CommitteeMembersState
noFilterResult)
        Set (Credential 'ColdCommitteeRole)
-> (Set (Credential 'ColdCommitteeRole) -> Bool) -> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set (Credential 'ColdCommitteeRole)
expiring)

      CommitteeMemberState -> Maybe EpochNo
cmsExpiration
        (CommitteeMemberState -> Maybe EpochNo)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) (Maybe EpochNo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
NoChangeExpected CommitteeMembersState
noFilterResult
          Map (Credential 'ColdCommitteeRole) (Maybe EpochNo)
-> (Map (Credential 'ColdCommitteeRole) (Maybe EpochNo) -> Bool)
-> Expectation
forall a. (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
`shouldSatisfy` (Maybe EpochNo -> Bool)
-> Map (Credential 'ColdCommitteeRole) (Maybe EpochNo) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ((EpochNo -> Bool) -> Maybe EpochNo -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (EpochNo -> EpochNo -> Bool
forall a. Ord a => a -> a -> Bool
>= EpochNo
currentEpoch EpochNo -> EpochNo -> EpochNo
forall a. Num a => a -> a -> a
+ EpochNo
1))
  where
    filterNext :: NextEpochChange
-> CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
filterNext NextEpochChange
nextEpochChange CommitteeMembersState
cms =
      (CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter
        ( \case
            CommitteeMemberState HotCredAuthStatus
_ MemberStatus
_ Maybe EpochNo
_ NextEpochChange
nextEpochChange' ->
              NextEpochChange
nextEpochChange NextEpochChange -> NextEpochChange -> Bool
forall a. Eq a => a -> a -> Bool
== NextEpochChange
nextEpochChange'
        )
        (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
cms)
    termAdjusted :: CommitteeMembersState
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'ColdCommitteeRole)
termAdjusted CommitteeMembersState
cms =
      (Credential 'ColdCommitteeRole
 -> CommitteeMemberState -> Maybe (Credential 'ColdCommitteeRole))
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map
     (Credential 'ColdCommitteeRole) (Credential 'ColdCommitteeRole)
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey
        ( \Credential 'ColdCommitteeRole
k CommitteeMemberState
cm ->
            case CommitteeMemberState
cm of
              CommitteeMemberState HotCredAuthStatus
_ MemberStatus
_ Maybe EpochNo
_ (TermAdjusted EpochNo
_) -> Credential 'ColdCommitteeRole
-> Maybe (Credential 'ColdCommitteeRole)
forall a. a -> Maybe a
Just Credential 'ColdCommitteeRole
k
              CommitteeMemberState
_ -> Maybe (Credential 'ColdCommitteeRole)
forall a. Maybe a
Nothing
        )
        (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
cms)

propNoExpiration ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  Expectation
propNoExpiration :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> Expectation
propNoExpiration NewEpochState era
nes =
  NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes ((Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeState era
  -> Map (Credential 'ColdCommitteeRole) EpochNo
  -> CommitteeMembersState
  -> Expectation)
 -> Expectation)
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
forall a b. (a -> b) -> a -> b
$
    \Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeState era
_ Map (Credential 'ColdCommitteeRole) EpochNo
_ CommitteeMembersState
noFilterResult -> do
      let noExpiration :: Map (Credential 'ColdCommitteeRole) CommitteeMemberState
noExpiration = (CommitteeMemberState -> Bool)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Maybe EpochNo -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe EpochNo -> Bool)
-> (CommitteeMemberState -> Maybe EpochNo)
-> CommitteeMemberState
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommitteeMemberState -> Maybe EpochNo
cmsExpiration) (CommitteeMembersState
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee CommitteeMembersState
noFilterResult)
      Bool -> Expectation -> Expectation
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Map (Credential 'ColdCommitteeRole) CommitteeMemberState -> Bool
forall k a. Map k a -> Bool
Map.null Map (Credential 'ColdCommitteeRole) CommitteeMemberState
noExpiration) (Expectation -> Expectation) -> Expectation -> Expectation
forall a b. (a -> b) -> a -> b
$
        -- only Unrecognized members should have no expiration
        [MemberStatus] -> Set MemberStatus
forall a. Ord a => [a] -> Set a
Set.fromList (CommitteeMemberState -> MemberStatus
cmsStatus (CommitteeMemberState -> MemberStatus)
-> [CommitteeMemberState] -> [MemberStatus]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
-> [CommitteeMemberState]
forall k a. Map k a -> [a]
Map.elems Map (Credential 'ColdCommitteeRole) CommitteeMemberState
noExpiration) Set MemberStatus -> Set MemberStatus -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` MemberStatus -> Set MemberStatus
forall a. a -> Set a
Set.singleton MemberStatus
Unrecognized

genCommittee ::
  forall era.
  Gen (Maybe (Committee era))
genCommittee :: forall era. Gen (Maybe (Committee era))
genCommittee = [(Int, Gen (Maybe (Committee era)))] -> Gen (Maybe (Committee era))
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency [(Int
1, Maybe (Committee era) -> Gen (Maybe (Committee era))
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Committee era)
forall a. Maybe a
Nothing), (Int
9, Committee era -> Maybe (Committee era)
forall a. a -> Maybe a
Just (Committee era -> Maybe (Committee era))
-> Gen (Committee era) -> Gen (Maybe (Committee era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
forall era.
Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
genCommittee' Gen [Credential 'ColdCommitteeRole]
forall a. Arbitrary a => Gen a
arbitrary)]

genRelevantCommitteeState ::
  forall era.
  Maybe (Committee era) ->
  Maybe (Committee era) ->
  Gen (CommitteeState era)
genRelevantCommitteeState :: forall era.
Maybe (Committee era)
-> Maybe (Committee era) -> Gen (CommitteeState era)
genRelevantCommitteeState Maybe (Committee era)
maybeCm Maybe (Committee era)
maybeNextCm = do
  [Credential 'ColdCommitteeRole]
membersRetaining <-
    [Credential 'ColdCommitteeRole]
-> [Credential 'ColdCommitteeRole]
-> [Credential 'ColdCommitteeRole]
forall a. [a] -> [a] -> [a]
(++)
      ([Credential 'ColdCommitteeRole]
 -> [Credential 'ColdCommitteeRole]
 -> [Credential 'ColdCommitteeRole])
-> Gen [Credential 'ColdCommitteeRole]
-> Gen
     ([Credential 'ColdCommitteeRole]
      -> [Credential 'ColdCommitteeRole])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
forall era.
Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
genMembersRetaining Maybe (Committee era)
maybeCm
      Gen
  ([Credential 'ColdCommitteeRole]
   -> [Credential 'ColdCommitteeRole])
-> Gen [Credential 'ColdCommitteeRole]
-> Gen [Credential 'ColdCommitteeRole]
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
forall era.
Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
genMembersRetaining Maybe (Committee era)
maybeNextCm
  [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
pairs <- [Credential 'ColdCommitteeRole]
-> [CommitteeAuthorization]
-> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'ColdCommitteeRole]
membersRetaining ([CommitteeAuthorization]
 -> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)])
-> Gen [CommitteeAuthorization]
-> Gen [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [CommitteeAuthorization]
forall a. Arbitrary a => Gen a
arbitrary
  CommitteeState era -> Gen (CommitteeState era)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommitteeState era -> Gen (CommitteeState era))
-> CommitteeState era -> Gen (CommitteeState era)
forall a b. (a -> b) -> a -> b
$ Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> CommitteeState era
forall era.
Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> CommitteeState era
CommitteeState (Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
 -> CommitteeState era)
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> CommitteeState era
forall a b. (a -> b) -> a -> b
$ [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
pairs

genNextCommittee ::
  forall era.
  Maybe (Committee era) ->
  Gen (Maybe (Committee era))
genNextCommittee :: forall era. Maybe (Committee era) -> Gen (Maybe (Committee era))
genNextCommittee Maybe (Committee era)
maybeCm =
  [Gen (Maybe (Committee era))] -> Gen (Maybe (Committee era))
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Maybe (Committee era) -> Gen (Maybe (Committee era))
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Committee era)
forall a. Maybe a
Nothing, Committee era -> Maybe (Committee era)
forall a. a -> Maybe a
Just (Committee era -> Maybe (Committee era))
-> Gen (Committee era) -> Gen (Maybe (Committee era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
forall era.
Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
genCommittee' (Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
forall era.
Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
genMembersRetaining Maybe (Committee era)
maybeCm)]

genCommittee' :: Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
genCommittee' :: forall era.
Gen [Credential 'ColdCommitteeRole] -> Gen (Committee era)
genCommittee' Gen [Credential 'ColdCommitteeRole]
genCreds = do
  [Credential 'ColdCommitteeRole]
creds <- Gen [Credential 'ColdCommitteeRole]
genCreds
  [(Credential 'ColdCommitteeRole, EpochNo)]
m <- [Credential 'ColdCommitteeRole]
-> [EpochNo] -> [(Credential 'ColdCommitteeRole, EpochNo)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Credential 'ColdCommitteeRole]
creds ([EpochNo] -> [(Credential 'ColdCommitteeRole, EpochNo)])
-> Gen [EpochNo] -> Gen [(Credential 'ColdCommitteeRole, EpochNo)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen EpochNo -> Gen [EpochNo]
forall a. Gen a -> Gen [a]
listOf (Word64 -> EpochNo
EpochNo (Word64 -> EpochNo) -> Gen Word64 -> Gen EpochNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Word64, Word64) -> Gen Word64
forall a. (Bounded a, Integral a) => (a, a) -> Gen a
chooseBoundedIntegral (Word64
0, Word64
20))
  Map (Credential 'ColdCommitteeRole) EpochNo
-> UnitInterval -> Committee era
forall era.
Map (Credential 'ColdCommitteeRole) EpochNo
-> UnitInterval -> Committee era
Committee ([(Credential 'ColdCommitteeRole, EpochNo)]
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(Credential 'ColdCommitteeRole, EpochNo)]
m) (UnitInterval -> Committee era)
-> Gen UnitInterval -> Gen (Committee era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen UnitInterval
forall a. Arbitrary a => Gen a
arbitrary

genRelevantColdCredsFilter ::
  forall era.
  Maybe (Committee era) ->
  CommitteeState era ->
  Gen (Set.Set (Credential 'ColdCommitteeRole))
genRelevantColdCredsFilter :: forall era.
Maybe (Committee era)
-> CommitteeState era -> Gen (Set (Credential 'ColdCommitteeRole))
genRelevantColdCredsFilter Maybe (Committee era)
maybeCm (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) = do
  [Credential 'ColdCommitteeRole]
creds <-
    [Credential 'ColdCommitteeRole]
-> [Credential 'ColdCommitteeRole]
-> [Credential 'ColdCommitteeRole]
forall a. [a] -> [a] -> [a]
(++)
      ([Credential 'ColdCommitteeRole]
 -> [Credential 'ColdCommitteeRole]
 -> [Credential 'ColdCommitteeRole])
-> Gen [Credential 'ColdCommitteeRole]
-> Gen
     ([Credential 'ColdCommitteeRole]
      -> [Credential 'ColdCommitteeRole])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
forall era.
Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
genMembersRetaining Maybe (Committee era)
maybeCm
      Gen
  ([Credential 'ColdCommitteeRole]
   -> [Credential 'ColdCommitteeRole])
-> Gen [Credential 'ColdCommitteeRole]
-> Gen [Credential 'ColdCommitteeRole]
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Credential 'ColdCommitteeRole]
-> Gen [Credential 'ColdCommitteeRole]
forall a. Arbitrary a => [a] -> Gen [a]
genRetaining (Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> [Credential 'ColdCommitteeRole]
forall k a. Map k a -> [k]
Map.keys Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers)
  Set (Credential 'ColdCommitteeRole)
-> Gen (Set (Credential 'ColdCommitteeRole))
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Set (Credential 'ColdCommitteeRole)
 -> Gen (Set (Credential 'ColdCommitteeRole)))
-> Set (Credential 'ColdCommitteeRole)
-> Gen (Set (Credential 'ColdCommitteeRole))
forall a b. (a -> b) -> a -> b
$ [Credential 'ColdCommitteeRole]
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => [a] -> Set a
Set.fromList [Credential 'ColdCommitteeRole]
creds

genRelevantHotCredsFilter ::
  forall era.
  CommitteeState era ->
  Gen (Set.Set (Credential 'HotCommitteeRole))
genRelevantHotCredsFilter :: forall era.
CommitteeState era -> Gen (Set (Credential 'HotCommitteeRole))
genRelevantHotCredsFilter (CommitteeState Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers) =
  [Credential 'HotCommitteeRole]
-> Set (Credential 'HotCommitteeRole)
forall a. Ord a => [a] -> Set a
Set.fromList
    ([Credential 'HotCommitteeRole]
 -> Set (Credential 'HotCommitteeRole))
-> Gen [Credential 'HotCommitteeRole]
-> Gen (Set (Credential 'HotCommitteeRole))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Credential 'HotCommitteeRole]
-> Gen [Credential 'HotCommitteeRole]
forall a. Arbitrary a => [a] -> Gen [a]
genRetaining
      [Credential 'HotCommitteeRole
hk | (Credential 'ColdCommitteeRole
_, CommitteeHotCredential Credential 'HotCommitteeRole
hk) <- Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers]

genMembersRetaining ::
  forall era.
  Maybe (Committee era) ->
  Gen [Credential 'ColdCommitteeRole]
genMembersRetaining :: forall era.
Maybe (Committee era) -> Gen [Credential 'ColdCommitteeRole]
genMembersRetaining Maybe (Committee era)
maybeCm =
  [Credential 'ColdCommitteeRole]
-> Gen [Credential 'ColdCommitteeRole]
forall a. Arbitrary a => [a] -> Gen [a]
genRetaining ([Credential 'ColdCommitteeRole]
 -> Gen [Credential 'ColdCommitteeRole])
-> [Credential 'ColdCommitteeRole]
-> Gen [Credential 'ColdCommitteeRole]
forall a b. (a -> b) -> a -> b
$ Map (Credential 'ColdCommitteeRole) EpochNo
-> [Credential 'ColdCommitteeRole]
forall k a. Map k a -> [k]
Map.keys (Map (Credential 'ColdCommitteeRole) EpochNo
 -> [Credential 'ColdCommitteeRole])
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> [Credential 'ColdCommitteeRole]
forall a b. (a -> b) -> a -> b
$ (Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo)
-> Maybe (Committee era)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
Committee era -> Map (Credential 'ColdCommitteeRole) 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 <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ret)
  [a]
new <- Gen [a]
forall a. Arbitrary a => Gen a
arbitrary
  [a] -> Gen [a]
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a] -> Gen [a]) -> [a] -> Gen [a]
forall a b. (a -> b) -> a -> b
$ [a]
new [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
retSize [a]
ret

withCommitteeInfo ::
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  ( Map.Map (Credential 'ColdCommitteeRole) EpochNo -> -- current committee members
    CommitteeState era ->
    Map.Map (Credential 'ColdCommitteeRole) EpochNo -> -- next epoch committee members
    CommitteeMembersState ->
    Expectation
  ) ->
  Expectation
withCommitteeInfo :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeState era
    -> Map (Credential 'ColdCommitteeRole) EpochNo
    -> CommitteeMembersState
    -> Expectation)
-> Expectation
withCommitteeInfo NewEpochState era
nes Map (Credential 'ColdCommitteeRole) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> CommitteeMembersState
-> Expectation
expectation = Map (Credential 'ColdCommitteeRole) EpochNo
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole) EpochNo
-> CommitteeMembersState
-> Expectation
expectation Map (Credential 'ColdCommitteeRole) EpochNo
comMembers CommitteeState era
comState Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers CommitteeMembersState
noFilterQueryResult
  where
    noFilterQueryResult :: CommitteeMembersState
noFilterQueryResult = NewEpochState era -> CommitteeMembersState
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> CommitteeMembersState
queryCommitteeMembersStateNoFilters NewEpochState era
nes
    (Map (Credential 'ColdCommitteeRole) EpochNo
comMembers, CommitteeState era
comState, Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers) = NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo,
    CommitteeState era, Map (Credential 'ColdCommitteeRole) EpochNo)
forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo,
    CommitteeState era, Map (Credential 'ColdCommitteeRole) EpochNo)
committeeInfo NewEpochState era
nes

committeeInfo ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  ( Map.Map (Credential 'ColdCommitteeRole) EpochNo
  , CommitteeState era
  , Map.Map (Credential 'ColdCommitteeRole) EpochNo
  )
committeeInfo :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> (Map (Credential 'ColdCommitteeRole) EpochNo,
    CommitteeState era, Map (Credential 'ColdCommitteeRole) EpochNo)
committeeInfo NewEpochState era
nes =
  let ledgerState :: LedgerState era
ledgerState = NewEpochState era
nes NewEpochState era
-> Getting (LedgerState era) (NewEpochState era) (LedgerState era)
-> LedgerState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (LedgerState era) (EpochState era))
-> NewEpochState era -> Const (LedgerState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEpochStateL ((EpochState era -> Const (LedgerState era) (EpochState era))
 -> NewEpochState era
 -> Const (LedgerState era) (NewEpochState era))
-> ((LedgerState era -> Const (LedgerState era) (LedgerState era))
    -> EpochState era -> Const (LedgerState era) (EpochState era))
-> Getting (LedgerState era) (NewEpochState era) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Const (LedgerState era) (LedgerState era))
-> EpochState era -> Const (LedgerState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL
      govState :: GovState era
govState = LedgerState era
ledgerState LedgerState era
-> Getting (GovState era) (LedgerState era) (GovState era)
-> GovState era
forall s a. s -> Getting a s a -> a
^. (UTxOState era -> Const (GovState era) (UTxOState era))
-> LedgerState era -> Const (GovState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(UTxOState era -> f (UTxOState era))
-> LedgerState era -> f (LedgerState era)
lsUTxOStateL ((UTxOState era -> Const (GovState era) (UTxOState era))
 -> LedgerState era -> Const (GovState era) (LedgerState era))
-> ((GovState era -> Const (GovState era) (GovState era))
    -> UTxOState era -> Const (GovState era) (UTxOState era))
-> Getting (GovState era) (LedgerState era) (GovState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GovState era -> Const (GovState era) (GovState era))
-> UTxOState era -> Const (GovState era) (UTxOState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> UTxOState era -> f (UTxOState era)
utxosGovStateL
      comMembers :: Map (Credential 'ColdCommitteeRole) EpochNo
comMembers =
        (Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo)
-> Maybe (Committee era)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
committeeMembers (Maybe (Committee era)
 -> Map (Credential 'ColdCommitteeRole) EpochNo)
-> Maybe (Committee era)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall a b. (a -> b) -> a -> b
$
          StrictMaybe (Committee era) -> Maybe (Committee era)
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe (GovState era
govState GovState era
-> Getting
     (StrictMaybe (Committee era))
     (GovState era)
     (StrictMaybe (Committee era))
-> StrictMaybe (Committee era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Committee era))
  (GovState era)
  (StrictMaybe (Committee era))
forall era.
ConwayEraGov era =>
Lens' (GovState era) (StrictMaybe (Committee era))
Lens' (GovState era) (StrictMaybe (Committee era))
committeeGovStateL)
      comState :: CommitteeState era
comState = LedgerState era
ledgerState LedgerState era
-> Getting
     (CommitteeState era) (LedgerState era) (CommitteeState era)
-> CommitteeState era
forall s a. s -> Getting a s a -> a
^. (CertState era -> Const (CommitteeState era) (CertState era))
-> LedgerState era -> Const (CommitteeState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Const (CommitteeState era) (CertState era))
 -> LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> CertState era -> Const (CommitteeState era) (CertState era))
-> Getting
     (CommitteeState era) (LedgerState era) (CommitteeState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era -> Const (CommitteeState era) (VState era))
-> CertState era -> Const (CommitteeState era) (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL ((VState era -> Const (CommitteeState era) (VState era))
 -> CertState era -> Const (CommitteeState era) (CertState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> VState era -> Const (CommitteeState era) (VState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> CertState era
-> Const (CommitteeState era) (CertState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CommitteeState era
 -> Const (CommitteeState era) (CommitteeState era))
-> VState era -> Const (CommitteeState era) (VState era)
forall era (f :: * -> *).
Functor f =>
(CommitteeState era -> f (CommitteeState era))
-> VState era -> f (VState era)
vsCommitteeStateL
      nextCommitteeMembers :: Map (Credential 'ColdCommitteeRole) EpochNo
nextCommitteeMembers = NewEpochState era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
ConwayEraGov era =>
NewEpochState era -> Map (Credential 'ColdCommitteeRole) EpochNo
getNextEpochCommitteeMembers NewEpochState era
nes
   in (Map (Credential 'ColdCommitteeRole) EpochNo
comMembers, CommitteeState era
comState, Map (Credential 'ColdCommitteeRole) EpochNo
nextCommitteeMembers)

queryCommitteeMembersStateNoFilters ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  CommitteeMembersState
queryCommitteeMembersStateNoFilters :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era -> CommitteeMembersState
queryCommitteeMembersStateNoFilters =
  forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> CommitteeMembersState
queryCommitteeMembersState @era
    Set (Credential 'ColdCommitteeRole)
forall a. Set a
Set.empty
    Set (Credential 'HotCommitteeRole)
forall a. Set a
Set.empty
    Set MemberStatus
forall a. Set a
Set.empty