Skip to content

Commit f802c1e

Browse files
committed
Made a test that required a UMap invalid for eras after Babbage.
Fix mkConwayTestAccountState which was calling era if the DRep was delegated.
1 parent 954cecb commit f802c1e

File tree

3 files changed

+17
-12
lines changed
  • eras/conway/impl/testlib/Test/Cardano/Ledger/Conway
  • libs/cardano-ledger-api

3 files changed

+17
-12
lines changed

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Era.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import Cardano.Ledger.UMap
2020
import Data.Coerce
2121
import qualified Data.Map.Strict as Map
2222
import qualified Data.Set as Set
23-
import GHC.Stack
2423
import Lens.Micro
2524
import Test.Cardano.Ledger.Babbage.Era
2625
import Test.Cardano.Ledger.Conway.Arbitrary ()
@@ -54,20 +53,19 @@ instance BabbageEraTest ConwayEra
5453

5554
instance ConwayEraTest ConwayEra
5655

56+
-- | similar to mkShelleyTestAccountState, but it ignores the mPtr, and doesn't
57+
-- need to test that mDRep is SNothing, since this is the Conway Era, where DReps can be allocated.
5758
mkConwayTestAccountState ::
58-
(HasCallStack, ConwayEraAccounts era) =>
59+
ConwayEraAccounts era =>
5960
Maybe Ptr ->
6061
CompactForm Coin ->
6162
Maybe (KeyHash 'StakePool) ->
6263
Maybe DRep ->
6364
AccountState era
6465
mkConwayTestAccountState _mPtr deposit mStakePool mDRep =
65-
case mDRep of
66-
Nothing ->
67-
mkConwayAccountState deposit
68-
& stakePoolDelegationAccountStateL .~ mStakePool
69-
& dRepDelegationAccountStateL .~ mDRep
70-
Just _ -> error "Delegation to DRep is not supported until Conway"
66+
mkConwayAccountState deposit
67+
& stakePoolDelegationAccountStateL .~ mStakePool
68+
& dRepDelegationAccountStateL .~ mDRep
7169

7270
conwayAccountsToUMap :: ConwayEraAccounts era => Accounts era -> UMap
7371
conwayAccountsToUMap accounts =

libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE RecordWildCards #-}

libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/QuerySpec.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
2+
{-# LANGUAGE BangPatterns #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE FlexibleContexts #-}
45
{-# LANGUAGE LambdaCase #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
67
{-# LANGUAGE TypeApplications #-}
78
{-# LANGUAGE TypeFamilies #-}
89
{-# LANGUAGE TypeOperators #-}
10+
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
911

1012
module Test.Cardano.Ledger.Api.State.QuerySpec (spec) where
1113

@@ -65,20 +67,24 @@ spec = do
6567
queryStakePoolDelegsAndRewardsSpec @MaryEra
6668
queryStakePoolDelegsAndRewardsSpec @AlonzoEra
6769
queryStakePoolDelegsAndRewardsSpec @BabbageEra
68-
queryStakePoolDelegsAndRewardsSpec @ConwayEra
70+
-- queryStakePoolDelegsAndRewardsSpec @ConwayEra -- See comment about queryStakePoolDelegsAndRewardsSpec and eras
6971
describe "GetCommitteeMembersState" $ do
7072
committeeMembersStateSpec @ConwayEra
7173

72-
queryStakePoolDelegsAndRewardsSpec :: forall era. ShelleyEraTest era => Spec
74+
-- | This does not make sense for Eras after Babbage. It requires only (ShelleyEraTest era)
75+
-- which pretends that from every era, one can extract a UMap.
76+
-- One cannot extract a UMap from the ConwayEra
77+
queryStakePoolDelegsAndRewardsSpec ::
78+
forall era. (AtMostEra BabbageEra era, ShelleyEraTest era) => Spec
7379
queryStakePoolDelegsAndRewardsSpec =
7480
describe (eraName @era) $ do
7581
describe "GetFilteredDelegationsAndRewardAccounts" $ do
7682
prop "queryStakePoolDelegsAndRewards same as getFilteredDelegationsAndRewardAccounts" $
7783
forAll (genValidUMapWithCreds @era) $ \(umap :: UMap, creds) ->
7884
let nes :: NewEpochState era
7985
nes = def & nesEsL . esLStateL . lsCertStateL . certDStateL . accountsL .~ accountsFromUMap umap
80-
in queryStakePoolDelegsAndRewards nes creds
81-
`shouldBe` getFilteredDelegationsAndRewardAccounts umap creds
86+
in (queryStakePoolDelegsAndRewards nes creds)
87+
`shouldBe` (getFilteredDelegationsAndRewardAccounts umap creds)
8288

8389
committeeMembersStateSpec ::
8490
forall era.

0 commit comments

Comments
 (0)