Skip to content

Commit

Permalink
Removed GovRelation from GovEnv
Browse files Browse the repository at this point in the history
Constrained hotfix

Limited tree size

Fixed a bug in prevGovActionId translation

Fixed TestRep of Proposals

Fixed endianness in Agda.TxId toExpr implementation

Fixed up the mismatch of prevGovActionIds in EnactState and Proposals

Added more debug logging

Added generation timeout tests

Added addtional constraints to Proposals
  • Loading branch information
Soupstraw committed Apr 25, 2024
1 parent 2f0ad36 commit 9458cb5
Show file tree
Hide file tree
Showing 22 changed files with 677 additions and 170 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repository cardano-haskell-packages
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-executable-spec.git
tag: 324fafa887b7b6b38e15d2b505c4eec5a3247176
--sha256: sha256-zpQToGA04NQ3TfkeWBJXIzisvoGLfYdWNbVQ/2BfeEI=
tag: 1ffb1d13b8892c0943780cd7bd9e2724b5c20cab
--sha256: sha256-iiC0AwhPce6XnaGYHyQBeMSIttvn2c+Legu0tUgYOEM=

index-state:
-- Bump this if you need newer packages from Hackage
Expand Down
7 changes: 5 additions & 2 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Gov.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ import Cardano.Ledger.Conway.Governance (
isCommitteeVotingAllowed,
isDRepVotingAllowed,
isStakePoolVotingAllowed,
pRootsL,
proposalsActionsMap,
proposalsAddAction,
proposalsAddVote,
proposalsLookupId,
toPrevGovActionIds,
)
import Cardano.Ledger.Conway.Governance.Procedures (GovAction (..), foldrVotingProcedures)
import Cardano.Ledger.Conway.PParams (
Expand Down Expand Up @@ -112,14 +114,14 @@ import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro
import qualified Lens.Micro as L
import NoThunks.Class (NoThunks (..))
import Validation (failureUnless)

data GovEnv era = GovEnv
{ geTxId :: !(TxId (EraCrypto era))
, geEpoch :: !EpochNo
, gePParams :: !(PParams era)
, gePrevGovActionIds :: !(GovRelation StrictMaybe era)
, gePPolicy :: !(StrictMaybe (ScriptHash (EraCrypto era)))
, geCommitteeState :: !(CommitteeState era)
}
Expand Down Expand Up @@ -329,11 +331,12 @@ govTransition ::
TransitionRule (EraRule "GOV" era)
govTransition = do
TRC
( GovEnv txid currentEpoch pp prevGovActionIds constitutionPolicy committeeState
( GovEnv txid currentEpoch pp constitutionPolicy committeeState
, st
, gp
) <-
judgmentContext
let prevGovActionIds = st ^. pRootsL . L.to toPrevGovActionIds

expectedNetworkId <- liftSTS $ asks networkId

Expand Down
3 changes: 0 additions & 3 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ import Cardano.Ledger.Conway.Governance (
GovProcedures (..),
Proposals,
constitutionScriptL,
pRootsL,
proposalsGovStateL,
toPrevGovActionIds,
)
import Cardano.Ledger.Conway.Rules.Cert (CertEnv, ConwayCertPredFailure)
import Cardano.Ledger.Conway.Rules.Certs (
Expand Down Expand Up @@ -390,7 +388,6 @@ ledgerTransition = do
(txIdTxBody txBody)
currentEpoch
pp
(utxoState ^. utxosGovStateL . proposalsGovStateL . pRootsL . L.to toPrevGovActionIds)
(utxoState ^. utxosGovStateL . constitutionGovStateL . constitutionScriptL)
(certState ^. certVStateL . vsCommitteeStateL)
, utxoState ^. utxosGovStateL . proposalsGovStateL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ instance (Era era, Arbitrary (PParamsHKD Identity era)) => Arbitrary (GovEnv era
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

instance Era era => Arbitrary (VotingProcedure era) where
arbitrary = VotingProcedure <$> arbitrary <*> arbitrary
Expand Down
15 changes: 15 additions & 0 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/GovSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
Expand Down Expand Up @@ -290,6 +291,20 @@ proposalsSpec =
constitutionProposal
[ injectFailure $ InvalidPrevGovActionId constitutionProposal
]
it "NoConfidence without a valid parent fails" $ do
pProcReturnAddr <- registerRewardAccount
corruptGPID <- arbitrary
pProcDeposit <- getsPParams ppGovActionDepositL
let
badProposal =
ProposalProcedure
{ pProcGovAction = NoConfidence $ SJust corruptGPID
, pProcAnchor = def
, ..
}
submitFailingProposal
badProposal
[injectFailure $ InvalidPrevGovActionId badProposal]
it "Subtrees are pruned when proposals expire" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
p1 <- submitInitConstitutionGovAction
Expand Down
43 changes: 27 additions & 16 deletions eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ newtype ImpTestM era a = ImpTestM {_unImpTestM :: ReaderT (ImpTestEnv era) IO a}
, MonadReader (ImpTestEnv era)
)

instance
( Testable a
, ShelleyEraImp era
) =>
Testable (ImpTestM era a)
where
property m = property . fmap ioProperty . runGenT $ do
res <- liftGen $ runImpTestGenM mkImpState m
liftIO $ fst <$> res

instance MonadWriter [SomeSTSEvent era] (ImpTestM era) where
writer (x, evs) = (impEventsL %= (<> evs)) $> x
listen act = do
Expand Down Expand Up @@ -1120,35 +1130,36 @@ logEntry e = impLogL %= (<> pretty loc <> "\t" <> pretty e <> line)
logToExpr :: (HasCallStack, ToExpr a) => a -> ImpTestM era ()
logToExpr e = logEntry (showExpr e)

mkImpState :: ShelleyEraImp era => ImpTestState era
mkImpState =
ImpTestState
{ impNES = initImpNES
, impRootTxIn = TxIn (mkTxId 0) minBound
, impKeyPairs = mempty
, impByronKeyPairs = mempty
, impNativeScripts = mempty
, impLastTick = 0
, impGlobals = testGlobals
, impLog = mempty
, impGen = mkQCGen 2024
, impEvents = mempty
}

withImpState ::
forall era.
ShelleyEraImp era =>
SpecWith (ImpTestState era) ->
Spec
withImpState =
beforeAll $ execImpTestM Nothing initImpTestState addRootTxOut
beforeAll $ execImpTestM Nothing mkImpState addRootTxOut
where
initImpTestState =
ImpTestState
{ impNES = initImpNES
, impRootTxIn = rootTxIn
, impKeyPairs = mempty
, impByronKeyPairs = mempty
, impNativeScripts = mempty
, impLastTick = 0
, impGlobals = testGlobals
, impLog = mempty
, impGen = mkQCGen 2024
, impEvents = mempty
}
rootCoin = Coin 1_000_000_000
rootTxIn = TxIn (mkTxId 0) minBound
addRootTxOut = do
(rootKeyHash, _) <- freshKeyPair
let rootAddr = Addr Testnet (KeyHashObj rootKeyHash) StakeRefNull
rootTxOut = mkBasicTxOut rootAddr $ inject rootCoin
impNESL . nesEsL . esLStateL . lsUTxOStateL . utxosUtxoL
%= (<> UTxO (Map.singleton rootTxIn rootTxOut))
%= (<> UTxO (Map.singleton (impRootTxIn @era mkImpState) rootTxOut))

-- | Creates a fresh @SafeHash@
freshSafeHash :: Era era => ImpTestM era (SafeHash (EraCrypto era) a)
Expand Down
6 changes: 4 additions & 2 deletions libs/cardano-data/testlib/Test/Cardano/Data/TreeDiff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

module Test.Cardano.Data.TreeDiff where

import Data.Foldable (Foldable (..))
import Data.Foldable qualified as F
import Data.OMap.Strict
import Data.OSet.Strict
import Test.Cardano.Ledger.Binary.TreeDiff (ToExpr (..))
import Test.Cardano.Ledger.Binary.TreeDiff (Expr (..), ToExpr (..))

deriving instance ToExpr a => ToExpr (OSet a)
instance ToExpr a => ToExpr (OSet a) where
toExpr x = App "OSet.fromList" [toExpr $ toList x]

instance (HasOKey k v, ToExpr v) => ToExpr (OMap k v) where
listToExpr = listToExpr . F.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library
base >=4.14 && <5,
cardano-data,
cardano-strict-containers,
data-default-class,
microlens,
mtl,
cardano-ledger-binary,
Expand All @@ -57,7 +58,8 @@ library
constrained-generators,
deepseq,
small-steps >=1.1,
text
text,
unliftio

if !impl(ghc >=9.2)
ghc-options: -Wno-incomplete-patterns
Expand Down

0 comments on commit 9458cb5

Please sign in to comment.