From d1fdfc3afcf73cd66775a656e1bb9cce83edd9b5 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Mon, 13 May 2024 12:26:40 -0400 Subject: [PATCH] Add pparams update test separate. Need to undo changes to propose constitution! --- .../Cardano/Testnet/Test/Gov/UpdatePParam.hs | 85 ++++++------------- .../cardano-testnet-test.hs | 4 +- 2 files changed, 31 insertions(+), 58 deletions(-) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/UpdatePParam.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/UpdatePParam.hs index 6249915ab6b..c281e0de96c 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/UpdatePParam.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/UpdatePParam.hs @@ -12,28 +12,24 @@ module Cardano.Testnet.Test.Gov.UpdatePParam import Cardano.Api as Api import Cardano.Api.Ledger (EpochInterval (..)) import qualified Cardano.Api.Ledger as L +import Cardano.Api.Shelley (createAnchor) -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.Conway.PParams as L -import qualified Cardano.Ledger.Core 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.Aeson.Encode.Pretty (encodePretty) import Data.Bifunctor (first) +import qualified Data.ByteString as BS import qualified Data.Map.Strict as Map import Data.Maybe -import Data.Maybe.Strict import Data.String import qualified Data.Text as Text import Data.Word -import GHC.Exts (IsList (..)) import Lens.Micro import System.FilePath (()) @@ -52,7 +48,7 @@ import Hedgehog import qualified Hedgehog.Extras as H -- | Execute me with: --- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/Propose And Ratify New Constitution/"'@ +-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/Update PParams/"'@ hprop_update_pparam :: Property hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempAbsBasePath' -> runWithDefaultWatchdog_ $ do -- Start a local test net @@ -61,10 +57,14 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath work <- H.createDirectoryIfMissing $ tempAbsPath' "work" - - -- Generate model for votes - let allVotes :: [(String, Int)] + let ceo = ConwayEraOnwardsConway + sbe = conwayEraOnwardsToShelleyBasedEra ceo + era = toCardanoEra sbe + cEra = AnyCardanoEra era + -- Generate model for votes + allVotes :: [(String, Int)] allVotes = zip (concatMap (uncurry replicate) [(4, "yes"), (3, "no"), (2, "abstain")]) [1..] + annotateShow allVotes let numVotes :: Int @@ -73,12 +73,22 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA guardRailScript <- H.note $ work "guard-rail-script.plutusV3" H.writeFile guardRailScript $ Text.unpack plutusV3NonSpendingScript + execConfigOffline <- H.mkExecConfigOffline tempBaseAbsPath + + gov <- H.createDirectoryIfMissing $ work "governance" + + proposalAnchorFile <- H.note $ gov "sample-proposal-anchor" + H.writeFile proposalAnchorFile "dummy anchor data" + proposalAnchorDataBS <- evalIO $ BS.readFile proposalAnchorFile + proposalAnchorDataHash <- H.execCli' execConfigOffline + [ "conway", "governance" + , "hash", "anchor-data", "--file-text", proposalAnchorFile + ] -- TODO: Update help text for policyid. The script hash is not -- only useful for minting scripts - -- TODO: Left off here. Use offline execConfig function constitutionScriptHash <- filter (/= '\n') <$> - H.execCli' execConfig + H.execCli' execConfigOffline [ anyEraToString cEra, "transaction" , "policyid" , "--script-file", guardRailScript @@ -86,16 +96,15 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA H.note_ $ "Constitution script hash: " <> constitutionScriptHash - let ceo = ConwayEraOnwardsConway - sbe = conwayEraOnwardsToShelleyBasedEra ceo - era = toCardanoEra sbe - cEra = AnyCardanoEra era - fastTestnetOptions = cardanoDefaultTestnetOptions + url <- evalMaybe $ L.textToUrl 28 "https://tinyurl.com/3wrwb2as" + let fastTestnetOptions = cardanoDefaultTestnetOptions { cardanoEpochLength = 100 , cardanoNodeEra = cEra , cardanoNumDReps = numVotes } - constitution = undefined + anchor = createAnchor url proposalAnchorDataBS + ScriptHash cScriptHash = fromString constitutionScriptHash + constitution = L.Constitution anchor $ L.SJust cScriptHash alonzoGenesis <- evalEither $ first prettyError defaultAlonzoGenesis (startTime, shelleyGenesis') <- getDefaultShelleyGenesis fastTestnetOptions @@ -123,15 +132,7 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA H.note_ $ "Abs path: " <> tempAbsBasePath' H.note_ $ "Socketpath: " <> unFile socketPath H.note_ $ "Foldblocks config file: " <> unFile configurationFile - gov <- H.createDirectoryIfMissing $ work "governance" - - proposalAnchorFile <- H.note $ gov "sample-proposal-anchor" - H.writeFile proposalAnchorFile "dummy anchor data" - proposalAnchorDataHash <- H.execCli' execConfig - [ "conway", "governance" - , "hash", "anchor-data", "--file-text", proposalAnchorFile - ] let stakeVkeyFp = gov "stake.vkey" stakeSKeyFp = gov "stake.skey" @@ -228,6 +229,7 @@ hprop_update_pparam = H.integrationWorkspace "propose-new-constitution" $ \tempA pparamsVoteTxBodyFp <- createVotingTxBody execConfig epochStateView sbe work "pparams-vote-tx-body" pparamsVoteFiles wallet0 + let signingKeys = SomeKeyPair <$> (paymentKeyInfoPair wallet0:(defaultDRepKeyPair . snd <$> allVotes)) pparamsVoteTxFp <- signTx execConfig cEra work "signed-vote-tx" pparamsVoteTxBodyFp signingKeys submitTx execConfig cEra pparamsVoteTxFp @@ -252,34 +254,3 @@ checkPParamsUpdated committeeTermLength (AnyNewEpochState sbe nes) = in if curCommTermLength == committeeTermLength then Just () -- PParams was successfully updated and we terminate the fold. else Nothing -- PParams was not updated yet, we continue the fold. - -checkConstitutionWasRatified - :: String -- submitted constitution hash - -> String -- submitted guard rail script hash - -> AnyNewEpochState - -> StateT s IO LedgerStateCondition -- ^ Accumulator at block i and fold status -checkConstitutionWasRatified submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState = - if filterRatificationState submittedConstitutionHash submittedGuardRailScriptHash anyNewEpochState - then return ConditionMet - else return ConditionNotMet - -filterRatificationState - :: String -- ^ Submitted constitution anchor hash - -> String -- ^ Submitted guard rail script hash - -> AnyNewEpochState - -> Bool -filterRatificationState c guardRailScriptHash (AnyNewEpochState sbe newEpochState) = do - caseShelleyToBabbageOrConwayEraOnwards - (const $ error "filterRatificationState: Only conway era supported") - - (const $ do - -- This is the next ratify state! Not the current constitution!!! - let constitution = newEpochState ^. L.newEpochStateGovStateL . L.cgsConstitutionL - constitutionAnchorHash = Ledger.anchorDataHash $ Ledger.constitutionAnchor constitution - L.ScriptHash constitutionScriptHash = fromMaybe (error "filterRatificationState: consitution does not have a guardrail script") - $ strictMaybeToMaybe $ constitution ^. Ledger.constitutionScriptL - Text.pack c == renderSafeHashAsHex constitutionAnchorHash && L.hashToTextAsHex constitutionScriptHash == Text.pack guardRailScriptHash - - ) - sbe - diff --git a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs index 9e23c8db3b4..2aabb467077 100644 --- a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs +++ b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs @@ -21,6 +21,7 @@ import qualified Cardano.Testnet.Test.Gov.ProposeNewConstitution as Gov import qualified Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO as Gov import qualified Cardano.Testnet.Test.Gov.TreasuryGrowth as Gov import qualified Cardano.Testnet.Test.Gov.TreasuryWithdrawal as Gov +import qualified Cardano.Testnet.Test.Gov.UpdatePParam as Gov import qualified Cardano.Testnet.Test.Node.Shutdown import qualified Cardano.Testnet.Test.SanityCheck as LedgerEvents import qualified Cardano.Testnet.Test.SubmitApi.Babbage.Transaction @@ -49,7 +50,8 @@ tests = do , H.ignoreOnWindows "Treasury Growth" Gov.prop_check_if_treasury_is_growing -- TODO: Replace foldBlocks with checkLedgerStateCondition , T.testGroup "Governance" - [ H.ignoreOnMacAndWindows "Committee Add New" Gov.hprop_constitutional_committee_add_new + [ H.ignoreOnMacAndWindows "Update PParams" Gov.hprop_update_pparam + , H.ignoreOnMacAndWindows "Committee Add New" Gov.hprop_constitutional_committee_add_new , H.ignoreOnMacAndWindows "Committee Motion Of No Confidence" Gov.hprop_gov_no_confidence -- 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