Skip to content

Commit

Permalink
Add ConstutionalCommittee test
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 7, 2024
1 parent eebadeb commit 5e4b018
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
1 change: 1 addition & 0 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ test-suite cardano-testnet-test
Cardano.Testnet.Test.Cli.Queries
Cardano.Testnet.Test.Cli.QuerySlotNumber
Cardano.Testnet.Test.FoldBlocks
Cardano.Testnet.Test.Gov.ConstitutionalCommittee
Cardano.Testnet.Test.Gov.DRepActivity
Cardano.Testnet.Test.Gov.DRepDeposits
Cardano.Testnet.Test.Gov.DRepRetirement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}

Check warning on line 2 in cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ConstitutionalCommittee.hs

View workflow job for this annotation

GitHub Actions / build

Warning in module Cardano.Testnet.Test.Gov.ConstitutionalCommittee: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE NumericUnderscores #-}"
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

Check warning on line 5 in cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ConstitutionalCommittee.hs

View workflow job for this annotation

GitHub Actions / build

Warning in module Cardano.Testnet.Test.Gov.ConstitutionalCommittee: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE TypeApplications #-}"

module Cardano.Testnet.Test.Gov.ConstitutionalCommittee
( hprop_constitutional_committee
) where

import Cardano.Api as Api
import Cardano.Api.Error (displayError)

import qualified Cardano.Crypto.Hash as L
import qualified Cardano.Ledger.Conway.Governance as L
import qualified Cardano.Ledger.Conway.Governance as Ledger
import qualified Cardano.Ledger.Hashes as L
import qualified Cardano.Ledger.Shelley.LedgerState as L
import Cardano.Testnet

import Prelude

import Control.Monad
import Control.Monad.State.Strict (StateT)
import Data.Maybe
import Data.Maybe.Strict
import Data.String
import qualified Data.Text as Text
import GHC.Exts (IsList (..))
import GHC.Stack (callStack)
import Lens.Micro
import System.FilePath ((</>))

import Testnet.Components.Configuration
import Testnet.Components.DReps (createVotingTxBody, generateVoteFiles,
retrieveTransactionId, signTx, submitTx)
import Testnet.Components.Query
import Testnet.Components.TestWatchdog
import Testnet.Defaults
import qualified Testnet.Process.Cli as P
import qualified Testnet.Process.Run as H
import qualified Testnet.Property.Utils as H
import Testnet.Types

import Hedgehog
import qualified Hedgehog.Extras as H
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO

hprop_constitutional_committee :: Property
hprop_constitutional_committee = H.integrationWorkspace "constitutional-committee" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do
-- Start a local test net
conf@Conf { tempAbsPath } <- mkConf tempAbsBasePath'
let tempAbsPath' = unTmpAbsPath tempAbsPath
tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath

work <- H.createDirectoryIfMissing $ tempAbsPath' </> "work"

-- Generate model for votes
let allVotes :: [(String, Int)]
allVotes = zip (concatMap (uncurry replicate) [(4, "yes"), (3, "no"), (2, "abstain")]) [1..]
annotateShow allVotes

let numVotes :: Int
numVotes = length allVotes
annotateShow numVotes

let ceo = ConwayEraOnwardsConway
sbe = conwayEraOnwardsToShelleyBasedEra ceo
era = toCardanoEra sbe
cEra = AnyCardanoEra era
fastTestnetOptions = cardanoDefaultTestnetOptions
{ cardanoEpochLength = 100
, cardanoNodeEra = cEra
, cardanoNumDReps = numVotes
}

TestnetRuntime
{ testnetMagic
, poolNodes
, wallets=wallet0:wallet1:_
, configurationFile
}
<- cardanoTestnetDefault fastTestnetOptions conf

poolNode1 <- H.headM poolNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic

let socketName' = IO.sprocketName poolSprocket1
socketBase = IO.sprocketBase poolSprocket1 -- /tmp
socketPath = socketBase </> socketName'

epochStateView <- getEpochStateView (File configurationFile) (File socketPath)

H.note_ $ "Sprocket: " <> show poolSprocket1
H.note_ $ "Abs path: " <> tempAbsBasePath'
H.note_ $ "Socketpath: " <> socketPath
H.note_ $ "Foldblocks config file: " <> configurationFile

-- Create Conway constitution
gov <- H.createDirectoryIfMissing $ work </> "governance"
proposalAnchorFile <- H.note $ gov </> "sample-proposal-anchor"
consitutionFile <- H.note $ gov </> "sample-constitution"
constitutionActionFp <- H.note $ gov </> "constitution.action"

H.writeFile proposalAnchorFile "dummy anchor data"
H.writeFile consitutionFile "dummy constitution data"
constitutionHash <- H.execCli' execConfig
[ "conway", "governance"
, "hash", "anchor-data", "--file-text", consitutionFile
]

proposalAnchorDataHash <- H.execCli' execConfig
[ "conway", "governance"
, "hash", "anchor-data", "--file-text", proposalAnchorFile
]

let stakeVkeyFp = gov </> "stake.vkey"
stakeSKeyFp = gov </> "stake.skey"

_ <- P.cliStakeAddressKeyGen tempAbsPath'
$ P.KeyNames { P.verificationKeyFile = stakeVkeyFp
, P.signingKeyFile = stakeSKeyFp
}

failure
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo
import qualified Cardano.Testnet.Test.Cli.Queries
import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber
import qualified Cardano.Testnet.Test.FoldBlocks
import qualified Cardano.Testnet.Test.Gov.ConstitutionalCommittee as ConstitutionalCommittee
import qualified Cardano.Testnet.Test.Gov.DRepDeposits
import qualified Cardano.Testnet.Test.Gov.DRepRetirement as DRepRetirement
import qualified Cardano.Testnet.Test.Gov.ProposeNewConstitution
Expand Down Expand Up @@ -47,7 +48,7 @@ tests = do
, H.ignoreOnWindows "Treasury Growth" LedgerEvents.prop_check_if_treasury_is_growing
-- TODO: Replace foldBlocks with checkLedgerStateCondition
, T.testGroup "Governance"
[ H.ignoreOnMacAndWindows "ProposeAndRatifyNewConstitution" Cardano.Testnet.Test.Gov.ProposeNewConstitution.hprop_ledger_events_propose_new_constitution
[ H.ignoreOnMacAndWindows "ConstitutionalCommittee" ConstitutionalCommittee.hprop_constitutional_committee
-- TODO: "DRep Activity" is too flaky at the moment. Disabling until we can fix it.
-- , H.ignoreOnWindows "DRep Activity" Cardano.Testnet.Test.LedgerEvents.Gov.DRepActivity.hprop_check_drep_activity
, H.ignoreOnWindows "DRep Deposits" Cardano.Testnet.Test.Gov.DRepDeposits.hprop_ledger_events_drep_deposits
Expand Down

0 comments on commit 5e4b018

Please sign in to comment.