{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Test.Cardano.Ledger.UMapSpec where

import Cardano.Ledger.BaseTypes (StrictMaybe (SJust, SNothing))
import Cardano.Ledger.Coin (Coin, CompactForm)
import Cardano.Ledger.Compactible (fromCompact)
import Cardano.Ledger.Credential (Credential, Ptr)
import Cardano.Ledger.DRep (DRep)
import Cardano.Ledger.Keys (KeyHash, KeyRole (StakePool, Staking))
import Cardano.Ledger.UMap (
  RDPair (RDPair, rdReward),
  StakeCredentials (..),
  UMElem (UMElem),
  UMap (UMap, umElems, umPtrs),
  UView (DRepUView, PtrUView, RewDepUView, SPoolUView),
  addCompact,
  compactRewardMap,
  dRepMap,
  delete,
  delete',
  depositMap,
  domRestrict,
  domRestrictedMap,
  domRestrictedStakeCredentials,
  domain,
  empty,
  insert,
  insert',
  invPtrMap,
  member,
  nullUView,
  ptrMap,
  range,
  rdDeposit,
  rdPairMap,
  rewardMap,
  sPoolMap,
  size,
  toStakeCredentials,
  umInvariant,
  unUView,
  unUnify,
  unify,
  (∪),
  (∪+),
  (⋪),
  (⋫),
  (⨃),
 )
import qualified Cardano.Ledger.UMap as UMap (lookup)
import Control.Exception (assert)
import Data.Foldable (Foldable (fold))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary (
  genInsertDeleteRoundtripDRep,
  genInsertDeleteRoundtripPtr,
  genInsertDeleteRoundtripRDPair,
  genInsertDeleteRoundtripSPool,
  genInvariantNonEmpty,
  genRightPreferenceUMap,
  genValidTuples,
  genValidUMap,
  genValidUMapWithCreds,
 )

data Action
  = InsertRDPair (Credential 'Staking) RDPair
  | InsertPtr Ptr (Credential 'Staking)
  | InsertSPool (Credential 'Staking) (KeyHash 'StakePool)
  | InsertDRep (Credential 'Staking) DRep
  | DeleteRDPair (Credential 'Staking)
  | DeletePtr Ptr
  | DeleteSPool (Credential 'Staking)
  | DeleteDRep (Credential 'Staking)
  deriving (Int -> Action -> ShowS
[Action] -> ShowS
Action -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Action] -> ShowS
$cshowList :: [Action] -> ShowS
show :: Action -> String
$cshow :: Action -> String
showsPrec :: Int -> Action -> ShowS
$cshowsPrec :: Int -> Action -> ShowS
Show)

instance Arbitrary Action where
  arbitrary :: Gen Action
arbitrary =
    forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ Credential 'Staking -> RDPair -> Action
InsertRDPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      , Ptr -> Credential 'Staking -> Action
InsertPtr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      , Credential 'Staking -> KeyHash 'StakePool -> Action
InsertSPool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary
      , Credential 'Staking -> Action
DeleteRDPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , Ptr -> Action
DeletePtr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , Credential 'Staking -> Action
DeleteSPool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      , Credential 'Staking -> Action
DeleteDRep forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
      ]

genRDPair :: Gen Action
genRDPair :: Gen Action
genRDPair = Credential 'Staking -> RDPair -> Action
InsertRDPair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

genPtr :: Gen Action
genPtr :: Gen Action
genPtr = Ptr -> Credential 'Staking -> Action
InsertPtr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

genSPool :: Gen Action
genSPool :: Gen Action
genSPool = Credential 'Staking -> KeyHash 'StakePool -> Action
InsertSPool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

genDRep :: Gen Action
genDRep :: Gen Action
genDRep = Credential 'Staking -> DRep -> Action
InsertDRep forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary

reify :: Action -> UMap -> UMap
reify :: Action -> UMap -> UMap
reify = \case
  InsertRDPair Credential 'Staking
k RDPair
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k RDPair
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) RDPair
RewDepUView
  InsertPtr Ptr
k Credential 'Staking
v -> forall k v. k -> v -> UView k v -> UMap
insert Ptr
k Credential 'Staking
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView Ptr (Credential 'Staking)
PtrUView
  InsertSPool Credential 'Staking
k KeyHash 'StakePool
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k KeyHash 'StakePool
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView
  InsertDRep Credential 'Staking
k DRep
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k DRep
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) DRep
DRepUView
  DeleteRDPair Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) RDPair
RewDepUView
  DeletePtr Ptr
k -> forall k v. k -> UView k v -> UMap
delete Ptr
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView Ptr (Credential 'Staking)
PtrUView
  DeleteSPool Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView
  DeleteDRep Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) DRep
DRepUView

reifyRDPair :: Action -> UMap -> UMap
reifyRDPair :: Action -> UMap -> UMap
reifyRDPair = \case
  InsertRDPair Credential 'Staking
k RDPair
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k RDPair
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) RDPair
RewDepUView
  DeleteRDPair Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) RDPair
RewDepUView
  Action
_ -> forall a. a -> a
id

reifyPtr :: Action -> UMap -> UMap
reifyPtr :: Action -> UMap -> UMap
reifyPtr = \case
  InsertPtr Ptr
k Credential 'Staking
v -> forall k v. k -> v -> UView k v -> UMap
insert Ptr
k Credential 'Staking
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView Ptr (Credential 'Staking)
PtrUView
  DeletePtr Ptr
k -> forall k v. k -> UView k v -> UMap
delete Ptr
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView Ptr (Credential 'Staking)
PtrUView
  Action
_ -> forall a. a -> a
id

reifySPool :: Action -> UMap -> UMap
reifySPool :: Action -> UMap -> UMap
reifySPool = \case
  InsertSPool Credential 'Staking
k KeyHash 'StakePool
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k KeyHash 'StakePool
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView
  DeleteSPool Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView
  Action
_ -> forall a. a -> a
id

reifyDRep :: Action -> UMap -> UMap
reifyDRep :: Action -> UMap -> UMap
reifyDRep = \case
  InsertDRep Credential 'Staking
k DRep
v -> forall k v. k -> v -> UView k v -> UMap
insert Credential 'Staking
k DRep
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) DRep
DRepUView
  DeleteDRep Credential 'Staking
k -> forall k v. k -> UView k v -> UMap
delete Credential 'Staking
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. UMap -> UView (Credential 'Staking) DRep
DRepUView
  Action
_ -> forall a. a -> a
id

runActions :: [Action] -> UMap -> UMap
runActions :: [Action] -> UMap -> UMap
runActions [Action]
actions UMap
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap -> UMap
reify UMap
umap [Action]
actions

runRDPairs :: [Action] -> UMap -> UMap
runRDPairs :: [Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap -> UMap
reifyRDPair UMap
umap [Action]
actions

runPtrs :: [Action] -> UMap -> UMap
runPtrs :: [Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap -> UMap
reifyPtr UMap
umap [Action]
actions

runSPools :: [Action] -> UMap -> UMap
runSPools :: [Action] -> UMap -> UMap
runSPools [Action]
actions UMap
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap -> UMap
reifySPool UMap
umap [Action]
actions

runDReps :: [Action] -> UMap -> UMap
runDReps :: [Action] -> UMap -> UMap
runDReps [Action]
actions UMap
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap -> UMap
reifyDRep UMap
umap [Action]
actions

sizeTest ::
  ( Map.Map (Credential 'Staking) RDPair
  , Map.Map Ptr (Credential 'Staking)
  , Map.Map (Credential 'Staking) (KeyHash 'StakePool)
  , Map.Map (Credential 'Staking) DRep
  ) ->
  IO ()
sizeTest :: (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
 Map (Credential 'Staking) (KeyHash 'StakePool),
 Map (Credential 'Staking) DRep)
-> IO ()
sizeTest (Map (Credential 'Staking) RDPair
rdPairs, Map Ptr (Credential 'Staking)
ptrs, Map (Credential 'Staking) (KeyHash 'StakePool)
sPools, Map (Credential 'Staking) DRep
dReps) = do
  let
    umap :: UMap
umap = Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rdPairs Map Ptr (Credential 'Staking)
ptrs Map (Credential 'Staking) (KeyHash 'StakePool)
sPools Map (Credential 'Staking) DRep
dReps
    rdPairsSize :: Int
rdPairsSize = forall k v. UView k v -> Int
size (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap)
    ptrsSize :: Int
ptrsSize = forall k v. UView k v -> Int
size (UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
umap)
    sPoolSize :: Int
sPoolSize = forall k v. UView k v -> Int
size (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
umap)
    dRepSize :: Int
dRepSize = forall k v. UView k v -> Int
size (UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
umap)
  forall k a. Map k a -> Int
Map.size Map (Credential 'Staking) RDPair
rdPairs forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
rdPairsSize
  forall k a. Map k a -> Int
Map.size Map Ptr (Credential 'Staking)
ptrs forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
ptrsSize
  forall k a. Map k a -> Int
Map.size Map (Credential 'Staking) (KeyHash 'StakePool)
sPools forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
sPoolSize
  forall k a. Map k a -> Int
Map.size Map (Credential 'Staking) DRep
dReps forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
dRepSize

unifyRoundTripTo ::
  ( Map.Map (Credential 'Staking) RDPair
  , Map.Map Ptr (Credential 'Staking)
  , Map.Map (Credential 'Staking) (KeyHash 'StakePool)
  , Map.Map (Credential 'Staking) DRep
  ) ->
  IO ()
unifyRoundTripTo :: (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
 Map (Credential 'Staking) (KeyHash 'StakePool),
 Map (Credential 'Staking) DRep)
-> IO ()
unifyRoundTripTo (Map (Credential 'Staking) RDPair
rdPairs, Map Ptr (Credential 'Staking)
ptrs, Map (Credential 'Staking) (KeyHash 'StakePool)
sPools, Map (Credential 'Staking) DRep
dReps) = do
  let umap :: UMap
umap = Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rdPairs Map Ptr (Credential 'Staking)
ptrs Map (Credential 'Staking) (KeyHash 'StakePool)
sPools Map (Credential 'Staking) DRep
dReps
  UMap -> Map (Credential 'Staking) RDPair
rdPairMap UMap
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map (Credential 'Staking) RDPair
rdPairs
  UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map Ptr (Credential 'Staking)
ptrs
  UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map (Credential 'Staking) (KeyHash 'StakePool)
sPools
  UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map (Credential 'Staking) DRep
dReps

unifyRoundTripFrom :: [Action] -> Property
unifyRoundTripFrom :: [Action] -> Property
unifyRoundTripFrom [Action]
actions =
  let
    umap :: UMap
umap = [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty
    rdPairs :: Map (Credential 'Staking) RDPair
rdPairs = UMap -> Map (Credential 'Staking) RDPair
rdPairMap UMap
umap
    ptrs :: Map Ptr (Credential 'Staking)
ptrs = UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
umap
    sPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
sPools = UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
umap
    dReps :: Map (Credential 'Staking) DRep
dReps = UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
umap
   in
    UMap
umap forall a. (Eq a, Show a) => a -> a -> Property
=== Map (Credential 'Staking) RDPair
-> Map Ptr (Credential 'Staking)
-> Map (Credential 'Staking) (KeyHash 'StakePool)
-> Map (Credential 'Staking) DRep
-> UMap
unify Map (Credential 'Staking) RDPair
rdPairs Map Ptr (Credential 'Staking)
ptrs Map (Credential 'Staking) (KeyHash 'StakePool)
sPools Map (Credential 'Staking) DRep
dReps

oldUnionRewAgg ::
  UView (Credential 'Staking) RDPair ->
  Map (Credential 'Staking) (CompactForm Coin) ->
  UMap
(RewDepUView UMap {Map (Credential 'Staking) UMElem
umElems :: Map (Credential 'Staking) UMElem
umElems :: UMap -> Map (Credential 'Staking) UMElem
umElems, Map Ptr (Credential 'Staking)
umPtrs :: Map Ptr (Credential 'Staking)
umPtrs :: UMap -> Map Ptr (Credential 'Staking)
umPtrs}) oldUnionRewAgg :: UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
`oldUnionRewAgg` Map (Credential 'Staking) (CompactForm Coin)
aggRewMap = Map (Credential 'Staking) UMElem
-> Map Ptr (Credential 'Staking) -> UMap
UMap Map (Credential 'Staking) UMElem
newUmElem Map Ptr (Credential 'Staking)
umPtrs
  where
    newUmElem :: Map (Credential 'Staking) UMElem
newUmElem =
      let
        result :: Map (Credential 'Staking) UMElem
result = forall k a b c.
Ord k =>
(k -> a -> b -> Maybe c)
-> (Map k a -> Map k c)
-> (Map k b -> Map k c)
-> Map k a
-> Map k b
-> Map k c
Map.mergeWithKey forall {p}. p -> UMElem -> CompactForm Coin -> Maybe UMElem
f forall a. a -> a
id (forall a b. a -> b -> a
const forall k a. Map k a
Map.empty) Map (Credential 'Staking) UMElem
umElems Map (Credential 'Staking) (CompactForm Coin)
aggRewMap
        f :: p -> UMElem -> CompactForm Coin -> Maybe UMElem
f p
_k (UMElem StrictMaybe RDPair
p1 Set Ptr
s StrictMaybe (KeyHash 'StakePool)
deposit StrictMaybe DRep
drep) CompactForm Coin
delta = forall a. a -> Maybe a
Just (StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool)
-> StrictMaybe DRep
-> UMElem
UMElem (CompactForm Coin -> StrictMaybe RDPair -> StrictMaybe RDPair
addC CompactForm Coin
delta StrictMaybe RDPair
p1) Set Ptr
s StrictMaybe (KeyHash 'StakePool)
deposit StrictMaybe DRep
drep)
       in
        -- We use Map.empty below because aggRewMap is a subset of umElems, we never add anything here.
        forall a. HasCallStack => Bool -> a -> a
assert (forall k a. Ord k => Map k a -> Bool
Map.valid Map (Credential 'Staking) UMElem
result) Map (Credential 'Staking) UMElem
result
    addC :: CompactForm Coin -> StrictMaybe RDPair -> StrictMaybe RDPair
    addC :: CompactForm Coin -> StrictMaybe RDPair -> StrictMaybe RDPair
addC CompactForm Coin
newR = \case
      StrictMaybe RDPair
SNothing -> forall a. StrictMaybe a
SNothing
      SJust (RDPair CompactForm Coin
r CompactForm Coin
d) -> forall a. a -> StrictMaybe a
SJust forall a b. (a -> b) -> a -> b
$ CompactForm Coin -> CompactForm Coin -> RDPair
RDPair (CompactForm Coin -> CompactForm Coin -> CompactForm Coin
addCompact CompactForm Coin
r CompactForm Coin
newR) CompactForm Coin
d

spec :: Spec
spec :: Spec
spec = do
  forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"UMap" forall a b. (a -> b) -> a -> b
$ do
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Invariant" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Empty" (\(Credential 'Staking
cred :: Credential 'Staking) Ptr
ptr -> Credential 'Staking -> Ptr -> UMap -> Bool
umInvariant Credential 'Staking
cred Ptr
ptr UMap
empty)
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Non-empty" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (Credential 'Staking, Ptr, UMap)
genInvariantNonEmpty
          (\(Credential 'Staking
cred, Ptr
ptr, UMap
umap) -> Credential 'Staking -> Ptr -> UMap -> Bool
umInvariant Credential 'Staking
cred Ptr
ptr UMap
umap)
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
xprop String
"Non-empty with insert and delete actions" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Credential 'Staking, Ptr, UMap)
genInvariantNonEmpty forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary)
          (\((Credential 'Staking
cred, Ptr
ptr, UMap
umap), [Action]
actions) -> Credential 'Staking -> Ptr -> UMap -> Bool
umInvariant Credential 'Staking
cred Ptr
ptr forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
umap)
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Unify roundtrip" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"To" forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuples (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
 Map (Credential 'Staking) (KeyHash 'StakePool),
 Map (Credential 'Staking) DRep)
-> IO ()
unifyRoundTripTo
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"From" [Action] -> Property
unifyRoundTripFrom
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Insert-delete roundtrip" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"RDPair" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Credential 'Staking, RDPair)
genInsertDeleteRoundtripRDPair
          (\(UMap
umap, Credential 'Staking
k, RDPair
v) -> UMap
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> UMap
unUView (forall k v. k -> UView k v -> UView k v
delete' Credential 'Staking
k (forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k RDPair
v (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap))))
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PtrUView" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Ptr, Credential 'Staking)
genInsertDeleteRoundtripPtr
          (\(UMap
umap, Ptr
k, Credential 'Staking
v) -> UMap
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> UMap
unUView (forall k v. k -> UView k v -> UView k v
delete' Ptr
k (forall k v. k -> v -> UView k v -> UView k v
insert' Ptr
k Credential 'Staking
v (UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
umap))))
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SPoolUView" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Credential 'Staking, KeyHash 'StakePool)
genInsertDeleteRoundtripSPool
          (\(UMap
umap, Credential 'Staking
k, KeyHash 'StakePool
v) -> UMap
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> UMap
unUView (forall k v. k -> UView k v -> UView k v
delete' Credential 'Staking
k (forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k KeyHash 'StakePool
v (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
umap))))
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"DRepUView" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Credential 'Staking, DRep)
genInsertDeleteRoundtripDRep
          (\(UMap
umap, Credential 'Staking
k, DRep
v) -> UMap
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> UMap
unUView (forall k v. k -> UView k v -> UView k v
delete' Credential 'Staking
k (forall k v. k -> v -> UView k v -> UView k v
insert' Credential 'Staking
k DRep
v (UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
umap))))
    forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Size" forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen
  (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
   Map (Credential 'Staking) (KeyHash 'StakePool),
   Map (Credential 'Staking) DRep)
genValidTuples (Map (Credential 'Staking) RDPair, Map Ptr (Credential 'Staking),
 Map (Credential 'Staking) (KeyHash 'StakePool),
 Map (Credential 'Staking) DRep)
-> IO ()
sizeTest
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Membership" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \(UMap
umap :: UMap, Credential 'Staking
cred) ->
            forall k v. k -> UView k v -> Bool
member Credential 'Staking
cred (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking
cred (UMap -> Map (Credential 'Staking) RDPair
rdPairMap UMap
umap)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUViews"
        ( \(UMap
umap :: UMap, Ptr
ptr) ->
            forall k v. k -> UView k v -> Bool
member Ptr
ptr (UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Ptr
ptr (UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
umap)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \(UMap
umap :: UMap, Credential 'Staking
cred) ->
            forall k v. k -> UView k v -> Bool
member Credential 'Staking
cred (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking
cred (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
umap)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \(UMap
umap :: UMap, Credential 'Staking
cred) ->
            forall k v. k -> UView k v -> Bool
member Credential 'Staking
cred (UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking
cred (UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
umap)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Bisimulation" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions ->
            UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty)
              forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions ->
            UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty)
              forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions ->
            UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty)
              forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions ->
            UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty)
              forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Null" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Bool
Map.null (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Bool
nullUView (UMap -> UView (Credential 'Staking) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Bool
Map.null (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Bool
nullUView (UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Bool
Map.null (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Bool
nullUView (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Bool
Map.null (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Bool
nullUView (UMap -> UView (Credential 'Staking) DRep
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Lookup" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions Credential 'Staking
cred ->
            forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. k -> UView k v -> Maybe v
UMap.lookup Credential 'Staking
cred (UMap -> UView (Credential 'Staking) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtruView"
        ( \[Action]
actions Ptr
ptr ->
            forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Ptr
ptr (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. k -> UView k v -> Maybe v
UMap.lookup Ptr
ptr (UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions Credential 'Staking
cred ->
            forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. k -> UView k v -> Maybe v
UMap.lookup Credential 'Staking
cred (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions Credential 'Staking
cred ->
            forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
cred (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. k -> UView k v -> Maybe v
UMap.lookup Credential 'Staking
cred (UMap -> UView (Credential 'Staking) DRep
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Domain" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Set k
Map.keysSet (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set k
domain (UMap -> UView (Credential 'Staking) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Set k
Map.keysSet (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set k
domain (UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Set k
Map.keysSet (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set k
domain (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions ->
            forall k a. Map k a -> Set k
Map.keysSet (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set k
domain (UMap -> UView (Credential 'Staking) DRep
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Range" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions ->
            forall a. Ord a => [a] -> Set a
Set.fromList (forall k a. Map k a -> [a]
Map.elems (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty)))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set v
range (UMap -> UView (Credential 'Staking) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions ->
            forall a. Ord a => [a] -> Set a
Set.fromList (forall k a. Map k a -> [a]
Map.elems (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty)))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set v
range (UMap -> UView Ptr (Credential 'Staking)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions ->
            forall a. Ord a => [a] -> Set a
Set.fromList (forall k a. Map k a -> [a]
Map.elems (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty)))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set v
range (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions ->
            forall a. Ord a => [a] -> Set a
Set.fromList (forall k a. Map k a -> [a]
Map.elems (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty)))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Set v
range (UMap -> UView (Credential 'Staking) DRep
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Union (left preference)" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions Credential 'Staking
cred RDPair
rdPair ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a b. a -> b -> a
const (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking
cred RDPair
rdPair)
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) RDPair
RewDepUView (UMap -> UView (Credential 'Staking) RDPair
RewDepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> (k, v) -> UMap
 (Credential 'Staking
cred, RDPair
rdPair)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions Ptr
cred Credential 'Staking
ptr ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a b. a -> b -> a
const (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty)) (forall k a. k -> a -> Map k a
Map.singleton Ptr
cred Credential 'Staking
ptr)
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView Ptr (Credential 'Staking)
PtrUView (UMap -> UView Ptr (Credential 'Staking)
PtrUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> (k, v) -> UMap
 (Ptr
cred, Credential 'Staking
ptr)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions Credential 'Staking
cred KeyHash 'StakePool
pool ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a b. a -> b -> a
const (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking
cred KeyHash 'StakePool
pool)
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> (k, v) -> UMap
 (Credential 'Staking
cred, KeyHash 'StakePool
pool)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions Credential 'Staking
cred DRep
pool ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a b. a -> b -> a
const (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking
cred DRep
pool)
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) DRep
DRepUView (UMap -> UView (Credential 'Staking) DRep
DRepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> (k, v) -> UMap
 (Credential 'Staking
cred, DRep
pool)))
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Union (right preference)" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView (domain of map on the right has to be subset of RewDepUView View)"
        forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Map (Credential 'Staking) RDPair)
genRightPreferenceUMap
          ( \(UMap
umap, Map (Credential 'Staking) RDPair
m) ->
              forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith
                (\(RDPair CompactForm Coin
_ CompactForm Coin
leftDep) (RDPair CompactForm Coin
rightRD CompactForm Coin
_) -> CompactForm Coin -> CompactForm Coin -> RDPair
RDPair CompactForm Coin
rightRD CompactForm Coin
leftDep)
                (UMap -> Map (Credential 'Staking) RDPair
rdPairMap UMap
umap)
                Map (Credential 'Staking) RDPair
m
                forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map (Credential 'Staking) RDPair
rdPairMap (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap forall k v. UView k v -> Map k v -> UMap
 Map (Credential 'Staking) RDPair
m)
          )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions Map Ptr (Credential 'Staking)
m ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\Credential 'Staking
_ Credential 'Staking
x -> Credential 'Staking
x) (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty)) Map Ptr (Credential 'Staking)
m
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView Ptr (Credential 'Staking)
PtrUView (UMap -> UView Ptr (Credential 'Staking)
PtrUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Map k v -> UMap
 Map Ptr (Credential 'Staking)
m))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions Map (Credential 'Staking) (KeyHash 'StakePool)
m ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\KeyHash 'StakePool
_ KeyHash 'StakePool
x -> KeyHash 'StakePool
x) (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty)) Map (Credential 'Staking) (KeyHash 'StakePool)
m
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Map k v -> UMap
 Map (Credential 'Staking) (KeyHash 'StakePool)
m))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions Map (Credential 'Staking) DRep
m ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\DRep
_ DRep
x -> DRep
x) (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty)) Map (Credential 'Staking) DRep
m
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) DRep
DRepUView (UMap -> UView (Credential 'Staking) DRep
DRepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Map k v -> UMap
 Map (Credential 'Staking) DRep
m))
        )
    forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
      String
"Monoidal Rewards (domain of map on the right has to be subset of RewDepUView View)"
      forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
        Gen (UMap, Map (Credential 'Staking) RDPair)
genRightPreferenceUMap
        ( \(UMap
umap, Map (Credential 'Staking) RDPair
m) ->
            forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a. Semigroup a => a -> a -> a
(<>) (UMap -> Map (Credential 'Staking) (CompactForm Coin)
compactRewardMap UMap
umap) (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking) RDPair
m)
              forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> Map (Credential 'Staking) (CompactForm Coin)
compactRewardMap (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
∪+ (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking) RDPair
m))
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Domain exclusion" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions Set (Credential 'Staking)
dom ->
            forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty)) Set (Credential 'Staking)
dom
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) RDPair
RewDepUView (Set (Credential 'Staking)
dom forall k v. Set k -> UView k v -> UMap
 UMap -> UView (Credential 'Staking) RDPair
RewDepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions Set Ptr
dom ->
            forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty)) Set Ptr
dom
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView Ptr (Credential 'Staking)
PtrUView (Set Ptr
dom forall k v. Set k -> UView k v -> UMap
 UMap -> UView Ptr (Credential 'Staking)
PtrUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions Set (Credential 'Staking)
dom ->
            forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty)) Set (Credential 'Staking)
dom
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView (Set (Credential 'Staking)
dom forall k v. Set k -> UView k v -> UMap
 UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions Set (Credential 'Staking)
dom ->
            forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty)) Set (Credential 'Staking)
dom
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) DRep
DRepUView (Set (Credential 'Staking)
dom forall k v. Set k -> UView k v -> UMap
 UMap -> UView (Credential 'Staking) DRep
DRepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)))
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Range exclusion" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions Set RDPair
rng ->
            forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Bool
Set.member Set RDPair
rng) (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) RDPair
RewDepUView (UMap -> UView (Credential 'Staking) RDPair
RewDepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Set v -> UMap
 Set RDPair
rng))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions Set (Credential 'Staking)
rng ->
            forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Bool
Set.member Set (Credential 'Staking)
rng) (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView Ptr (Credential 'Staking)
PtrUView (UMap -> UView Ptr (Credential 'Staking)
PtrUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Set v -> UMap
 Set (Credential 'Staking)
rng))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions Set (KeyHash 'StakePool)
rng ->
            forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Bool
Set.member Set (KeyHash 'StakePool)
rng) (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Set v -> UMap
 Set (KeyHash 'StakePool)
rng))
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions Set DRep
rng ->
            forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Bool
Set.member Set DRep
rng) (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v. UView k v -> Map k v
unUnify (UMap -> UView (Credential 'Staking) DRep
DRepUView (UMap -> UView (Credential 'Staking) DRep
DRepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty) forall k v. UView k v -> Set v -> UMap
 Set DRep
rng))
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Domain restriction" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"RewDepUView"
        ( \[Action]
actions (Map (Credential 'Staking) RDPair
m :: Map.Map (Credential 'Staking) RDPair) ->
            forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'Staking) RDPair
m (UMap -> Map (Credential 'Staking) RDPair
rdPairMap ([Action] -> UMap -> UMap
runRDPairs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v u. UView k v -> Map k u -> Map k u
domRestrict (UMap -> UView (Credential 'Staking) RDPair
RewDepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)) Map (Credential 'Staking) RDPair
m
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"PtrUView"
        ( \[Action]
actions (Map Ptr (Credential 'Staking)
m :: Map.Map Ptr (Credential 'Staking)) ->
            forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map Ptr (Credential 'Staking)
m (UMap -> Map Ptr (Credential 'Staking)
ptrMap ([Action] -> UMap -> UMap
runPtrs [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v u. UView k v -> Map k u -> Map k u
domRestrict (UMap -> UView Ptr (Credential 'Staking)
PtrUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)) Map Ptr (Credential 'Staking)
m
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"SPoolUView"
        ( \[Action]
actions (Map (Credential 'Staking) (KeyHash 'StakePool)
m :: Map.Map (Credential 'Staking) (KeyHash 'StakePool)) ->
            forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'Staking) (KeyHash 'StakePool)
m (UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap ([Action] -> UMap -> UMap
runSPools [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v u. UView k v -> Map k u -> Map k u
domRestrict (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)) Map (Credential 'Staking) (KeyHash 'StakePool)
m
        )
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"DRepUView"
        ( \[Action]
actions (Map (Credential 'Staking) DRep
m :: Map.Map (Credential 'Staking) DRep) ->
            forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'Staking) DRep
m (UMap -> Map (Credential 'Staking) DRep
dRepMap ([Action] -> UMap -> UMap
runDReps [Action]
actions UMap
empty))
              forall a. (Eq a, Show a) => a -> a -> Property
=== forall k v u. UView k v -> Map k u -> Map k u
domRestrict (UMap -> UView (Credential 'Staking) DRep
DRepUView ([Action] -> UMap -> UMap
runActions [Action]
actions UMap
empty)) Map (Credential 'Staking) DRep
m
        )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Old and new implementation is equivalent" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
        String
"unionRewAgg or ∪+ === oldUnionRewAgg"
        forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll
          Gen (UMap, Map (Credential 'Staking) RDPair)
genRightPreferenceUMap
          ( \(UMap
umap, Map (Credential 'Staking) RDPair
m) ->
              UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
∪+ (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking) RDPair
m) forall a. (Eq a, Show a) => a -> a -> Property
=== UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap UView (Credential 'Staking) RDPair
-> Map (Credential 'Staking) (CompactForm Coin) -> UMap
`oldUnionRewAgg` (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking) RDPair
m)
          )
    forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"StakeCredentials" forall a b. (a -> b) -> a -> b
$ do
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"toStakeCredentials as full domRestrictedStakeCredentials" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen UMap
genValidUMap forall a b. (a -> b) -> a -> b
$ \UMap
umap ->
          UMap -> StakeCredentials
toStakeCredentials UMap
umap
            forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials (forall k a. Map k a -> Set k
Map.keysSet (UMap -> Map (Credential 'Staking) UMElem
umElems UMap
umap)) UMap
umap

      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"domRestrictedStakeCredentials" forall a b. (a -> b) -> a -> b
$ forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (UMap, Set (Credential 'Staking))
genValidUMapWithCreds forall a b. (a -> b) -> a -> b
$ \(UMap
umap, Set (Credential 'Staking)
creds) ->
        Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials Set (Credential 'Staking)
creds UMap
umap
          forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` StakeCredentials
            { scRewards :: Map (Credential 'Staking) Coin
scRewards = UMap -> Map (Credential 'Staking) Coin
rewardMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
            , scDeposits :: Map (Credential 'Staking) Coin
scDeposits = UMap -> Map (Credential 'Staking) Coin
depositMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
            , scSPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools = UMap -> Map (Credential 'Staking) (KeyHash 'StakePool)
sPoolMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
            , scDReps :: Map (Credential 'Staking) DRep
scDReps = UMap -> Map (Credential 'Staking) DRep
dRepMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
            , scPtrs :: Map Ptr (Credential 'Staking)
scPtrs = forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (forall a. Ord a => a -> Set a -> Bool
`Set.member` Set (Credential 'Staking)
creds) forall a b. (a -> b) -> a -> b
$ UMap -> Map Ptr (Credential 'Staking)
ptrMap UMap
umap
            , scPtrsInverse :: Map (Credential 'Staking) (Set Ptr)
scPtrsInverse = UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
            }
      forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"domRestrictedStakeCredentials with domRestrictedMap" forall a b. (a -> b) -> a -> b
$
        forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (UMap, Set (Credential 'Staking))
genValidUMapWithCreds forall a b. (a -> b) -> a -> b
$ \(UMap
umap, Set (Credential 'Staking)
creds) ->
          let rdmap :: Map (Credential 'Staking) RDPair
rdmap = forall k v. Set k -> UView k v -> Map k v
domRestrictedMap Set (Credential 'Staking)
creds (UMap -> UView (Credential 'Staking) RDPair
RewDepUView UMap
umap)
              ptrs :: Map (Credential 'Staking) (Set Ptr)
ptrs = UMap -> Map (Credential 'Staking) (Set Ptr)
invPtrMap UMap
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking)
creds
           in Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials Set (Credential 'Staking)
creds UMap
umap
                forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` StakeCredentials
                  { scRewards :: Map (Credential 'Staking) Coin
scRewards = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdReward) Map (Credential 'Staking) RDPair
rdmap
                  , scDeposits :: Map (Credential 'Staking) Coin
scDeposits = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Compactible a => CompactForm a -> a
fromCompact forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDPair -> CompactForm Coin
rdDeposit) Map (Credential 'Staking) RDPair
rdmap
                  , scSPools :: Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools = forall k v. Set k -> UView k v -> Map k v
domRestrictedMap Set (Credential 'Staking)
creds (UMap -> UView (Credential 'Staking) (KeyHash 'StakePool)
SPoolUView UMap
umap)
                  , scDReps :: Map (Credential 'Staking) DRep
scDReps = forall k v. Set k -> UView k v -> Map k v
domRestrictedMap Set (Credential 'Staking)
creds (UMap -> UView (Credential 'Staking) DRep
DRepUView UMap
umap)
                  , scPtrs :: Map Ptr (Credential 'Staking)
scPtrs = forall k v. Set k -> UView k v -> Map k v
domRestrictedMap (forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold Map (Credential 'Staking) (Set Ptr)
ptrs) (UMap -> UView Ptr (Credential 'Staking)
PtrUView UMap
umap)
                  , scPtrsInverse :: Map (Credential 'Staking) (Set Ptr)
scPtrsInverse = Map (Credential 'Staking) (Set Ptr)
ptrs
                  }