Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash check in transaction build tests #6023

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ configuration/cardano/mainnet-alonzo-genesis.json text eol=lf
configuration/cardano/mainnet-byron-genesis.json text eol=lf
configuration/cardano/mainnet-conway-genesis.json text eol=lf
configuration/cardano/mainnet-shelley-genesis.json text eol=lf
cardano-testnet/test/cardano-testnet-test/files/sample-proposal-anchor text eol=lf
cardano-testnet/test/cardano-testnet-test/files/sample-constitution-anchor text eol=lf
14 changes: 14 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ packages:
trace-resources
trace-forward

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api
tag: d5e0a292ae459deff35fa00fbecb63133a3dcf9c
subdir: cardano-api
--sha256: sha256-AZeK0hiM+dROd4EUncCLnu9ONtnUGonS9ly2NdIJXVA=

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-cli
tag: d854349759700ad18089ae84f6157e1ba9f0b8b2
subdir: cardano-cli
--sha256: sha256-7Nrh5i4hs/cgSOTBnicXQLfcOcClo/Ml0yuPBI2BRv8=

extra-packages: Cabal

program-options
Expand Down
7 changes: 5 additions & 2 deletions 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 @@ -204,6 +205,7 @@ test-suite cardano-testnet-test
Cardano.Testnet.Test.Gov.PredefinedAbstainDRep
Cardano.Testnet.Test.Gov.ProposeNewConstitution
Cardano.Testnet.Test.Gov.ProposeNewConstitutionSPO
Cardano.Testnet.Test.Gov.Transaction.HashMismatch
Cardano.Testnet.Test.Gov.TreasuryDonation
Cardano.Testnet.Test.Gov.TreasuryGrowth
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
Expand All @@ -220,7 +222,7 @@ test-suite cardano-testnet-test
, base16-bytestring
, bytestring
, cardano-api:{cardano-api, internal}
, cardano-cli
, cardano-cli:{cardano-cli, cardano-cli-test-lib}
, cardano-crypto-class
, cardano-ledger-conway
, cardano-ledger-core
Expand All @@ -240,6 +242,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 @@ -26,6 +27,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 @@ -35,11 +37,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 @@ -339,7 +343,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 @@ -361,42 +365,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) [Some $ paymentKeyInfoPair wallet]
Expand Down
12 changes: 12 additions & 0 deletions cardano-testnet/src/Testnet/Process/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Testnet.Process.Run
, mkExecConfigOffline
, ProcessError(..)
, ExecutableError(..)
, addEnvVarsToConfig
) where

import Prelude
Expand All @@ -33,6 +34,7 @@ import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import Data.Function
import qualified Data.List as List
import Data.Maybe (fromMaybe)
import Data.Monoid (Last (..))
import Data.String (fromString)
import qualified Data.Text as Text
Expand Down Expand Up @@ -193,6 +195,16 @@ mkExecConfig tempBaseAbsPath sprocket networkId = do
, H.execConfigCwd = Last $ Just tempBaseAbsPath
}

-- | Adds environment variables to an 'ExecConfig' that may already
-- have some environment variables set. This is done by prepending the new
-- environment variables to the existing ones.
addEnvVarsToConfig :: H.ExecConfig -> [(String, String)] -> H.ExecConfig
palas marked this conversation as resolved.
Show resolved Hide resolved
addEnvVarsToConfig execConfig newEnvVars =
execConfig { H.execConfigEnv = Last $ Just $ newEnvVars <> prevEnvVars }
where
prevEnvVars :: [(String, String)]
prevEnvVars = fromMaybe [] . getLast $ H.execConfigEnv execConfig

-- | Creates an 'ExecConfig' that can be used to run a process offline.
-- e.g cardano-cli without a node running.
mkExecConfigOffline :: ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import qualified Hedgehog.Extras as H
-- | Execute me with:
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/register deregister stake address in transaction build/"'@
hprop_tx_register_deregister_stake_address :: Property
hprop_tx_register_deregister_stake_address = integrationWorkspace "register-deregister-stake-address" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
hprop_tx_register_deregister_stake_address = integrationWorkspace "register-deregister-stake-addr" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
-- Start a local test net
conf@Conf { tempAbsPath } <- mkConf tempAbsBasePath'
let tempAbsPath' = unTmpAbsPath tempAbsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import qualified Data.Text as Text
import GHC.Exts (IsList (..))
import GHC.Stack
import Lens.Micro
import System.Directory (makeAbsolute)
import System.FilePath ((</>))

import Test.Cardano.CLI.Hash (serveFilesWhile)
import Testnet.Components.Configuration
import Testnet.Components.Query
import Testnet.Defaults
Expand All @@ -44,7 +46,7 @@ import Testnet.Process.Cli.Keys
import qualified Testnet.Process.Cli.SPO as SPO
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
import Testnet.Process.Cli.Transaction
import Testnet.Process.Run (execCli', mkExecConfig)
import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
import Testnet.Start.Types (GenesisOptions (..), cardanoNumPools)
import Testnet.Types
Expand Down Expand Up @@ -106,16 +108,15 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
H.note_ $ "Foldblocks config file: " <> unFile configurationFile

gov <- H.createDirectoryIfMissing $ work </> "governance"
proposalAnchorFp <- H.note $ gov </> "sample-proposal-anchor"
proposalDataFp <- H.note $ gov </> "sample-proposal-data"
updateCommitteeFp <- H.note $ gov </> "update-cc.action"

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

updateCommitteeFp <- H.note $ gov </> "update-cc.action"

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

let ccColdSKeyFp n = gov </> "cc-" <> show n <> "-cold.skey"
Expand Down Expand Up @@ -179,30 +180,42 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
EpochNo epochNo <- H.noteShowM $ getCurrentEpochNo epochStateView
let ccExpiryEpoch = epochNo + 200

_ <- execCli' execConfig $
[ eraName, "governance", "action" , "update-committee"
, "--testnet"
, "--anchor-url", "https://tinyurl.com/3wrwb2as"
, "--anchor-data-hash", proposalAnchorDataHash
, "--governance-action-deposit", show minGovActDeposit
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
, "--threshold", "0.2"
, "--out-file", updateCommitteeFp
]
<> concatMap
(\fp -> ["--add-cc-cold-verification-key-file", fp, "--epoch", show ccExpiryEpoch])
ccColdKeyFps
let relativeUrl = ["ipfs", proposalAnchorDataIpfsHash]

txbodyFp <- H.note $ work </> "tx.body"
txin1' <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
void $ execCli' execConfig
[ eraName, "transaction", "build"
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
, "--tx-in", Text.unpack $ renderTxIn txin1'
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show @Int 5_000_000
, "--proposal-file", updateCommitteeFp
, "--out-file", txbodyFp
]

-- 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' $
[ eraName, "governance", "action" , "update-committee"
, "--testnet"
, "--anchor-url", "ipfs://" ++ proposalAnchorDataIpfsHash
, "--anchor-data-hash", proposalAnchorDataHash
, "--check-anchor-data"
, "--governance-action-deposit", show minGovActDeposit
, "--deposit-return-stake-verification-key-file", verificationKeyFp stakeKeys
, "--threshold", "0.2"
, "--out-file", updateCommitteeFp
]
<> concatMap
(\fp -> ["--add-cc-cold-verification-key-file", fp, "--epoch", show ccExpiryEpoch])
ccColdKeyFps

void $ execCli' execConfig'
[ eraName, "transaction", "build"
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
, "--tx-in", Text.unpack $ renderTxIn txin1'
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show @Int 5_000_000
, "--proposal-file", updateCommitteeFp
, "--out-file", txbodyFp
]
)

-- double check that we're starting with an empty committee
committeeMembers <- getCommitteeMembers epochStateView ceo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -197,8 +198,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
Loading
Loading