Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mateusz Galazyn <228866+carbolymer@users.noreply.github.com>
  • Loading branch information
palas and carbolymer committed May 9, 2024
1 parent 848b14f commit a3b7e39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
20 changes: 10 additions & 10 deletions cardano-testnet/src/Testnet/EpochStateProcessing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Testnet.EpochStateProcessing
) where

import Cardano.Api
import Cardano.Api.Ledger (GovActionId (..))
import Cardano.Api.Ledger (EpochInterval (..), GovActionId (..))
import qualified Cardano.Api.Ledger as L

import qualified Cardano.Ledger.Conway.Governance as L
Expand All @@ -22,7 +22,7 @@ import Prelude

import Control.Monad.State.Strict (MonadState (put), StateT)
import qualified Data.Map as Map
import Data.Word (Word32, Word64)
import Data.Word (Word32)
import GHC.Stack
import Lens.Micro ((^.))

Expand Down Expand Up @@ -79,20 +79,20 @@ maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState) =
| ti1 == L.extractHash ti2 = Just gai
compareWithTxId _ x _ _ = x

-- | Watch the epoch state view until the guard function returns @Just@ or the timeout is reached.
-- | Wait for at least `minWait` epochs and at most `maxWait` epochs.
-- | The function will return the result of the guard function if it is met, otherwise it will return @Nothing@.
-- | Watch the epoch state view until the guard function returns 'Just' or the timeout epoch is reached.
-- Wait for at least @minWait@ epochs and at most @maxWait@ epochs.
-- The function will return the result of the guard function if it is met, otherwise it will return @Nothing@.
watchEpochStateView
:: forall m a. (MonadIO m, MonadTest m, MonadAssertion m)
:: forall m a. (HasCallStack, MonadIO m, MonadTest m, MonadAssertion m)
=> EpochStateView -- ^ The info to access the epoch state
-> (AnyNewEpochState -> m (Maybe a)) -- ^ The guard function (@Just@ if the condition is met, @Nothing@ otherwise)
-> Word64 -- ^ The minimum number of epochs to wait
-> Word64 -- ^ The maximum number of epochs to wait
-> EpochInterval -- ^ The minimum number of epochs to wait
-> EpochInterval -- ^ The maximum number of epochs to wait
-> m (Maybe a)
watchEpochStateView epochStateView f minWait maxWait = do
watchEpochStateView epochStateView f (EpochInterval minWait) (EpochInterval maxWait) = withFrozenCallStack $ do
AnyNewEpochState _ newEpochState <- getEpochState epochStateView
let (EpochNo currentEpoch) = L.nesEL newEpochState
go (EpochNo $ currentEpoch + minWait) (EpochNo $ currentEpoch + maxWait)
go (EpochNo $ currentEpoch + fromIntegral minWait) (EpochNo $ currentEpoch + fromIntegral maxWait)
where
go :: EpochNo -> EpochNo -> m (Maybe a)
go (EpochNo startEpoch) (EpochNo timeout) = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ import Testnet.Components.DRep (createVotingTxBody, delegateToDRep, ge
import Testnet.Components.Query (EpochStateView, checkDRepState,
findLargestUtxoForPaymentKey, getCurrentEpochNo, getEpochStateView,
getMinDRepDeposit)
import Testnet.Components.TestWatchdog
import Testnet.Defaults
import Testnet.Components.TestWatchdog (runWithDefaultWatchdog_)
import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair)
import Testnet.EpochStateProcessing (watchEpochStateView)
import qualified Testnet.Process.Cli as P
import qualified Testnet.Process.Run as H
import qualified Testnet.Property.Util as H
import Testnet.Types
import Testnet.Types (KeyPair (..), PaymentKeyInfo (..), PoolNode (..), SomeKeyPair (..),
TestnetRuntime (TestnetRuntime, configurationFile, poolNodes, testnetMagic, wallets),
nodeSocketPath)

import Hedgehog
import qualified Hedgehog as H
import Hedgehog (MonadTest, Property, annotateShow)
import qualified Hedgehog.Extras as H

-- | Execute me with:
Expand Down Expand Up @@ -92,9 +93,9 @@ hprop_check_drep_activity = H.integrationWorkspace "test-activity" $ \tempAbsBas
gov <- H.createDirectoryIfMissing $ work </> "governance"

-- This proposal should pass
let minEpochsToWaitIfChanging = 0 -- The change already provides a min bound
minEpochsToWaitIfNotChanging = 2 -- We cannot wait for change since there is no change (we wait a bit)
maxEpochsToWaitAfterProposal = 2 -- If it takes more than 2 epochs we give up in any case
let minEpochsToWaitIfChanging = EpochInterval 0 -- The change already provides a min bound
minEpochsToWaitIfNotChanging = EpochInterval 2 -- We cannot wait for change since there is no change (we wait a bit)
maxEpochsToWaitAfterProposal = EpochInterval 2 -- If it takes more than 2 epochs we give up in any case
firstTargetDRepActivity = 3
void $ activityChangeProposalTest execConfig epochStateView configurationFile socketPath ceo gov
"firstProposal" wallet0 [(1, "yes")] firstTargetDRepActivity
Expand Down Expand Up @@ -159,12 +160,12 @@ activityChangeProposalTest
-> PaymentKeyInfo
-> t (Int, String)
-> Word32
-> Word64
-> EpochInterval
-> Maybe Word32
-> Word64
-> EpochInterval
-> m (String, Word32)
activityChangeProposalTest execConfig epochStateView configurationFile socketPath ceo work prefix
wallet votes change minWait mExpected maxWait = do
wallet votes change minWait mExpected maxWait@(EpochInterval maxWaitNum) = do

let sbe = conwayEraOnwardsToShelleyBasedEra ceo

Expand All @@ -180,24 +181,22 @@ activityChangeProposalTest execConfig epochStateView configurationFile socketPat

thisProposal@(governanceActionTxId, governanceActionIndex) <-
makeActivityChangeProposal execConfig epochStateView configurationFile socketPath
ceo baseDir "proposal" mPreviousProposalInfo change wallet (epochBeforeProp + maxWait)
ceo baseDir "proposal" mPreviousProposalInfo change wallet (epochBeforeProp + fromIntegral maxWaitNum)

voteChangeProposal execConfig epochStateView sbe baseDir "vote"
governanceActionTxId governanceActionIndex propVotes wallet

(EpochNo epochAfterProp) <- getCurrentEpochNo epochStateView
H.note_ $ "Epoch after \"" <> prefix <> "\" prop: " <> show epochAfterProp

mResult <- watchEpochStateView epochStateView isSuccess minWait maxWait

void $ H.evalMaybe mResult
H.nothingFailM $ watchEpochStateView epochStateView isDRepActivityUpdated minWait maxWait

return thisProposal

where
isSuccess :: (HasCallStack, MonadTest m)
isDRepActivityUpdated :: (HasCallStack, MonadTest m)
=> AnyNewEpochState -> m (Maybe ())
isSuccess (AnyNewEpochState sbe newEpochState) =
isDRepActivityUpdated (AnyNewEpochState sbe newEpochState) =
caseShelleyToBabbageOrConwayEraOnwards
(const $ error "activityChangeProposalTest: Only conway era onwards supported")
(const $ do
Expand Down

0 comments on commit a3b7e39

Please sign in to comment.