From f1bf8b12e966ee93080f7ab2038b1c8a8e4eb191 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 6 Jun 2024 21:16:27 +0200 Subject: [PATCH] Move `makeActivityChangeProposal` to `DRep.hs` --- .../src/Testnet/Process/Cli/DRep.hs | 91 ++++++++++++++++++- .../Cardano/Testnet/Test/Gov/DRepActivity.hs | 91 +------------------ .../Testnet/Test/Gov/PParamChangeFailsSPO.hs | 1 - 3 files changed, 91 insertions(+), 92 deletions(-) diff --git a/cardano-testnet/src/Testnet/Process/Cli/DRep.hs b/cardano-testnet/src/Testnet/Process/Cli/DRep.hs index 4406b8408cb..ad6eff60d8c 100644 --- a/cardano-testnet/src/Testnet/Process/Cli/DRep.hs +++ b/cardano-testnet/src/Testnet/Process/Cli/DRep.hs @@ -13,10 +13,13 @@ module Testnet.Process.Cli.DRep , registerDRep , delegateToDRep , getLastPParamUpdateActionId + , makeActivityChangeProposal ) where import Cardano.Api hiding (Certificate, TxBody) -import Cardano.Api.Ledger (EpochInterval (EpochInterval)) +import Cardano.Api.Ledger (EpochInterval (EpochInterval, unEpochInterval)) + +import Cardano.Testnet (maybeExtractGovernanceActionIndex) import Prelude @@ -26,12 +29,15 @@ import qualified Data.Aeson as Aeson import qualified Data.Aeson.Lens as AL import Data.Text (Text) import qualified Data.Text as Text +import Data.Typeable (Typeable) import Data.Word (Word32) +import GHC.Exts (fromString) import GHC.Stack import Lens.Micro ((^?)) import System.FilePath (()) import Testnet.Components.Query +import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen) import Testnet.Process.Cli.Transaction import Testnet.Process.Run (execCli', execCliStdoutToJson) import Testnet.Types @@ -329,3 +335,86 @@ getLastPParamUpdateActionId execConfig = do actionIx <- evalMaybe mActionIx txId <- evalMaybe mTxId return (Just (Text.unpack txId, fromIntegral actionIx)) + +-- | Create a proposal to change the DRep activity interval. +-- Return the transaction id and the index of the governance action. +makeActivityChangeProposal + :: (HasCallStack, H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m, Typeable era) + => H.ExecConfig -- ^ Specifies the CLI execution configuration. + -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained + -- using the 'getEpochStateView' function. + -> ConwayEraOnwards era -- ^ The 'ConwayEraOnwards' witness for current era. + -> FilePath -- ^ Base directory path where generated files will be stored. + -> String -- ^ Name for the subfolder that will be created under 'work' folder. + -> Maybe (String, Word32) -- ^ The transaction id and the index of the previosu governance action if any. + -> EpochInterval -- ^ The target DRep activity interval to be set by the proposal. + -> PaymentKeyInfo -- ^ Wallet that will pay for the transaction. + -> EpochInterval -- ^ Number of epochs to wait for the proposal to be registered by the chain. + -> m (String, Word32) -- ^ The transaction id and the index of the governance action. +makeActivityChangeProposal execConfig epochStateView ceo work prefix + prevGovActionInfo drepActivity wallet timeout = do + + let sbe = conwayEraOnwardsToShelleyBasedEra ceo + era = toCardanoEra sbe + cEra = AnyCardanoEra era + + baseDir <- H.createDirectoryIfMissing $ work prefix + + let stakeVkeyFp = baseDir "stake.vkey" + stakeSKeyFp = baseDir "stake.skey" + + cliStakeAddressKeyGen + $ KeyPair { verificationKey = File stakeVkeyFp + , signingKey = File stakeSKeyFp + } + + proposalAnchorFile <- H.note $ baseDir "sample-proposal-anchor" + H.writeFile proposalAnchorFile "dummy anchor data" + + proposalAnchorDataHash <- execCli' execConfig + [ "conway", "governance" + , "hash", "anchor-data", "--file-text", proposalAnchorFile + ] + + minDRepDeposit <- getMinDRepDeposit epochStateView ceo + + proposalFile <- H.note $ baseDir "sample-proposal-anchor" + + void $ execCli' execConfig $ + [ "conway", "governance", "action", "create-protocol-parameters-update" + , "--testnet" + , "--governance-action-deposit", show @Integer minDRepDeposit + , "--deposit-return-stake-verification-key-file", stakeVkeyFp + ] ++ concatMap (\(prevGovernanceActionTxId, prevGovernanceActionIndex) -> + [ "--prev-governance-action-tx-id", prevGovernanceActionTxId + , "--prev-governance-action-index", show prevGovernanceActionIndex + ]) prevGovActionInfo ++ + [ "--drep-activity", show (unEpochInterval drepActivity) + , "--anchor-url", "https://tinyurl.com/3wrwb2as" + , "--anchor-data-hash", proposalAnchorDataHash + , "--out-file", proposalFile + ] + + proposalBody <- H.note $ baseDir "tx.body" + txIn <- findLargestUtxoForPaymentKey epochStateView sbe wallet + + void $ execCli' execConfig + [ "conway", "transaction", "build" + , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet + , "--tx-in", Text.unpack $ renderTxIn txIn + , "--proposal-file", proposalFile + , "--out-file", proposalBody + ] + + signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal" + (File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet] + + submitTx execConfig cEra signedProposalTx + + governanceActionTxId <- retrieveTransactionId execConfig signedProposalTx + + governanceActionIndex <- + H.nothingFailM $ watchEpochStateUpdate epochStateView timeout $ \(anyNewEpochState, _, _) -> + return $ maybeExtractGovernanceActionIndex (fromString governanceActionTxId) anyNewEpochState + + return (governanceActionTxId, governanceActionIndex) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs index f46ec881246..c3bec1a1bd3 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/DRepActivity.hs @@ -3,12 +3,9 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} module Cardano.Testnet.Test.Gov.DRepActivity ( hprop_check_drep_activity - , makeActivityChangeProposal - , voteChangeProposal ) where import Cardano.Api as Api @@ -26,8 +23,6 @@ import Control.Monad import Control.Monad.Catch (MonadCatch) import Data.Data (Typeable) import qualified Data.Map as Map -import Data.String -import qualified Data.Text as Text import Data.Word (Word32) import GHC.Stack (HasCallStack, withFrozenCallStack) import System.FilePath (()) @@ -35,9 +30,8 @@ import System.FilePath (()) import Testnet.Components.Query import Testnet.Defaults (defaultDRepKeyPair, defaultDelegatorStakeKeyPair) import Testnet.Process.Cli.DRep -import Testnet.Process.Cli.Keys import Testnet.Process.Cli.Transaction -import Testnet.Process.Run (execCli', mkExecConfig) +import Testnet.Process.Run (mkExecConfig) import Testnet.Property.Util (integrationWorkspace) import Testnet.Types @@ -210,89 +204,6 @@ activityChangeProposalTest execConfig epochStateView ceo work prefix pure thisProposal --- | Create a proposal to change the DRep activity interval. --- Return the transaction id and the index of the governance action. -makeActivityChangeProposal - :: (HasCallStack, H.MonadAssertion m, MonadTest m, MonadCatch m, MonadIO m, Typeable era) - => H.ExecConfig -- ^ Specifies the CLI execution configuration. - -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained - -- using the 'getEpochStateView' function. - -> ConwayEraOnwards era -- ^ The 'ConwayEraOnwards' witness for current era. - -> FilePath -- ^ Base directory path where generated files will be stored. - -> String -- ^ Name for the subfolder that will be created under 'work' folder. - -> Maybe (String, Word32) -- ^ The transaction id and the index of the previosu governance action if any. - -> EpochInterval -- ^ The target DRep activity interval to be set by the proposal. - -> PaymentKeyInfo -- ^ Wallet that will pay for the transaction. - -> EpochInterval -- ^ Number of epochs to wait for the proposal to be registered by the chain. - -> m (String, Word32) -- ^ The transaction id and the index of the governance action. -makeActivityChangeProposal execConfig epochStateView ceo work prefix - prevGovActionInfo drepActivity wallet timeout = do - - let sbe = conwayEraOnwardsToShelleyBasedEra ceo - era = toCardanoEra sbe - cEra = AnyCardanoEra era - - baseDir <- H.createDirectoryIfMissing $ work prefix - - let stakeVkeyFp = baseDir "stake.vkey" - stakeSKeyFp = baseDir "stake.skey" - - cliStakeAddressKeyGen - $ KeyPair { verificationKey = File stakeVkeyFp - , signingKey = File stakeSKeyFp - } - - proposalAnchorFile <- H.note $ baseDir "sample-proposal-anchor" - H.writeFile proposalAnchorFile "dummy anchor data" - - proposalAnchorDataHash <- execCli' execConfig - [ "conway", "governance" - , "hash", "anchor-data", "--file-text", proposalAnchorFile - ] - - minDRepDeposit <- getMinDRepDeposit epochStateView ceo - - proposalFile <- H.note $ baseDir "sample-proposal-anchor" - - void $ execCli' execConfig $ - [ "conway", "governance", "action", "create-protocol-parameters-update" - , "--testnet" - , "--governance-action-deposit", show @Integer minDRepDeposit - , "--deposit-return-stake-verification-key-file", stakeVkeyFp - ] ++ concatMap (\(prevGovernanceActionTxId, prevGovernanceActionIndex) -> - [ "--prev-governance-action-tx-id", prevGovernanceActionTxId - , "--prev-governance-action-index", show prevGovernanceActionIndex - ]) prevGovActionInfo ++ - [ "--drep-activity", show (unEpochInterval drepActivity) - , "--anchor-url", "https://tinyurl.com/3wrwb2as" - , "--anchor-data-hash", proposalAnchorDataHash - , "--out-file", proposalFile - ] - - proposalBody <- H.note $ baseDir "tx.body" - txIn <- findLargestUtxoForPaymentKey epochStateView sbe wallet - - void $ execCli' execConfig - [ "conway", "transaction", "build" - , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet - , "--tx-in", Text.unpack $ renderTxIn txIn - , "--proposal-file", proposalFile - , "--out-file", proposalBody - ] - - signedProposalTx <- signTx execConfig cEra baseDir "signed-proposal" - (File proposalBody) [SomeKeyPair $ paymentKeyInfoPair wallet] - - submitTx execConfig cEra signedProposalTx - - governanceActionTxId <- retrieveTransactionId execConfig signedProposalTx - - governanceActionIndex <- - H.nothingFailM $ watchEpochStateUpdate epochStateView timeout $ \(anyNewEpochState, _, _) -> - return $ maybeExtractGovernanceActionIndex (fromString governanceActionTxId) anyNewEpochState - - return (governanceActionTxId, governanceActionIndex) - -- | Cast votes for a governance action. voteChangeProposal :: (HasCallStack, MonadTest m, MonadIO m, MonadCatch m, H.MonadAssertion m, Typeable era) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/PParamChangeFailsSPO.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/PParamChangeFailsSPO.hs index 6b69893bc5c..40606b78660 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/PParamChangeFailsSPO.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/PParamChangeFailsSPO.hs @@ -12,7 +12,6 @@ import Cardano.Api as Api import Cardano.Api.Ledger (EpochInterval (EpochInterval)) import Cardano.Testnet -import Cardano.Testnet.Test.Gov.DRepActivity (makeActivityChangeProposal) import Prelude