Skip to content

Commit

Permalink
Review remarks part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 23, 2024
1 parent bd3e138 commit b4e6c9c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/cabal.project.old
configuration/defaults/simpleview/genesis/
configuration/defaults/liveview/genesis/
dist-newstyle
dist-newstyle/
dist-profiled/
dist/
Expand Down
2 changes: 2 additions & 0 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta
mStateView <- watchEpochStateUpdate epochStateView maxWait (const checkEpochState)
when (isNothing mStateView) $ do
val <- getFromEpochStateForEra
-- there's a tiny tiny chance that the value has changed since 'watchEpochStateUpdate'
-- so check it again
if val == expected
then pure ()
else H.failMessage callStack $ unlines
Expand Down
40 changes: 19 additions & 21 deletions cardano-testnet/src/Testnet/EpochStateProcessing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Testnet.EpochStateProcessing
import Cardano.Api
import Cardano.Api.Ledger (EpochInterval (..), GovActionId (..))
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (ShelleyLedgerEra)

import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Shelley.API as L
Expand All @@ -20,7 +19,6 @@ import qualified Cardano.Ledger.Shelley.LedgerState as L
import Prelude

import Control.Monad
import Data.Data ((:~:) (..))
import qualified Data.Map as Map
import Data.Maybe
import Data.Word (Word32)
Expand All @@ -29,7 +27,6 @@ import GHC.Stack
import Lens.Micro (to, (^.))

import Testnet.Components.Query (EpochStateView, watchEpochStateUpdate)
import Testnet.Property.Assert (assertErasEqual)

import Hedgehog
import Hedgehog.Extras (MonadAssertion)
Expand All @@ -55,15 +52,14 @@ maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState) =

-- | Wait for the last gov action proposal in the list to have DRep or SPO votes.
waitForGovActionVotes
:: forall m era. HasCallStack
:: forall m. HasCallStack
=> MonadAssertion m
=> MonadTest m
=> MonadIO m
=> EpochStateView -- ^ Current epoch state view. It can be obtained using the 'getEpochStateView' function.
-> ConwayEraOnwards era -- ^ The ConwayEraOnwards witness for current era.
-> EpochInterval -- ^ The maximum wait time in epochs.
-> m ()
waitForGovActionVotes epochStateView ceo maxWait = withFrozenCallStack $ do
waitForGovActionVotes epochStateView maxWait = withFrozenCallStack $ do
mResult <- watchEpochStateUpdate epochStateView maxWait checkForVotes
when (isNothing mResult) $
H.failMessage callStack "waitForGovActionVotes: No votes appeared before timeout."
Expand All @@ -72,19 +68,21 @@ waitForGovActionVotes epochStateView ceo maxWait = withFrozenCallStack $ do
:: HasCallStack
=> (AnyNewEpochState, SlotNo, BlockNo)
-> m (Maybe ())
checkForVotes (AnyNewEpochState actualEra newEpochState, _, _) = do
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
Refl <- H.leftFail $ assertErasEqual sbe actualEra
let govState :: L.ConwayGovState (ShelleyLedgerEra era)
govState = conwayEraOnwardsConstraints ceo $ newEpochState ^. newEpochStateGovStateL
proposals = govState ^. L.cgsProposalsL . L.pPropsL . to toList
if null proposals
then pure Nothing
else do
let lastProposal = last proposals
gaDRepVotes = lastProposal ^. L.gasDRepVotesL . to toList
gaSpoVotes = lastProposal ^. L.gasStakePoolVotesL . to toList
if null gaDRepVotes && null gaSpoVotes
then pure Nothing
else pure $ Just ()
checkForVotes (AnyNewEpochState actualEra newEpochState, _, _) = withFrozenCallStack $ do
caseShelleyToBabbageOrConwayEraOnwards
(const $ H.note_ "Only Conway era onwards is supported" >> failure)
(\ceo -> do
let govState = conwayEraOnwardsConstraints ceo $ newEpochState ^. newEpochStateGovStateL
proposals = govState ^. L.cgsProposalsL . L.pPropsL . to toList
if null proposals
then pure Nothing
else do
let lastProposal = last proposals
gaDRepVotes = lastProposal ^. L.gasDRepVotesL . to toList
gaSpoVotes = lastProposal ^. L.gasStakePoolVotesL . to toList
if null gaDRepVotes && null gaSpoVotes
then pure Nothing
else pure $ Just ()
)
actualEra

Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co

submitTx execConfig cEra voteTxFp

waitForGovActionVotes epochStateView ceo (L.EpochInterval 1)
waitForGovActionVotes epochStateView (L.EpochInterval 1)

govState <- getGovState epochStateView ceo
govActionState <- H.headM $ govState ^. L.cgsProposalsL . L.pPropsL . to toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ activityChangeProposalTest execConfig epochStateView ceo work prefix
(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp

-- Wait for the number of epochs for an enactment of the change
void $ waitForEpochs epochStateView minWait

forM_ mExpected $
-- enactment check
assertNewEpochState epochStateView sbe maxWait
(nesEpochStateL . epochStateGovStateL . curPParamsGovStateL . ppDRepActivityL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new

submitTx execConfig cEra voteTxFp

waitForGovActionVotes epochStateView ceo (EpochInterval 1)
waitForGovActionVotes epochStateView (EpochInterval 1)

-- Count votes before checking for ratification. It may happen that the proposal gets removed after
-- ratification because of a long waiting time, so we won't be able to access votes.
Expand Down

0 comments on commit b4e6c9c

Please sign in to comment.