Skip to content

Commit

Permalink
Add a property test that checks that one of the trhesholds is always …
Browse files Browse the repository at this point in the history
…selected
  • Loading branch information
lehins committed Nov 1, 2023
1 parent 5ea6e85 commit 6661f86
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ module Cardano.Ledger.Conway.Governance (
psDRepDistrL,
psDRepStateL,
RunConwayRatify (..),
-- * Exported for testing
pparamsUpdateThreshold
) where

import Cardano.Ledger.BaseTypes (
Expand Down
33 changes: 30 additions & 3 deletions eras/conway/impl/test/Test/Cardano/Ledger/Conway/DRepRatifySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -15,16 +16,17 @@ import Cardano.Ledger.CertState (CommitteeState (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Compactible (Compactible (..))
import Cardano.Ledger.Conway
import Cardano.Ledger.Conway.Core (Era (EraCrypto), PParamsHKD)
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance (
GovAction (..),
GovActionState (..),
RatifyEnv (..),
RatifyState,
Vote (..),
pparamsUpdateThreshold,
votingDRepThreshold,
)
import Cardano.Ledger.Conway.PParams (ConwayEraPParams)
import Cardano.Ledger.Conway.PParams (ConwayEraPParams, ppDRepVotingThresholdsL)
import Cardano.Ledger.Conway.Rules (
dRepAccepted,
dRepAcceptedRatio,
Expand All @@ -39,23 +41,48 @@ import Data.Functor.Identity (Identity)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Ratio ((%))
import qualified Data.Set as Set
import Data.Word (Word64)
import Lens.Micro
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.Cardano.Ledger.Core.Rational ((%!))

spec :: Spec
spec = do
describe "DRep Ratification" $ do
correctThresholdsProp @Conway
acceptedRatioProp @Conway
noStakeProp @Conway
allAbstainProp @Conway
noVotesProp @Conway
allYesProp @Conway
noConfidenceProp @Conway

correctThresholdsProp ::
forall era.
( ConwayEraPParams era
, Arbitrary (PParams era)
, Arbitrary (PParamsUpdate era)
) =>
Spec
correctThresholdsProp = do
prop "PParamsUpdateThreshold always selects a threshold" $ \(pp :: PParams era) ppu -> do
let DRepVotingThresholds {..} = pp ^. ppDRepVotingThresholdsL
allDRepThresholds =
Set.fromList
[ dvtPPNetworkGroup
, dvtPPEconomicGroup
, dvtPPTechnicalGroup
, dvtPPGovGroup
]
when (ppu /= emptyPParamsUpdate) $
pparamsUpdateThreshold pp ppu `shouldSatisfy` (`Set.member` allDRepThresholds)
pparamsUpdateThreshold pp emptyPParamsUpdate `shouldBe` (0 %! 1)

acceptedRatioProp :: forall era. Era era => Spec
acceptedRatioProp =
acceptedRatioProp = do
prop "DRep vote count for arbitrary vote ratios" $
forAll genRatios $ \ratios -> do
forAll (genTestData @era ratios) $
Expand Down

0 comments on commit 6661f86

Please sign in to comment.