Skip to content

Commit

Permalink
Update makeActivityChangeProposal to work with the new checks
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Oct 28, 2024
1 parent 7e9a49b commit a62a0d9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
4 changes: 3 additions & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library
, ansi-terminal
, bytestring
, cardano-api ^>= 10.1
, cardano-cli ^>= 10.1
, cardano-cli:{cardano-cli, cardano-cli-test-lib} ^>= 10.1
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-git-rev ^>= 0.2.2
Expand Down Expand Up @@ -65,6 +65,7 @@ library
, hedgehog-extras ^>= 0.6.4
, lens-aeson
, microlens
, monad-control
, mono-traversable
, mtl
, network
Expand Down Expand Up @@ -239,6 +240,7 @@ test-suite cardano-testnet-test
, lens
, lens-aeson
, microlens
, monad-control
, mtl
, process
, regex-compat
Expand Down
70 changes: 42 additions & 28 deletions cardano-testnet/src/Testnet/Process/Cli/DRep.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand All @@ -25,6 +26,7 @@ import Prelude

import Control.Monad (forM, void)
import Control.Monad.Catch (MonadCatch)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Lens as AL
import Data.Text (Text)
Expand All @@ -34,11 +36,13 @@ import Data.Word (Word16)
import GHC.Exts (fromString)
import GHC.Stack
import Lens.Micro ((^?))
import System.Directory (makeAbsolute)
import System.FilePath ((</>))

import Test.Cardano.CLI.Hash (serveFilesWhile)
import Testnet.Components.Query
import Testnet.Process.Cli.Transaction
import Testnet.Process.Run (execCli', execCliStdoutToJson)
import Testnet.Process.Run (addEnvVarsToConfig, execCli', execCliStdoutToJson)
import Testnet.Types

import Hedgehog (MonadTest, evalMaybe)
Expand Down Expand Up @@ -338,7 +342,7 @@ getLastPParamUpdateActionId execConfig = do
-- | 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)
:: (HasCallStack, MonadBaseControl IO m, 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.
Expand All @@ -360,42 +364,52 @@ makeActivityChangeProposal execConfig epochStateView ceo work

baseDir <- H.createDirectoryIfMissing work

proposalAnchorFile <- H.note $ baseDir </> "sample-proposal-anchor"
H.writeFile proposalAnchorFile "dummy anchor data"
let proposalAnchorDataIpfsHash = "QmexFJuEn5RtnHEqpxDcqrazdHPzAwe7zs2RxHLfMH5gBz"
proposalAnchorFile <- H.noteM $ liftIO $ makeAbsolute $ "test" </> "cardano-testnet-test" </> "files" </> "sample-proposal-anchor"

proposalAnchorDataHash <- execCli' execConfig
[ "hash", "anchor-data", "--file-text", proposalAnchorFile
[ "hash", "anchor-data", "--file-binary", proposalAnchorFile
]

minDRepDeposit <- getMinDRepDeposit epochStateView ceo
proposalFile <- H.note $ baseDir </> "proposa-file"

proposalFile <- H.note $ baseDir </> "sample-proposal-anchor"
minDRepDeposit <- getMinDRepDeposit epochStateView ceo

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
]
let relativeUrl = ["ipfs", proposalAnchorDataIpfsHash]

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
]
-- Create temporary HTTP server with files required by the call to `cardano-cli`
-- In this case, the server emulates an IPFS gateway
serveFilesWhile
[(relativeUrl, proposalAnchorFile)]
( \port -> do
let execConfig' = addEnvVarsToConfig execConfig [("IPFS_GATEWAY_URI", "http://localhost:" ++ show port ++ "/")]
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", "ipfs://" ++ proposalAnchorDataIpfsHash
, "--anchor-data-hash", proposalAnchorDataHash
, "--check-anchor-data"
, "--out-file", proposalFile
]

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Prelude

import Control.Monad
import Control.Monad.Catch (MonadCatch)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Data (Typeable)
import Data.Default.Class
import qualified Data.Map as Map
Expand Down Expand Up @@ -203,8 +204,8 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP
-- and issues the specified votes using default DReps. Optionally, it also
-- waits checks the expected effect of the proposal.
activityChangeProposalTest
:: forall m t era . (HasCallStack, MonadTest m, MonadIO m, H.MonadAssertion m, MonadCatch m, Foldable t, Typeable era,
EraGov (ShelleyLedgerEra era), ConwayEraPParams (ShelleyLedgerEra era))
:: forall m t era . (HasCallStack, MonadBaseControl IO m, MonadTest m, MonadIO m, H.MonadAssertion m,
MonadCatch m, Foldable t, Typeable era, EraGov (ShelleyLedgerEra era), ConwayEraPParams (ShelleyLedgerEra era))
=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
-- using the 'getEpochStateView' function.
Expand Down

0 comments on commit a62a0d9

Please sign in to comment.