Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Kuleshevich <[email protected]>
  • Loading branch information
Lucsanszky and lehins authored Nov 13, 2024
1 parent 6c3dd73 commit 4de44d3
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions eras/conway/impl/test/Test/Cardano/Ledger/Conway/SPORatifySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,10 @@ noStakeProp =
prop @((RatifyEnv era, RatifyState era, GovActionState era) -> IO ())
"If there is no stake, accept iff threshold is zero"
( \(re, rs, gas) ->
spoAccepted
@era
re {reStakePoolDistr = PoolDistr Map.empty (fromJust . toCompact $ Coin 100)}
rs
gas
`shouldBe` votingStakePoolThreshold @era rs (gasAction gas)
== SJust minBound
let re' = re {reStakePoolDistr = PoolDistr Map.empty (fromJust . toCompact $ Coin 100)}
in spoAccepted @era re' rs gas
`shouldBe`
(votingStakePoolThreshold @era rs (gasAction gas) == SJust minBound)
)

allAbstainProp ::
Expand Down Expand Up @@ -282,7 +279,7 @@ genTestData Ratios {yes, no, abstain, alwaysAbstain, noConfidence} = do
, stakeNoConfidence = Coin . fromIntegral $ length poolsNoConfidence
, stakeNotVoted = Coin . fromIntegral $ length rest
, delegatees = Map.union delegateesAA delegateesNC
, poolParams = Map.union poolParamsRest $ Map.union poolParamsAA poolParamsNC
, poolParams = Map.unions [poolParamsRest, poolParamsAA, poolParamsNC]
}
where
splitByPct ::
Expand All @@ -305,8 +302,10 @@ genTestData Ratios {yes, no, abstain, alwaysAbstain, noConfidence} = do
(rs1, rs2, rs3, rs4, rs5, rest'''')

genPoolParams p = do
params <- arbitrary
pure $ Map.fromList [(cred, params) | cred <- p]
let genPoolParams poolId = do
poolParams <- arbitrary
pure $ poolParams { ppId = poolId }
sequence $ fromKeys genPoolParams p

-- Given a delegatee and a map of stake pool params,
-- create a map of reward account delegatees.
Expand All @@ -315,17 +314,14 @@ genTestData Ratios {yes, no, abstain, alwaysAbstain, noConfidence} = do
Map (KeyHash 'StakePool (EraCrypto era)) (PoolParams (EraCrypto era)) ->
Map (Credential 'Staking (EraCrypto era)) (DRep (EraCrypto era))
mkDelegatees drep =
Map.fromList
. map (\(_, params) -> (raCredential $ ppRewardAccount params, drep))
. Map.toList
fromKeys (const drep) . map (raCredential . ppRewardAccount) . Map.elems

-- Create a map from each pool with the given value, where the key is the pool credential
-- and take the union of all these maps.
unionAllFromLists ::
[([KeyHash 'StakePool (EraCrypto era)], a)] ->
Map (KeyHash 'StakePool (EraCrypto era)) a
unionAllFromLists =
foldr (Map.union . (\(l, v) -> Map.fromList [(cred, v) | cred <- l])) Map.empty
unionAllFromLists = foldMap (\(ks, v) -> fromKeys (const v) ks)

genRatios :: Gen Ratios
genRatios = do
Expand Down

0 comments on commit 4de44d3

Please sign in to comment.