Skip to content

Update cardano-cli. Remove redundant AsType constructors usages. #6204

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

Merged
merged 3 commits into from
May 16, 2025
Merged
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: 1 addition & 1 deletion bench/plutus-scripts-bench/plutus-scripts-bench.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ library
-- IOG dependencies
--------------------------
build-depends:
, cardano-api ^>=10.14
, cardano-api ^>=10.16
, plutus-ledger-api ^>=1.45
, plutus-tx ^>=1.45
, plutus-tx-plugin ^>=1.45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ instance ToJSON (SigningKey PaymentKey) where
instance FromJSON (SigningKey PaymentKey) where
parseJSON o = do
te <- parseJSON o
case deserialiseFromTextEnvelope (AsSigningKey AsPaymentKey) te of
case deserialiseFromTextEnvelope te of
Right k -> pure k
Left err -> fail $ show err

Expand Down
4 changes: 2 additions & 2 deletions bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ library
, attoparsec-aeson
, base16-bytestring
, bytestring
, cardano-api ^>= 10.14
, cardano-api ^>= 10.16
, cardano-binary
, cardano-cli ^>= 10.8
, cardano-cli ^>= 10.9
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-data
Expand Down
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2025-04-16T18:30:40Z
, cardano-haskell-packages 2025-04-29T14:14:35Z
, cardano-haskell-packages 2025-05-15T08:36:14Z

packages:
cardano-node
Expand Down
2 changes: 1 addition & 1 deletion cardano-node-chairman/cardano-node-chairman.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ test-suite chairman-tests
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T"

build-tool-depends: cardano-node:cardano-node
, cardano-cli:cardano-cli ^>= 10.8
, cardano-cli:cardano-cli ^>= 10.9
, cardano-node-chairman:cardano-node-chairman
2 changes: 1 addition & 1 deletion cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ library
, async
, base16-bytestring
, bytestring
, cardano-api ^>= 10.14
, cardano-api ^>= 10.16
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-git-rev ^>=0.2.2
Expand Down
19 changes: 9 additions & 10 deletions cardano-node/src/Cardano/Node/Protocol/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ readLeaderCredentialsSingleton
shelleyKESFile = Just kesFile
} = do
vrfSKey <-
firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsVrfKey) (File vrfFile))
firstExceptT FileError (newExceptT $ readFileTextEnvelope (File vrfFile))

(opCert, kesSKey) <- opCertKesKeyCheck (File kesFile) (File opCertFile)

Expand All @@ -172,9 +172,9 @@ opCertKesKeyCheck
-> ExceptT PraosLeaderCredentialsError IO (OperationalCertificate, SigningKey KesKey)
opCertKesKeyCheck kesFile certFile = do
opCert <-
firstExceptT FileError (newExceptT $ readFileTextEnvelope AsOperationalCertificate certFile)
firstExceptT FileError (newExceptT $ readFileTextEnvelope certFile)
kesSKey <-
firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsKesKey) kesFile)
firstExceptT FileError (newExceptT $ readFileTextEnvelope kesFile)
let opCertSpecifiedKesKeyhash = verificationKeyHash $ getHotKey opCert
suppliedKesKeyHash = verificationKeyHash $ getVerificationKey kesSKey
-- Specified KES key in operational certificate should match the one
Expand All @@ -201,9 +201,9 @@ readLeaderCredentialsBulk ProtocolFilepaths { shelleyBulkCredsFile = mfp } =
-> ExceptT PraosLeaderCredentialsError IO (ShelleyLeaderCredentials StandardCrypto)
parseShelleyCredentials ShelleyCredentials { scCert, scVrf, scKes } = do
mkPraosLeaderCredentials
<$> parseEnvelope AsOperationalCertificate scCert
<*> parseEnvelope (AsSigningKey AsVrfKey) scVrf
<*> parseEnvelope (AsSigningKey AsKesKey) scKes
<$> parseEnvelope scCert
<*> parseEnvelope scVrf
<*> parseEnvelope scKes

readBulkFile
:: Maybe FilePath
Expand Down Expand Up @@ -246,12 +246,11 @@ mkPraosLeaderCredentials

parseEnvelope ::
HasTextEnvelope a
=> AsType a
-> (TextEnvelope, String)
=> (TextEnvelope, String)
-> ExceptT PraosLeaderCredentialsError IO a
parseEnvelope as (te, loc) =
parseEnvelope (te, loc) =
firstExceptT (FileError . Api.FileError loc) . hoistEither $
deserialiseFromTextEnvelope as te
deserialiseFromTextEnvelope te


------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions cardano-submit-api/cardano-submit-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ library
, aeson
, async
, bytestring
, cardano-api ^>= 10.14
, cardano-api ^>= 10.16
, cardano-binary
, cardano-cli ^>= 10.8
, cardano-cli ^>= 10.9
, cardano-crypto-class ^>= 2.2
, http-media
, iohk-monitoring
Expand Down
4 changes: 2 additions & 2 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ library
, aeson-pretty
, ansi-terminal
, bytestring
, cardano-api ^>= 10.14
, cardano-cli:{cardano-cli, cardano-cli-test-lib} ^>= 10.8
, cardano-api ^>= 10.16
, cardano-cli:{cardano-cli, cardano-cli-test-lib} ^>= 10.9
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-git-rev ^>= 0.2.2
Expand Down
15 changes: 11 additions & 4 deletions cardano-testnet/src/Testnet/Process/Cli/Transaction.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Testnet.Process.Cli.Transaction
( mkSimpleSpendOutputsOnlyTx
Expand All @@ -23,21 +25,25 @@ import Prelude

import Control.Monad (void)
import Control.Monad.Catch (MonadCatch)
import qualified Data.Aeson.Lens as A
import Data.List (isInfixOf)
import Data.String (fromString)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import qualified Data.Yaml as A
import GHC.IO.Exception (ExitCode (..))
import GHC.Stack
import Lens.Micro
import System.FilePath ((</>))

import Hedgehog (MonadTest)
import qualified Hedgehog.Extras as H

import Testnet.Components.Query (EpochStateView, findLargestUtxoForPaymentKey)
import Testnet.Process.Run (execCli')
import Testnet.Start.Types (anyEraToString)
import Testnet.Types

import Hedgehog (MonadTest)
import qualified Hedgehog.Extras as H

-- Transaction signing
data VoteFile

Expand Down Expand Up @@ -231,5 +237,6 @@ retrieveTransactionId execConfig signedTxBody = do
[ "latest", "transaction", "txid"
, "--tx-file", unFile signedTxBody
]
return $ mconcat $ lines txidOutput
result <- H.leftFail $ A.decodeEither' @A.Value $ fromString txidOutput
H.nothingFail . fmap T.unpack $ result ^? A.key "txhash" . A._String

Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ import System.Directory (makeAbsolute)
import System.FilePath ((</>))
import qualified System.Info as SYS

import Hedgehog (Property)
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Golden as H
import qualified Hedgehog.Extras.Test.TestWatchdog as H

import Testnet.Components.Query (findLargestUtxoForPaymentKey, getEpochStateView, getTxIx,
watchEpochStateUpdate)
import Testnet.Process.Cli.Transaction (TxOutAddress (..), mkSpendOutputsOnlyTx,
Expand All @@ -57,6 +50,13 @@ import Testnet.Start.Types (eraToString)
import Testnet.Types (PaymentKeyInfo (paymentKeyInfoAddr), paymentKeyInfoPair,
verificationKey)

import Hedgehog (Property)
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Golden as H
import qualified Hedgehog.Extras.Test.TestWatchdog as H

-- @DISABLE_RETRIES=1 cabal run cardano-testnet-test -- -p "/Spec.hs.Spec.Ledger Events.Plutus.Cost Calc.Ref Script/"@
hprop_ref_plutus_cost_calculation :: Property
hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus script" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
Expand Down Expand Up @@ -183,7 +183,7 @@ hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus scri
execCli'
execConfig
[ eraName
, "transaction", "calculate-plutus-script-cost"
, "transaction", "calculate-plutus-script-cost", "online"
, "--tx-file", unFile signedUnlockTx
, "--out-file", unFile txCostOutput
]
Expand All @@ -199,7 +199,7 @@ hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus scri
execCli'
execConfig
[ eraName
, "transaction", "calculate-plutus-script-cost"
, "transaction", "calculate-plutus-script-cost", "online"
, "--tx-file", unFile signedUnlockTx
]

Expand Down Expand Up @@ -306,7 +306,7 @@ hprop_included_plutus_cost_calculation = integrationRetryWorkspace 2 "included p
execCli'
execConfig
[ eraName
, "transaction", "calculate-plutus-script-cost"
, "transaction", "calculate-plutus-script-cost", "online"
, "--tx-file", unFile signedIncludedScript
, "--out-file", unFile includedScriptCostOutput
]
Expand Down Expand Up @@ -421,7 +421,7 @@ hprop_included_simple_script_cost_calculation = integrationRetryWorkspace 2 "inc
execCli'
execConfig
[ eraName
, "transaction", "calculate-plutus-script-cost"
, "transaction", "calculate-plutus-script-cost", "online"
, "--tx-file", unFile signedScriptUnlock
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.Testnet.Test.Cli.Query (
hprop_cli_queries
Expand Down Expand Up @@ -36,10 +37,10 @@ import qualified Data.Aeson.Encode.Pretty as Aeson
import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.KeyMap as Aeson
import qualified Data.Aeson.Lens as Aeson
import Data.Bifunctor (bimap)
import qualified Data.ByteString.Lazy as LBS
import Data.Default.Class
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import Data.String (IsString (fromString))
import Data.Text (Text)
import qualified Data.Text as T
Expand Down Expand Up @@ -128,7 +129,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
-- leadership-schedule
do
let spoKeys = Defaults.defaultSpoKeys 1
spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work $ verificationKey $ poolNodeKeysCold spoKeys
spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work $ verificationKey $ poolNodeKeysCold spoKeys
H.noteM_ $ execCli' execConfig [ eraName, "query", "leadership-schedule"
, "--genesis", shelleyGeneisFile
, "--stake-pool-verification-key", T.unpack $ serialiseToBech32 spoVerificationKey
Expand Down Expand Up @@ -179,10 +180,11 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
do
-- to stdout
stakePoolsOut <- execCli' execConfig [ eraName, "query", "stake-pools" ]
H.assertWith stakePoolsOut $ \pools ->
NumPools (length $ lines pools) == nPools
stakePools <- H.noteShowM $ H.leftFail $ Aeson.eitherDecode @[String] $ fromString stakePoolsOut
H.assertWith stakePools $ \pools ->
NumPools (length pools) == nPools
-- Light test of the query's answer, the ids should exist:
forM_ (lines stakePoolsOut) $ \stakePoolId -> do
forM_ stakePools $ \stakePoolId -> do
execCli' execConfig [ eraName, "query", "pool-state"
, "--stake-pool-id", stakePoolId ]
-- to a file
Expand All @@ -199,22 +201,15 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
do
-- to stdout
stakeDistrOut <- execCli' execConfig [ eraName, "query", "stake-distribution" ]
-- stake addresses with stake
let stakeAddresses :: [(Text, Text)] =
map
( bimap T.strip T.strip
. T.breakOn " " -- separate address and stake
. T.strip
. fromString )
. drop 2 -- drop header
. lines
$ stakeDistrOut
H.assertWith stakeAddresses $ \sa ->
stakeDistr <- H.leftFail $ Aeson.eitherDecode @(Map String Aeson.Value) $ fromString stakeDistrOut
H.note_ stakeDistrOut
let stakePools = Map.keys stakeDistr
H.assertWith stakePools $ \sa ->
NumPools (length sa) == nPools
-- Light test of the query's answer, the ids should exist:
forM_ stakeAddresses $ \(stakePoolId, _) -> do
forM_ stakePools $ \stakePoolId -> do
execCli' execConfig [ eraName, "query", "pool-state"
, "--stake-pool-id", T.unpack stakePoolId ]
, "--stake-pool-id", stakePoolId ]
-- to a file
let stakePoolsOutFile = work </> "stake-distribution-out.json"
H.noteM_ $ execCli' execConfig [ eraName, "query", "stake-distribution"
Expand Down Expand Up @@ -244,7 +239,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
fileQueryAmount <- H.evalMaybe $ fileQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number

-- Query individual SPO using SPOs bech32 of key and compare to previous result
delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work spoKey
delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work spoKey
keyQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution"
, "--spo-verification-key", T.unpack $ serialiseToBech32 delegatorVKey
]
Expand Down Expand Up @@ -449,6 +444,10 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
-- TODO @cardano-cli team
pure ()

TestQueryEraHistoryCmd -> do
-- TODO @cardano-cli team
pure ()

where
-- | Wait for the part of the epoch when futurePParams are known
waitForFuturePParamsToStabilise
Expand Down Expand Up @@ -482,13 +481,19 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
minSlotInThisEpochToWaitTo = firstSlotOfEpoch + slotsInEpochToWaitOut + 1
in slotNo >= minSlotInThisEpochToWaitTo

readVerificationKeyFromFile :: (HasCallStack, MonadIO m, MonadCatch m, MonadTest m, HasTextEnvelope (VerificationKey keyrole), SerialiseAsBech32 (VerificationKey keyrole))
=> AsType keyrole
-> FilePath
readVerificationKeyFromFile
:: ( HasCallStack
, MonadIO m
, MonadCatch m
, MonadTest m
, HasTextEnvelope (VerificationKey keyrole)
, SerialiseAsBech32 (VerificationKey keyrole)
)
=> FilePath
-> File content direction
-> m (VerificationKey keyrole)
readVerificationKeyFromFile asKey work =
H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile asKey . VerificationKeyFilePath . File . (work </>) . unFile
readVerificationKeyFromFile work =
H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile . VerificationKeyFilePath . File . (work </>) . unFile

_verificationStakeKeyToStakeAddress :: Int -> VerificationKey StakeKey -> StakeAddress
_verificationStakeKeyToStakeAddress testnetMagic delegatorVKey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te

let
sbe = ShelleyBasedEraConway
txEra = AsConwayEra
era = toCardanoEra sbe
cEra = AnyCardanoEra era
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
Expand Down Expand Up @@ -93,8 +92,8 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
, "--out-file", txbodyFp
]
cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp
apiTx <- H.evalEither $ deserialiseFromTextEnvelope (AsTx txEra) cddlUnwitnessedTx
let txFee = L.unCoin $ extractTxFee apiTx
apiTx <- H.evalEither $ deserialiseFromTextEnvelope cddlUnwitnessedTx
let txFee = L.unCoin $ extractTxFee sbe apiTx

-- This is the current calculated fee.
-- It's a sanity check to see if anything has
Expand Down Expand Up @@ -133,6 +132,6 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
txOutValue :: TxOut ctx era -> TxOutValue era
txOutValue (TxOut _ v _ _) = v

extractTxFee :: Tx era -> L.Coin
extractTxFee (ShelleyTx sbe ledgerTx) =
extractTxFee :: ShelleyBasedEra era -> Tx era -> L.Coin
extractTxFee _ (ShelleyTx sbe ledgerTx) =
shelleyBasedEraConstraints sbe $ ledgerTx ^. (L.bodyTxL . L.feeTxBodyL)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import qualified Testnet.Process.Cli.DRep as DRep
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.Cli.Transaction (retrieveTransactionId, signTx, submitTx)
import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
import Testnet.Start.Types (GenesisOptions (..), cardanoNumPools)
Expand Down
Loading
Loading