Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 7, 2024
1 parent ee89cd8 commit 6a93688
Show file tree
Hide file tree
Showing 35 changed files with 434 additions and 321 deletions.
21 changes: 11 additions & 10 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ library
hs-source-dirs: src
exposed-modules: Cardano.Testnet
Parsers.Run
Testnet.Start.Byron
Testnet.Start.Types
Testnet.Components.Configuration
Testnet.Components.DReps
Testnet.Components.SPO
Testnet.Components.Query
Testnet.Components.SPO
Testnet.Components.TestWatchdog
Testnet.Defaults
Testnet.Filepath
Testnet.EpochStateProcessing
Testnet.Filepath
Testnet.Ping
Testnet.Process.Cli
Testnet.Process.Run
Testnet.Property.Assert
Testnet.Property.Run
Testnet.Property.Utils
Testnet.Process.Cli
Testnet.Process.Run
Testnet.Runtime
Testnet.Start.Byron
Testnet.Start.Types
Testnet.SubmitApi
Testnet.Ping
Testnet.Types

other-modules: Parsers.Cardano
Parsers.Help
Expand Down Expand Up @@ -186,15 +187,15 @@ test-suite cardano-testnet-test
Cardano.Testnet.Test.Cli.QuerySlotNumber
Cardano.Testnet.Test.FoldBlocks
Cardano.Testnet.Test.Misc

Cardano.Testnet.Test.Gov.ConstitutionalCommittee
Cardano.Testnet.Test.Gov.DRepActivity
Cardano.Testnet.Test.Gov.DRepDeposits
Cardano.Testnet.Test.Gov.DRepRetirement
Cardano.Testnet.Test.Gov.InfoAction
Cardano.Testnet.Test.Gov.ProposeNewConstitution
Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
Cardano.Testnet.Test.Gov.DRepActivity
Cardano.Testnet.Test.Gov.TreasuryGrowth
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
Cardano.Testnet.Test.SanityCheck

Cardano.Testnet.Test.Node.Shutdown
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Cardano/Testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ import Testnet.EpochStateProcessing
import Testnet.Filepath
import Testnet.Process.Run (procChairman)
import Testnet.Property.Utils
import Testnet.Runtime
import Testnet.Start.Cardano
import Testnet.Start.Types
import Testnet.Types
2 changes: 1 addition & 1 deletion cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import qualified Options.Applicative as OA

import Testnet.Process.Cli
import Testnet.Property.Utils
import Testnet.Runtime (readNodeLoggingFormat)
import Testnet.Start.Cardano
import Testnet.Start.Types
import Testnet.Types (readNodeLoggingFormat)


optsTestnet :: EnvCli -> Parser CardanoTestnetOptions
Expand Down
4 changes: 2 additions & 2 deletions cardano-testnet/src/Testnet/Components/DReps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ import Testnet.Components.Query (EpochStateView, findLargestUtxoForPay
getCurrentEpochNo, getMinDRepDeposit, waitUntilEpoch)
import qualified Testnet.Process.Cli as H
import qualified Testnet.Process.Run as H
import Testnet.Runtime (KeyPair (..),
import Testnet.Start.Types (anyEraToString)
import Testnet.Types (KeyPair (..),
PaymentKeyInfo (paymentKeyInfoAddr, paymentKeyInfoPair), PaymentKeyPair (..),
SomeKeyPair (..), StakingKeyPair (..))
import Testnet.Start.Types (anyEraToString)

import Hedgehog (MonadTest, evalMaybe)
import qualified Hedgehog.Extras as H
Expand Down
3 changes: 1 addition & 2 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Testnet.Components.Query
, findUtxosWithAddress
, findLargestUtxoWithAddress
, findLargestUtxoForPaymentKey
, startLedgerNewEpochStateLogging
) where

import Cardano.Api as Api
Expand Down Expand Up @@ -54,7 +53,7 @@ import Lens.Micro (to, (^.))

import Testnet.Property.Assert
import Testnet.Property.Utils (runInBackground)
import Testnet.Runtime
import Testnet.Types

import qualified Hedgehog as H
import Hedgehog.Extras (MonadAssertion)
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Testnet/Components/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import Testnet.Process.Cli hiding (File, unFile)
import qualified Testnet.Process.Run as H
import Testnet.Process.Run (execCli, execCli', execCli_)
import Testnet.Property.Utils
import Testnet.Runtime (PoolNodeKeys (poolNodeKeysColdVkey))
import Testnet.Start.Types
import Testnet.Types (PoolNodeKeys (poolNodeKeysColdVkey))

import Hedgehog
import Hedgehog.Extras (ExecConfig)
Expand Down
94 changes: 39 additions & 55 deletions cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ module Testnet.Defaults
, defaultByronProtocolParamsJsonValue
, defaultYamlConfig
, defaultConwayGenesis
, defaultDRepVkeyFp
, defaultDRepSkeyFp
, defaultDRepKeyPair
, defaultDelegatorStakeKeyPair
, defaultSPOKeys
, defaultSPOColdKeyPair
, defaultSPOColdVKeyFp
, defaultSPOColdSKeyFp
, defaultSpoKeys
, defaultSpoColdKeyPair
, defaultShelleyGenesis
, defaultGenesisFilepath
, defaultYamlHardforkViaConfig
Expand All @@ -30,7 +26,7 @@ module Testnet.Defaults
, plutusV3SpendingScript
) where

import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), pshow)
import Cardano.Api (AnyCardanoEra (..), CardanoEra (..), File (..), pshow)
import qualified Cardano.Api.Shelley as Api

import Cardano.Ledger.Alonzo.Core (PParams (..))
Expand Down Expand Up @@ -76,9 +72,8 @@ import Numeric.Natural
import System.FilePath ((</>))

import Test.Cardano.Ledger.Core.Rational
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..),
SPOColdKeyPair (..), StakingKeyPair (StakingKeyPair))
import Testnet.Start.Types
import Testnet.Types

{- HLINT ignore "Use underscore" -}

Expand Down Expand Up @@ -505,60 +500,49 @@ defaultGenesisFilepath era =
eraToString era <> "-genesis.json"

-- | The relative path to DRep keys in directories created by cardano-testnet
defaultDRepVkeyFp
defaultDRepKeyPair
:: Int -- ^ The DRep's index (starts at 1)
-> FilePath
defaultDRepVkeyFp n = "drep-keys" </> ("drep" <> show n) </> "drep.vkey"

-- | The relative path to DRep secret keys in directories created by cardano-testnet
defaultDRepSkeyFp
:: Int -- ^ The DRep's index (starts at 1)
-> FilePath
defaultDRepSkeyFp n = "drep-keys" </> ("drep" <> show n) </> "drep.skey"

-- | The relative path to DRep key pairs in directories created by cardano-testnet
defaultDRepKeyPair :: Int -> PaymentKeyPair
defaultDRepKeyPair n = PaymentKeyPair (defaultDRepVkeyFp n) (defaultDRepSkeyFp n)

-- | The relative path to SPO cold verification key in directories created by cardano-testnet
defaultSPOColdVKeyFp :: Int -> FilePath
defaultSPOColdVKeyFp n = "pools-keys" </> "pool" <> show n </> "cold.vkey"

-- | The relative path to SPO cold secret key in directories created by cardano-testnet
defaultSPOColdSKeyFp :: Int -> FilePath
defaultSPOColdSKeyFp n = "pools-keys" </> "pool" <> show n </> "cold.skey"
-> KeyPair DRepKey
defaultDRepKeyPair n =
KeyPair
{ verificationKey = File $ "drep-keys" </> ("drep" <> show n) </> "drep.vkey"
, signingKey = File $ "drep-keys" </> ("drep" <> show n) </> "drep.skey"
}

-- | The relative path to SPO key cold key pair in directories created by cardano-testnet
defaultSPOColdKeyPair :: Int -> SPOColdKeyPair
defaultSPOColdKeyPair n = SPOColdKeyPair (defaultSPOColdVKeyFp n) (defaultSPOColdSKeyFp n)
-- | The relative path to SPO keys in directories created by cardano-testnet
defaultSpoColdKeyPair
:: Int
-> KeyPair SpoColdKey
defaultSpoColdKeyPair n =
KeyPair
{ verificationKey = File $ "pools-keys" </> "pool" <> show n </> "cold.vkey"
, signingKey = File $ "pools-keys" </> "pool" <> show n </> "cold.skey"
}

-- | The relative path to SPO key pairs in directories created by cardano-testnet
defaultSPOKeys :: Int -> PoolNodeKeys
defaultSPOKeys n =
defaultSpoKeys :: Int -> PoolNodeKeys
defaultSpoKeys n =
PoolNodeKeys
{ poolNodeKeysColdVkey = defaultSPOColdVKeyFp n
, poolNodeKeysColdSkey = defaultSPOColdSKeyFp n
, poolNodeKeysVrfVkey = "pools-keys" </> "pool" ++ show n </> "vrf.vkey"
, poolNodeKeysVrfSkey = "pools-keys" </> "pool" ++ show n </> "vrf.skey"
, poolNodeKeysStakingVkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.vkey"
, poolNodeKeysStakingSkey = "pools-keys" </> "pool" ++ show n </> "staking-reward.skey"
{ poolNodeKeysCold = defaultSpoColdKeyPair n
, poolNodeKeysVrf =
KeyPair
{ verificationKey = File $ "pools-keys" </> "pool" ++ show n </> "vrf.vkey"
, signingKey = File $ "pools-keys" </> "pool" ++ show n </> "vrf.skey"
}
, poolNodeKeysStaking =
KeyPair
{ verificationKey = File $ "pools-keys" </> "pool" ++ show n </> "staking-reward.vkey"
, signingKey = File $ "pools-keys" </> "pool" ++ show n </> "staking-reward.skey"
}
}

-- | The relative path to stake delegator stake keys in directories created by cardano-testnet
defaultDelegatorStakeVkeyFp
:: Int -- ^ The Stake delegator index (starts at 1)
-> FilePath
defaultDelegatorStakeVkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.vkey"

-- | The relative path to stake delegator stake secret keys in directories created by cardano-testnet
defaultDelegatorStakeSkeyFp
:: Int -- ^ The Stake delegator index (starts at 1)
-> FilePath
defaultDelegatorStakeSkeyFp n = "stake-delegators" </> ("delegator" <> show n) </> "staking.skey"

-- | The relative path to stake delegator key pairs in directories created by cardano-testnet
defaultDelegatorStakeKeyPair :: Int -> StakingKeyPair
defaultDelegatorStakeKeyPair n = StakingKeyPair (defaultDelegatorStakeVkeyFp n) (defaultDelegatorStakeSkeyFp n)
defaultDelegatorStakeKeyPair :: Int -> KeyPair StakingKey
defaultDelegatorStakeKeyPair n =
KeyPair
{ verificationKey = File $ "stake-delegators" </> ("delegator" <> show n) </> "staking.vkey"
, signingKey = File $ "stake-delegators" </> ("delegator" <> show n) </> "staking.skey"
}

-- TODO: We should not hardcode a script like this. We need to move
-- plutus-example from plutus apps to cardano-node-testnet. This will
Expand Down
36 changes: 17 additions & 19 deletions cardano-testnet/src/Testnet/EpochStateProcessing.hs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

module Testnet.EpochStateProcessing
( maybeExtractGovernanceActionIndex
, findCondition
) where

import Cardano.Api (AnyNewEpochState (..), ConwayEra, EpochNo, File (File),
FoldBlocksError, LedgerStateCondition (..), MonadIO, ShelleyBasedEra,
ValidationMode (FullValidation), foldEpochState, runExceptT,
shelleyBasedEraConstraints)
import qualified Cardano.Api as Api
import Cardano.Api
import Cardano.Api.Ledger (GovActionId (..))
import qualified Cardano.Api.Ledger as L

import qualified Cardano.Ledger.Conway.Governance as L
import Cardano.Ledger.Shelley.API (TxId (..))
import qualified Cardano.Ledger.Shelley.API as L
import qualified Cardano.Ledger.Shelley.LedgerState as L

import Prelude

import Control.Monad.State.Strict (MonadState (put), StateT)
import Data.Data ((:~:) (..))
import qualified Data.Map as Map
import Data.Type.Equality (TestEquality (..))
import Data.Word (Word32)
import GHC.Stack
import Lens.Micro ((^.))

import Testnet.Property.Assert (assertErasEqual)

import Hedgehog

findCondition
Expand Down Expand Up @@ -58,20 +57,19 @@ findCondition epochStateFoldFunc configurationFile socketPath maxEpochNo = withF
Just x -> put (Just x) >> pure ConditionMet
Nothing -> pure ConditionNotMet

maybeExtractGovernanceActionIndex :: ShelleyBasedEra ConwayEra -- ^ The era in which the test runs
-> Api.TxId
maybeExtractGovernanceActionIndex
:: forall era. HasCallStack
=> ConwayEraOnwards era -- ^ The era in which the test runs
-> TxId -- ^ transaction id searched for
-> AnyNewEpochState
-> Maybe Word32
maybeExtractGovernanceActionIndex sbe txid (AnyNewEpochState actualEra newEpochState) =
case testEquality sbe actualEra of
Just Refl -> do
let proposals = shelleyBasedEraConstraints sbe newEpochState
^. L.newEpochStateGovStateL
. L.proposalsGovStateL
Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals)
Nothing -> do
error $ "Eras mismatch! expected: " <> show sbe <> ", actual: " <> show actualEra
maybeExtractGovernanceActionIndex ceo txid (AnyNewEpochState actualEra newEpochState) = conwayEraOnwardsConstraints ceo $ do
let sbe = conwayEraOnwardsToShelleyBasedEra ceo
Refl <- either error pure $ assertErasEqual sbe actualEra
let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL
Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals)
where
compareWithTxId (Api.TxId ti1) Nothing (GovActionId (TxId ti2) (L.GovActionIx gai)) _
compareWithTxId (TxId ti1) Nothing (GovActionId (L.TxId ti2) (L.GovActionIx gai)) _
| ti1 == L.extractHash ti2 = Just gai
compareWithTxId _ x _ _ = x

Loading

0 comments on commit 6a93688

Please sign in to comment.