{-# 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.Crypto (StandardCrypto)
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 StandardCrypto) RDPair
| InsertPtr Ptr (Credential 'Staking StandardCrypto)
| InsertSPool (Credential 'Staking StandardCrypto) (KeyHash 'StakePool StandardCrypto)
| InsertDRep (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
| DeleteRDPair (Credential 'Staking StandardCrypto)
| DeletePtr Ptr
| DeleteSPool (Credential 'Staking StandardCrypto)
| DeleteDRep (Credential 'Staking StandardCrypto)
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 StandardCrypto -> 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 StandardCrypto -> 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 StandardCrypto
-> KeyHash 'StakePool StandardCrypto -> 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 StandardCrypto -> 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 StandardCrypto -> Action
DeleteSPool forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Arbitrary a => Gen a
arbitrary
, Credential 'Staking StandardCrypto -> 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 StandardCrypto -> 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 StandardCrypto -> 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 StandardCrypto
-> KeyHash 'StakePool StandardCrypto -> 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 StandardCrypto -> DRep StandardCrypto -> 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 StandardCrypto -> UMap StandardCrypto
reify :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reify = \case
InsertRDPair Credential 'Staking StandardCrypto
k RDPair
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k RDPair
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView
InsertPtr Ptr
k Credential 'Staking StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Ptr
k Credential 'Staking StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView
InsertSPool Credential 'Staking StandardCrypto
k KeyHash 'StakePool StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k KeyHash 'StakePool StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView
InsertDRep Credential 'Staking StandardCrypto
k DRep StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k DRep StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView
DeleteRDPair Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView
DeletePtr Ptr
k -> forall k c v. k -> UView c k v -> UMap c
delete Ptr
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView
DeleteSPool Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView
DeleteDRep Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView
reifyRDPair :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyRDPair :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyRDPair = \case
InsertRDPair Credential 'Staking StandardCrypto
k RDPair
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k RDPair
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView
DeleteRDPair Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView
Action
_ -> forall a. a -> a
id
reifyPtr :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyPtr :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyPtr = \case
InsertPtr Ptr
k Credential 'Staking StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Ptr
k Credential 'Staking StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView
DeletePtr Ptr
k -> forall k c v. k -> UView c k v -> UMap c
delete Ptr
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView
Action
_ -> forall a. a -> a
id
reifySPool :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifySPool :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifySPool = \case
InsertSPool Credential 'Staking StandardCrypto
k KeyHash 'StakePool StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k KeyHash 'StakePool StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView
DeleteSPool Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView
Action
_ -> forall a. a -> a
id
reifyDRep :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyDRep :: Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyDRep = \case
InsertDRep Credential 'Staking StandardCrypto
k DRep StandardCrypto
v -> forall k v c. k -> v -> UView c k v -> UMap c
insert Credential 'Staking StandardCrypto
k DRep StandardCrypto
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView
DeleteDRep Credential 'Staking StandardCrypto
k -> forall k c v. k -> UView c k v -> UMap c
delete Credential 'Staking StandardCrypto
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView
Action
_ -> forall a. a -> a
id
runActions :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions UMap StandardCrypto
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap StandardCrypto -> UMap StandardCrypto
reify UMap StandardCrypto
umap [Action]
actions
runRDPairs :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions UMap StandardCrypto
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyRDPair UMap StandardCrypto
umap [Action]
actions
runPtrs :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions UMap StandardCrypto
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyPtr UMap StandardCrypto
umap [Action]
actions
runSPools :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions UMap StandardCrypto
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap StandardCrypto -> UMap StandardCrypto
reifySPool UMap StandardCrypto
umap [Action]
actions
runDReps :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps :: [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions UMap StandardCrypto
umap = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Action -> UMap StandardCrypto -> UMap StandardCrypto
reifyDRep UMap StandardCrypto
umap [Action]
actions
sizeTest ::
( Map.Map (Credential 'Staking StandardCrypto) RDPair
, Map.Map Ptr (Credential 'Staking StandardCrypto)
, Map.Map (Credential 'Staking StandardCrypto) (KeyHash 'StakePool StandardCrypto)
, Map.Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
) ->
IO ()
sizeTest :: (Map (Credential 'Staking StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
-> IO ()
sizeTest (Map (Credential 'Staking StandardCrypto) RDPair
rdPairs, Map Ptr (Credential 'Staking StandardCrypto)
ptrs, Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools, Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps) = do
let
umap :: UMap StandardCrypto
umap = forall c.
Map (Credential 'Staking c) RDPair
-> Map Ptr (Credential 'Staking c)
-> Map (Credential 'Staking c) (KeyHash 'StakePool c)
-> Map (Credential 'Staking c) (DRep c)
-> UMap c
unify Map (Credential 'Staking StandardCrypto) RDPair
rdPairs Map Ptr (Credential 'Staking StandardCrypto)
ptrs Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps
rdPairsSize :: Int
rdPairsSize = forall c k v. UView c k v -> Int
size (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap)
ptrsSize :: Int
ptrsSize = forall c k v. UView c k v -> Int
size (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView UMap StandardCrypto
umap)
sPoolSize :: Int
sPoolSize = forall c k v. UView c k v -> Int
size (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView UMap StandardCrypto
umap)
dRepSize :: Int
dRepSize = forall c k v. UView c k v -> Int
size (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView UMap StandardCrypto
umap)
forall k a. Map k a -> Int
Map.size Map (Credential 'Staking StandardCrypto) 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 StandardCrypto)
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 StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
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 StandardCrypto) (DRep StandardCrypto)
dReps forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Int
dRepSize
unifyRoundTripTo ::
( Map.Map (Credential 'Staking StandardCrypto) RDPair
, Map.Map Ptr (Credential 'Staking StandardCrypto)
, Map.Map (Credential 'Staking StandardCrypto) (KeyHash 'StakePool StandardCrypto)
, Map.Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
) ->
IO ()
unifyRoundTripTo :: (Map (Credential 'Staking StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
-> IO ()
unifyRoundTripTo (Map (Credential 'Staking StandardCrypto) RDPair
rdPairs, Map Ptr (Credential 'Staking StandardCrypto)
ptrs, Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools, Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps) = do
let umap :: UMap StandardCrypto
umap = forall c.
Map (Credential 'Staking c) RDPair
-> Map Ptr (Credential 'Staking c)
-> Map (Credential 'Staking c) (KeyHash 'StakePool c)
-> Map (Credential 'Staking c) (DRep c)
-> UMap c
unify Map (Credential 'Staking StandardCrypto) RDPair
rdPairs Map Ptr (Credential 'Staking StandardCrypto)
ptrs Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps
forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap UMap StandardCrypto
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map (Credential 'Staking StandardCrypto) RDPair
rdPairs
forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap UMap StandardCrypto
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map Ptr (Credential 'Staking StandardCrypto)
ptrs
forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap UMap StandardCrypto
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools
forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap UMap StandardCrypto
umap forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps
unifyRoundTripFrom :: [Action] -> Property
unifyRoundTripFrom :: [Action] -> Property
unifyRoundTripFrom [Action]
actions =
let
umap :: UMap StandardCrypto
umap = [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty
rdPairs :: Map (Credential 'Staking StandardCrypto) RDPair
rdPairs = forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap UMap StandardCrypto
umap
ptrs :: Map Ptr (Credential 'Staking StandardCrypto)
ptrs = forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap UMap StandardCrypto
umap
sPools :: Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools = forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap UMap StandardCrypto
umap
dReps :: Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps = forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap UMap StandardCrypto
umap
in
UMap StandardCrypto
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall c.
Map (Credential 'Staking c) RDPair
-> Map Ptr (Credential 'Staking c)
-> Map (Credential 'Staking c) (KeyHash 'StakePool c)
-> Map (Credential 'Staking c) (DRep c)
-> UMap c
unify Map (Credential 'Staking StandardCrypto) RDPair
rdPairs Map Ptr (Credential 'Staking StandardCrypto)
ptrs Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
sPools Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
dReps
oldUnionRewAgg ::
UView c (Credential 'Staking c) RDPair ->
Map (Credential 'Staking c) (CompactForm Coin) ->
UMap c
(RewDepUView UMap {Map (Credential 'Staking c) (UMElem c)
umElems :: Map (Credential 'Staking c) (UMElem c)
umElems :: forall c. UMap c -> Map (Credential 'Staking c) (UMElem c)
umElems, Map Ptr (Credential 'Staking c)
umPtrs :: Map Ptr (Credential 'Staking c)
umPtrs :: forall c. UMap c -> Map Ptr (Credential 'Staking c)
umPtrs}) oldUnionRewAgg :: forall c.
UView c (Credential 'Staking c) RDPair
-> Map (Credential 'Staking c) (CompactForm Coin) -> UMap c
`oldUnionRewAgg` Map (Credential 'Staking c) (CompactForm Coin)
aggRewMap = forall c.
Map (Credential 'Staking c) (UMElem c)
-> Map Ptr (Credential 'Staking c) -> UMap c
UMap Map (Credential 'Staking c) (UMElem c)
newUmElem Map Ptr (Credential 'Staking c)
umPtrs
where
newUmElem :: Map (Credential 'Staking c) (UMElem c)
newUmElem =
let
result :: Map (Credential 'Staking c) (UMElem c)
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} {c}.
p -> UMElem c -> CompactForm Coin -> Maybe (UMElem c)
f forall a. a -> a
id (forall a b. a -> b -> a
const forall k a. Map k a
Map.empty) Map (Credential 'Staking c) (UMElem c)
umElems Map (Credential 'Staking c) (CompactForm Coin)
aggRewMap
f :: p -> UMElem c -> CompactForm Coin -> Maybe (UMElem c)
f p
_k (UMElem StrictMaybe RDPair
p1 Set Ptr
s StrictMaybe (KeyHash 'StakePool c)
deposit StrictMaybe (DRep c)
drep) CompactForm Coin
delta = forall a. a -> Maybe a
Just (forall c.
StrictMaybe RDPair
-> Set Ptr
-> StrictMaybe (KeyHash 'StakePool c)
-> StrictMaybe (DRep c)
-> UMElem c
UMElem (CompactForm Coin -> StrictMaybe RDPair -> StrictMaybe RDPair
addC CompactForm Coin
delta StrictMaybe RDPair
p1) Set Ptr
s StrictMaybe (KeyHash 'StakePool c)
deposit StrictMaybe (DRep c)
drep)
in
forall a. HasCallStack => Bool -> a -> a
assert (forall k a. Ord k => Map k a -> Bool
Map.valid Map (Credential 'Staking c) (UMElem c)
result) Map (Credential 'Staking c) (UMElem c)
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 StandardCrypto
cred :: Credential 'Staking StandardCrypto) Ptr
ptr -> forall c. Credential 'Staking c -> Ptr -> UMap c -> Bool
umInvariant Credential 'Staking StandardCrypto
cred Ptr
ptr forall c. UMap c
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 StandardCrypto, Ptr, UMap StandardCrypto)
genInvariantNonEmpty
(\(Credential 'Staking StandardCrypto
cred, Ptr
ptr, UMap StandardCrypto
umap) -> forall c. Credential 'Staking c -> Ptr -> UMap c -> Bool
umInvariant Credential 'Staking StandardCrypto
cred Ptr
ptr UMap StandardCrypto
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 StandardCrypto, Ptr, UMap StandardCrypto)
genInvariantNonEmpty forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Arbitrary a => Gen a
arbitrary)
(\((Credential 'Staking StandardCrypto
cred, Ptr
ptr, UMap StandardCrypto
umap), [Action]
actions) -> forall c. Credential 'Staking c -> Ptr -> UMap c -> Bool
umInvariant Credential 'Staking StandardCrypto
cred Ptr
ptr forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions UMap StandardCrypto
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 StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
genValidTuples (Map (Credential 'Staking StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
-> 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 StandardCrypto, Credential 'Staking StandardCrypto, RDPair)
genInsertDeleteRoundtripRDPair
(\(UMap StandardCrypto
umap, Credential 'Staking StandardCrypto
k, RDPair
v) -> UMap StandardCrypto
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> UMap c
unUView (forall k c v. k -> UView c k v -> UView c k v
delete' Credential 'Staking StandardCrypto
k (forall k v c. k -> v -> UView c k v -> UView c k v
insert' Credential 'Staking StandardCrypto
k RDPair
v (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
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 StandardCrypto, Ptr, Credential 'Staking StandardCrypto)
genInsertDeleteRoundtripPtr
(\(UMap StandardCrypto
umap, Ptr
k, Credential 'Staking StandardCrypto
v) -> UMap StandardCrypto
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> UMap c
unUView (forall k c v. k -> UView c k v -> UView c k v
delete' Ptr
k (forall k v c. k -> v -> UView c k v -> UView c k v
insert' Ptr
k Credential 'Staking StandardCrypto
v (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView UMap StandardCrypto
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 StandardCrypto, Credential 'Staking StandardCrypto,
KeyHash 'StakePool StandardCrypto)
genInsertDeleteRoundtripSPool
(\(UMap StandardCrypto
umap, Credential 'Staking StandardCrypto
k, KeyHash 'StakePool StandardCrypto
v) -> UMap StandardCrypto
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> UMap c
unUView (forall k c v. k -> UView c k v -> UView c k v
delete' Credential 'Staking StandardCrypto
k (forall k v c. k -> v -> UView c k v -> UView c k v
insert' Credential 'Staking StandardCrypto
k KeyHash 'StakePool StandardCrypto
v (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView UMap StandardCrypto
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 StandardCrypto, Credential 'Staking StandardCrypto,
DRep StandardCrypto)
genInsertDeleteRoundtripDRep
(\(UMap StandardCrypto
umap, Credential 'Staking StandardCrypto
k, DRep StandardCrypto
v) -> UMap StandardCrypto
umap forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> UMap c
unUView (forall k c v. k -> UView c k v -> UView c k v
delete' Credential 'Staking StandardCrypto
k (forall k v c. k -> v -> UView c k v -> UView c k v
insert' Credential 'Staking StandardCrypto
k DRep StandardCrypto
v (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView UMap StandardCrypto
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 StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
genValidTuples (Map (Credential 'Staking StandardCrypto) RDPair,
Map Ptr (Credential 'Staking StandardCrypto),
Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto),
Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto))
-> 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 StandardCrypto
umap :: UMap StandardCrypto, Credential 'Staking StandardCrypto
cred) ->
forall k c v. k -> UView c k v -> Bool
member Credential 'Staking StandardCrypto
cred (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking StandardCrypto
cred (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap UMap StandardCrypto
umap)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUViews"
( \(UMap StandardCrypto
umap :: UMap StandardCrypto, Ptr
ptr) ->
forall k c v. k -> UView c k v -> Bool
member Ptr
ptr (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView UMap StandardCrypto
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Ptr
ptr (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap UMap StandardCrypto
umap)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \(UMap StandardCrypto
umap :: UMap StandardCrypto, Credential 'Staking StandardCrypto
cred) ->
forall k c v. k -> UView c k v -> Bool
member Credential 'Staking StandardCrypto
cred (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView UMap StandardCrypto
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking StandardCrypto
cred (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap UMap StandardCrypto
umap)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \(UMap StandardCrypto
umap :: UMap StandardCrypto, Credential 'Staking StandardCrypto
cred) ->
forall k c v. k -> UView c k v -> Bool
member Credential 'Staking StandardCrypto
cred (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView UMap StandardCrypto
umap) forall a. (Eq a, Show a) => a -> a -> Property
=== forall k a. Ord k => k -> Map k a -> Bool
Map.member Credential 'Staking StandardCrypto
cred (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap UMap StandardCrypto
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 ->
forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions ->
forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions ->
forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions ->
forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Bool
nullUView (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions ->
forall k a. Map k a -> Bool
Map.null (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Bool
nullUView (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions ->
forall k a. Map k a -> Bool
Map.null (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Bool
nullUView (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions ->
forall k a. Map k a -> Bool
Map.null (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Bool
nullUView (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 StandardCrypto
cred ->
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking StandardCrypto
cred (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall k c v. k -> UView c k v -> Maybe v
UMap.lookup Credential 'Staking StandardCrypto
cred (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall k c v. k -> UView c k v -> Maybe v
UMap.lookup Ptr
ptr (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions Credential 'Staking StandardCrypto
cred ->
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking StandardCrypto
cred (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall k c v. k -> UView c k v -> Maybe v
UMap.lookup Credential 'Staking StandardCrypto
cred (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions Credential 'Staking StandardCrypto
cred ->
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking StandardCrypto
cred (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall k c v. k -> UView c k v -> Maybe v
UMap.lookup Credential 'Staking StandardCrypto
cred (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set k
domain (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions ->
forall k a. Map k a -> Set k
Map.keysSet (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set k
domain (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions ->
forall k a. Map k a -> Set k
Map.keysSet (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set k
domain (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions ->
forall k a. Map k a -> Set k
Map.keysSet (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set k
domain (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty)))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set v
range (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty)))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set v
range (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty)))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set v
range (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty)))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Set v
range (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView forall a b. (a -> b) -> a -> b
$ [Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 StandardCrypto
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 (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking StandardCrypto
cred RDPair
rdPair)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> (k, v) -> UMap c
∪ (Credential 'Staking StandardCrypto
cred, RDPair
rdPair)))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions Ptr
cred Credential 'Staking StandardCrypto
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 (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty)) (forall k a. k -> a -> Map k a
Map.singleton Ptr
cred Credential 'Staking StandardCrypto
ptr)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> (k, v) -> UMap c
∪ (Ptr
cred, Credential 'Staking StandardCrypto
ptr)))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions Credential 'Staking StandardCrypto
cred KeyHash 'StakePool StandardCrypto
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 (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking StandardCrypto
cred KeyHash 'StakePool StandardCrypto
pool)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> (k, v) -> UMap c
∪ (Credential 'Staking StandardCrypto
cred, KeyHash 'StakePool StandardCrypto
pool)))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions Credential 'Staking StandardCrypto
cred DRep StandardCrypto
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 (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty)) (forall k a. k -> a -> Map k a
Map.singleton Credential 'Staking StandardCrypto
cred DRep StandardCrypto
pool)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> (k, v) -> UMap c
∪ (Credential 'Staking StandardCrypto
cred, DRep StandardCrypto
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 StandardCrypto,
Map (Credential 'Staking StandardCrypto) RDPair)
genRightPreferenceUMap
( \(UMap StandardCrypto
umap, Map (Credential 'Staking StandardCrypto) 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)
(forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap UMap StandardCrypto
umap)
Map (Credential 'Staking StandardCrypto) RDPair
m
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap forall c k v. UView c k v -> Map k v -> UMap c
⨃ Map (Credential 'Staking StandardCrypto) RDPair
m)
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions Map Ptr (Credential 'Staking StandardCrypto)
m ->
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\Credential 'Staking StandardCrypto
_ Credential 'Staking StandardCrypto
x -> Credential 'Staking StandardCrypto
x) (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty)) Map Ptr (Credential 'Staking StandardCrypto)
m
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Map k v -> UMap c
⨃ Map Ptr (Credential 'Staking StandardCrypto)
m))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m ->
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\KeyHash 'StakePool StandardCrypto
_ KeyHash 'StakePool StandardCrypto
x -> KeyHash 'StakePool StandardCrypto
x) (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty)) Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Map k v -> UMap c
⨃ Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
m ->
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (\DRep StandardCrypto
_ DRep StandardCrypto
x -> DRep StandardCrypto
x) (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty)) Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
m
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Map k v -> UMap c
⨃ Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
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 StandardCrypto,
Map (Credential 'Staking StandardCrypto) RDPair)
genRightPreferenceUMap
( \(UMap StandardCrypto
umap, Map (Credential 'Staking StandardCrypto) 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
(<>) (forall c. UMap c -> Map (Credential 'Staking c) (CompactForm Coin)
compactRewardMap UMap StandardCrypto
umap) (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking StandardCrypto) RDPair
m)
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> Map (Credential 'Staking c) (CompactForm Coin)
compactRewardMap (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap forall c.
UView c (Credential 'Staking c) RDPair
-> Map (Credential 'Staking c) (CompactForm Coin) -> UMap c
∪+ (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking StandardCrypto) 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 StandardCrypto)
dom ->
forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty)) Set (Credential 'Staking StandardCrypto)
dom
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView (Set (Credential 'Staking StandardCrypto)
dom forall k c v. Set k -> UView c k v -> UMap c
⋪ forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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 (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty)) Set Ptr
dom
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView (Set Ptr
dom forall k c v. Set k -> UView c k v -> UMap c
⋪ forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions Set (Credential 'Staking StandardCrypto)
dom ->
forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty)) Set (Credential 'Staking StandardCrypto)
dom
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView (Set (Credential 'Staking StandardCrypto)
dom forall k c v. Set k -> UView c k v -> UMap c
⋪ forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions Set (Credential 'Staking StandardCrypto)
dom ->
forall k a. Ord k => Map k a -> Set k -> Map k a
Map.withoutKeys (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty)) Set (Credential 'Staking StandardCrypto)
dom
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView (Set (Credential 'Staking StandardCrypto)
dom forall k c v. Set k -> UView c k v -> UMap c
⋪ forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
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) (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Set v -> UMap c
⋫ Set RDPair
rng))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions Set (Credential 'Staking StandardCrypto)
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 StandardCrypto)
rng) (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Set v -> UMap c
⋫ Set (Credential 'Staking StandardCrypto)
rng))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions Set (KeyHash 'StakePool StandardCrypto)
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 StandardCrypto)
rng) (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Set v -> UMap c
⋫ Set (KeyHash 'StakePool StandardCrypto)
rng))
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions Set (DRep StandardCrypto)
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 StandardCrypto)
rng) (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v. UView c k v -> Map k v
unUnify (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty) forall c k v. UView c k v -> Set v -> UMap c
⋫ Set (DRep StandardCrypto)
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 StandardCrypto) RDPair
m :: Map.Map (Credential 'Staking StandardCrypto) RDPair) ->
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'Staking StandardCrypto) RDPair
m (forall c. UMap c -> Map (Credential 'Staking c) RDPair
rdPairMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runRDPairs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v u. UView c k v -> Map k u -> Map k u
domRestrict (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)) Map (Credential 'Staking StandardCrypto) RDPair
m
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"PtrUView"
( \[Action]
actions (Map Ptr (Credential 'Staking StandardCrypto)
m :: Map.Map Ptr (Credential 'Staking StandardCrypto)) ->
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map Ptr (Credential 'Staking StandardCrypto)
m (forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runPtrs [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v u. UView c k v -> Map k u -> Map k u
domRestrict (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)) Map Ptr (Credential 'Staking StandardCrypto)
m
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"SPoolUView"
( \[Action]
actions (Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m :: Map.Map (Credential 'Staking StandardCrypto) (KeyHash 'StakePool StandardCrypto)) ->
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m (forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runSPools [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v u. UView c k v -> Map k u -> Map k u
domRestrict (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)) Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
m
)
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop
String
"DRepUView"
( \[Action]
actions (Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
m :: Map.Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)) ->
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.intersection Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
m (forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runDReps [Action]
actions forall c. UMap c
empty))
forall a. (Eq a, Show a) => a -> a -> Property
=== forall c k v u. UView c k v -> Map k u -> Map k u
domRestrict (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView ([Action] -> UMap StandardCrypto -> UMap StandardCrypto
runActions [Action]
actions forall c. UMap c
empty)) Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
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 StandardCrypto,
Map (Credential 'Staking StandardCrypto) RDPair)
genRightPreferenceUMap
( \(UMap StandardCrypto
umap, Map (Credential 'Staking StandardCrypto) RDPair
m) ->
forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap forall c.
UView c (Credential 'Staking c) RDPair
-> Map (Credential 'Staking c) (CompactForm Coin) -> UMap c
∪+ (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking StandardCrypto) RDPair
m) forall a. (Eq a, Show a) => a -> a -> Property
=== forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap forall c.
UView c (Credential 'Staking c) RDPair
-> Map (Credential 'Staking c) (CompactForm Coin) -> UMap c
`oldUnionRewAgg` (RDPair -> CompactForm Coin
rdReward forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Credential 'Staking StandardCrypto) 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 StandardCrypto)
genValidUMap forall a b. (a -> b) -> a -> b
$ \UMap StandardCrypto
umap ->
forall c. UMap c -> StakeCredentials c
toStakeCredentials UMap StandardCrypto
umap
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` forall c.
Set (Credential 'Staking c) -> UMap c -> StakeCredentials c
domRestrictedStakeCredentials (forall k a. Map k a -> Set k
Map.keysSet (forall c. UMap c -> Map (Credential 'Staking c) (UMElem c)
umElems UMap StandardCrypto
umap)) UMap StandardCrypto
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 StandardCrypto, Set (Credential 'Staking StandardCrypto))
genValidUMapWithCreds forall a b. (a -> b) -> a -> b
$ \(UMap StandardCrypto
umap, Set (Credential 'Staking StandardCrypto)
creds) ->
forall c.
Set (Credential 'Staking c) -> UMap c -> StakeCredentials c
domRestrictedStakeCredentials Set (Credential 'Staking StandardCrypto)
creds UMap StandardCrypto
umap
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` StakeCredentials
{ scRewards :: Map (Credential 'Staking StandardCrypto) Coin
scRewards = forall c. UMap c -> Map (Credential 'Staking c) Coin
rewardMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
creds
, scDeposits :: Map (Credential 'Staking StandardCrypto) Coin
scDeposits = forall c. UMap c -> Map (Credential 'Staking c) Coin
depositMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
creds
, scSPools :: Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
scSPools = forall c.
UMap c -> Map (Credential 'Staking c) (KeyHash 'StakePool c)
sPoolMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
creds
, scDReps :: Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
scDReps = forall c. UMap c -> Map (Credential 'Staking c) (DRep c)
dRepMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
creds
, scPtrs :: Map Ptr (Credential 'Staking StandardCrypto)
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 StandardCrypto)
creds) forall a b. (a -> b) -> a -> b
$ forall c. UMap c -> Map Ptr (Credential 'Staking c)
ptrMap UMap StandardCrypto
umap
, scPtrsInverse :: Map (Credential 'Staking StandardCrypto) (Set Ptr)
scPtrsInverse = forall c. UMap c -> Map (Credential 'Staking c) (Set Ptr)
invPtrMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
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 StandardCrypto, Set (Credential 'Staking StandardCrypto))
genValidUMapWithCreds forall a b. (a -> b) -> a -> b
$ \(UMap StandardCrypto
umap, Set (Credential 'Staking StandardCrypto)
creds) ->
let rdmap :: Map (Credential 'Staking StandardCrypto) RDPair
rdmap = forall k c v. Set k -> UView c k v -> Map k v
domRestrictedMap Set (Credential 'Staking StandardCrypto)
creds (forall c. UMap c -> UView c (Credential 'Staking c) RDPair
RewDepUView UMap StandardCrypto
umap)
ptrs :: Map (Credential 'Staking StandardCrypto) (Set Ptr)
ptrs = forall c. UMap c -> Map (Credential 'Staking c) (Set Ptr)
invPtrMap UMap StandardCrypto
umap forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'Staking StandardCrypto)
creds
in forall c.
Set (Credential 'Staking c) -> UMap c -> StakeCredentials c
domRestrictedStakeCredentials Set (Credential 'Staking StandardCrypto)
creds UMap StandardCrypto
umap
forall a. (HasCallStack, Show a, Eq a) => a -> a -> IO ()
`shouldBe` StakeCredentials
{ scRewards :: Map (Credential 'Staking StandardCrypto) 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 StandardCrypto) RDPair
rdmap
, scDeposits :: Map (Credential 'Staking StandardCrypto) 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 StandardCrypto) RDPair
rdmap
, scSPools :: Map
(Credential 'Staking StandardCrypto)
(KeyHash 'StakePool StandardCrypto)
scSPools = forall k c v. Set k -> UView c k v -> Map k v
domRestrictedMap Set (Credential 'Staking StandardCrypto)
creds (forall c.
UMap c -> UView c (Credential 'Staking c) (KeyHash 'StakePool c)
SPoolUView UMap StandardCrypto
umap)
, scDReps :: Map (Credential 'Staking StandardCrypto) (DRep StandardCrypto)
scDReps = forall k c v. Set k -> UView c k v -> Map k v
domRestrictedMap Set (Credential 'Staking StandardCrypto)
creds (forall c. UMap c -> UView c (Credential 'Staking c) (DRep c)
DRepUView UMap StandardCrypto
umap)
, scPtrs :: Map Ptr (Credential 'Staking StandardCrypto)
scPtrs = forall k c v. Set k -> UView c k v -> Map k v
domRestrictedMap (forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold Map (Credential 'Staking StandardCrypto) (Set Ptr)
ptrs) (forall c. UMap c -> UView c Ptr (Credential 'Staking c)
PtrUView UMap StandardCrypto
umap)
, scPtrsInverse :: Map (Credential 'Staking StandardCrypto) (Set Ptr)
scPtrsInverse = Map (Credential 'Staking StandardCrypto) (Set Ptr)
ptrs
}