From 3bcdcaf1987fa7183658c0728cc4de19ec814eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joosep=20J=C3=A4=C3=A4ger?= Date: Tue, 13 Aug 2024 16:44:54 +0300 Subject: [PATCH] Added a conformance ImpTest to try to catch the ccminsize bug --- .../Cardano/Ledger/Conformance/Imp/Ratify.hs | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/Imp/Ratify.hs b/libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/Imp/Ratify.hs index 8cfea3d3c91..8f3f4e72d69 100644 --- a/libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/Imp/Ratify.hs +++ b/libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/Imp/Ratify.hs @@ -3,7 +3,8 @@ module Test.Cardano.Ledger.Conformance.Imp.Ratify (spec) where -import Cardano.Ledger.BaseTypes (StrictMaybe (..), natVersion) +import qualified Data.List.NonEmpty as NE +import Cardano.Ledger.BaseTypes (StrictMaybe (..), natVersion, addEpochInterval, EpochInterval (..)) import Cardano.Ledger.Conway (Conway) import Cardano.Ledger.Conway.Governance ( GovAction (..), @@ -16,13 +17,14 @@ import Cardano.Ledger.Conway.PParams ( dvtMotionNoConfidenceL, ppDRepVotingThresholdsL, ppPoolVotingThresholdsL, - pvtMotionNoConfidenceL, + pvtMotionNoConfidenceL, ppCommitteeMaxTermLengthL, ) import Cardano.Ledger.Shelley.LedgerState ( asTreasuryL, epochStateGovStateL, esAccountStateL, nesEsL, + nesELL, ) import qualified Data.Sequence.Strict as SSeq import Lens.Micro ((&), (.~)) @@ -34,9 +36,11 @@ import Test.Cardano.Ledger.Constrained.Conway (ConwayFn) import Test.Cardano.Ledger.Conway.ImpTest import Test.Cardano.Ledger.Core.Rational (IsRatio (..)) import Test.Cardano.Ledger.Imp.Common +import Cardano.Ledger.Credential (Credential(..)) +import qualified Data.Map as Map spec :: Spec -spec = describe "RATIFY" . withImpStateWithProtVer (natVersion @10) $ +spec = describe "RATIFY" . withImpStateWithProtVer @Conway (natVersion @10) $ do it "NoConfidence accepted conforms" $ do modifyPParams $ \pp -> pp @@ -64,3 +68,51 @@ spec = describe "RATIFY" . withImpStateWithProtVer (natVersion @10) $ ratEnv ratSt (RatifySignal (noConfidenceGAS SSeq.:<| SSeq.Empty)) + it "Duplicate CC hot keys count as separate votes" $ do + let maxTermLength = EpochInterval 10 + modifyPParams $ \pp -> + pp + & ppCommitteeMaxTermLengthL .~ maxTermLength + (credDRep, _, _) <- setupSingleDRep 100 + ccCold0 <- KeyHashObj <$> freshKeyHash + ccCold1 <- KeyHashObj <$> freshKeyHash + hotKey <- KeyHashObj <$> freshKeyHash + curEpoch <- getsNES nesELL + let + ccExpiry = curEpoch `addEpochInterval` maxTermLength + committee = Map.fromList + [ (ccCold0, ccExpiry) + , (ccCold1, ccExpiry) + ] + + logEntry "Electing the committee" + committeeId <- submitGovAction $ UpdateCommittee SNothing mempty committee maxBound + submitYesVote_ (DRepVoter credDRep) committeeId + logAcceptedRatio committeeId + passNEpochs 2 + getLastEnactedCommittee `shouldReturn` SJust (GovPurposeId committeeId) + + logEntry "Registering hotkeys" + _ <- registerCommitteeHotKeys (pure hotKey) (ccCold0 NE.:| [ccCold1]) + + logEntry "Proposing a new constitution" + newConstitution <- arbitrary + constitutionId <- submitGovAction $ NewConstitution SNothing newConstitution + submitYesVote_ (CommitteeVoter hotKey) constitutionId + submitYesVote_ (DRepVoter credDRep) constitutionId + constitutionGAS <- getGovActionState constitutionId + + logEntry "Testing conformance" + treasury <- getsNES $ nesEsL . esAccountStateL . asTreasuryL + let execCtx = ConwayRatifyExecContext treasury [constitutionGAS] + ratEnv <- getRatifyEnv + govSt <- getsNES $ nesEsL . epochStateGovStateL + let + ratSt = getRatifyState govSt + result = + testConformance @ConwayFn @"RATIFY" @Conway + execCtx + ratEnv + ratSt + (RatifySignal (constitutionGAS SSeq.:<| mempty)) + pure result