Skip to content

Commit d1f30b5

Browse files
palascarbolymersmelc
authored
Add test for DRep Activity mechanism (#5796)
* Organize voting code in `ProposeNewConstitution` test * Organize more code in `ProposeNewConstitution` test * Initial version of DRepActivity test * Extract function for activity change proposals in `DRepActivity` * Register DReps after changing activity param * Add activity so that DReps expire * Refactor `activityChangeProposalTest` so that expected is optional * Remove `previousProposalInfo` parameter from `activityChangeProposalTest` * Fixes required by rebasing * Refactor `getCurrentEpochNo` so that it doesn't depend on era * Extract constants as variables for readability * Use `foldEpochState` to wait for stability * Fix hardcoded values * Apply suggested fix for typo in file name Co-authored-by: Mateusz Galazyn <[email protected]> * Move parameter explanations to the argument Haddocks * Move `KeyPair` class to `Testnet.Runtime` * Apply suggestions from code reviews Co-authored-by: Clément Hurlin <[email protected]> Co-authored-by: Mateusz Galazyn <[email protected]> --------- Co-authored-by: Mateusz Galazyn <[email protected]> Co-authored-by: Clément Hurlin <[email protected]>
1 parent 6526694 commit d1f30b5

File tree

10 files changed

+703
-171
lines changed

10 files changed

+703
-171
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ test-suite cardano-testnet-test
193193
Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution
194194
Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitutionSPO
195195
Cardano.Testnet.Test.LedgerEvents.Gov.TreasuryWithdrawal
196+
Cardano.Testnet.Test.LedgerEvents.Gov.DRepActivity
196197
Cardano.Testnet.Test.LedgerEvents.SanityCheck
197198
Cardano.Testnet.Test.LedgerEvents.TreasuryGrowth
198199

@@ -218,6 +219,7 @@ test-suite cardano-testnet-test
218219
, cardano-testnet
219220
, containers
220221
, directory
222+
, exceptions
221223
, filepath
222224
, hedgehog
223225
, hedgehog-extras

cardano-testnet/src/Testnet/Components/Configuration.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) (NumDReps numDelReps) era shell
121121
let genesisShelleyDirAbs = takeDirectory inputGenesisShelleyFp
122122
genesisShelleyDir <- H.createDirectoryIfMissing genesisShelleyDirAbs
123123
let testnetMagic = sgNetworkMagic shelleyGenesis
124-
numStakeDelegators = 3 :: Int
124+
-- At least there should be a delegator per DRep
125+
-- otherwise some won't be representing anybody
126+
numStakeDelegators = max 3 numDelReps :: Int
125127
startTime = sgSystemStart shelleyGenesis
126128

127129
-- TODO: Remove this rewrite.

cardano-testnet/src/Testnet/Components/DReps.hs

Lines changed: 265 additions & 93 deletions
Large diffs are not rendered by default.

cardano-testnet/src/Testnet/Components/Query.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Testnet.Components.Query
2020
, findLargestUtxoWithAddress
2121
, findLargestUtxoForPaymentKey
2222
, startLedgerNewEpochStateLogging
23+
, getCurrentEpochNo
2324
) where
2425

2526
import Cardano.Api as Api
@@ -301,7 +302,12 @@ checkDRepState sbe configurationFile socketPath execConfig f = withFrozenCallSta
301302
[ "checkDRepState: foldEpochState returned Nothing: "
302303
, "This is probably an error related to foldEpochState." ]
303304
H.failure
304-
Right (_, Just val) ->
305+
Right (ConditionNotMet, Just _) -> do
306+
H.note_ $ unlines
307+
[ "checkDRepState: foldEpochState returned Just and ConditionNotMet: "
308+
, "This is probably an error related to foldEpochState." ]
309+
H.failure
310+
Right (ConditionMet, Just val) ->
305311
return val
306312

307313
-- | Obtain governance state from node (CLI query)
@@ -336,3 +342,10 @@ getMinDRepDeposit execConfig ceo = withFrozenCallStack $ do
336342
. _Integral
337343
H.evalMaybe mMinDRepDeposit
338344

345+
-- | Obtain current epoch number using 'getEpochState'
346+
getCurrentEpochNo :: (MonadTest m, MonadAssertion m, MonadIO m)
347+
=> EpochStateView
348+
-> m EpochNo
349+
getCurrentEpochNo epochStateView = do
350+
AnyNewEpochState _ newEpochState <- getEpochState epochStateView
351+
return $ newEpochState ^. L.nesELL

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ module Testnet.Defaults
1616
, defaultConwayGenesis
1717
, defaultDRepVkeyFp
1818
, defaultDRepSkeyFp
19+
, defaultDRepKeyPair
1920
, defaultShelleyGenesis
2021
, defaultGenesisFilepath
2122
, defaultYamlHardforkViaConfig
2223
, defaultMainnetTopology
2324
, plutusV3NonSpendingScript
2425
, plutusV3SpendingScript
26+
, defaultDelegatorStakeKeyPair
2527
) where
2628

2729
import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), pshow)
@@ -70,6 +72,7 @@ import Numeric.Natural
7072
import System.FilePath ((</>))
7173

7274
import Test.Cardano.Ledger.Core.Rational
75+
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), StakingKeyPair (StakingKeyPair))
7376
import Testnet.Start.Types
7477

7578
{- HLINT ignore "Use underscore" -}
@@ -508,6 +511,26 @@ defaultDRepSkeyFp
508511
-> FilePath
509512
defaultDRepSkeyFp n = "drep-keys" </> ("drep" <> show n) </> "drep.skey"
510513

514+
-- | The relative path to DRep key pairs in directories created by cardano-testnet
515+
defaultDRepKeyPair :: Int -> PaymentKeyPair
516+
defaultDRepKeyPair n = PaymentKeyPair (defaultDRepVkeyFp n) (defaultDRepSkeyFp n)
517+
518+
-- | The relative path to stake delegator stake keys in directories created by cardano-testnet
519+
defaultDelegatorStakeVkeyFp
520+
:: Int -- ^ The Stake delegator index (starts at 1)
521+
-> FilePath
522+
defaultDelegatorStakeVkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.vkey"
523+
524+
-- | The relative path to stake delegator stake secret keys in directories created by cardano-testnet
525+
defaultDelegatorStakeSkeyFp
526+
:: Int -- ^ The Stake delegator index (starts at 1)
527+
-> FilePath
528+
defaultDelegatorStakeSkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.skey"
529+
530+
-- | The relative path to stake delegator key pairs in directories created by cardano-testnet
531+
defaultDelegatorStakeKeyPair :: Int -> StakingKeyPair
532+
defaultDelegatorStakeKeyPair n = StakingKeyPair (defaultDelegatorStakeVkeyFp n) (defaultDelegatorStakeSkeyFp n)
533+
511534
-- TODO: We should not hardcode a script like this. We need to move
512535
-- plutus-example from plutus apps to cardano-node-testnet. This will
513536
-- let us directly compile the plutus validators and avoid bit rotting of

cardano-testnet/src/Testnet/Runtime.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
{-# LANGUAGE NamedFieldPuns #-}
77
{-# LANGUAGE OverloadedStrings #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
9+
{-# LANGUAGE ExistentialQuantification #-}
10+
{-# LANGUAGE InstanceSigs #-}
911

1012
module Testnet.Runtime
1113
( LeadershipSlot(..)
@@ -18,6 +20,8 @@ module Testnet.Runtime
1820
, PoolNode(..)
1921
, PoolNodeKeys(..)
2022
, Delegator(..)
23+
, KeyPair(..)
24+
, SomeKeyPair(..)
2125
, allNodes
2226
, poolSprockets
2327
, poolNodeStdout
@@ -134,6 +138,22 @@ data LeadershipSlot = LeadershipSlot
134138
, slotTime :: Text
135139
} deriving (Eq, Show, Generic, FromJSON)
136140

141+
class KeyPair a where
142+
secretKey :: a -> FilePath
143+
144+
instance KeyPair PaymentKeyPair where
145+
secretKey :: PaymentKeyPair -> FilePath
146+
secretKey = paymentSKey
147+
148+
instance KeyPair StakingKeyPair where
149+
secretKey :: StakingKeyPair -> FilePath
150+
secretKey = stakingSKey
151+
152+
data SomeKeyPair = forall a . KeyPair a => SomeKeyPair a
153+
154+
instance KeyPair SomeKeyPair where
155+
secretKey :: SomeKeyPair -> FilePath
156+
secretKey (SomeKeyPair x) = secretKey x
137157

138158
poolNodeStdout :: PoolNode -> FilePath
139159
poolNodeStdout = nodeStdout . poolRuntime

0 commit comments

Comments
 (0)