Skip to content

Commit e9bb755

Browse files
authored
Merge pull request #6204 from IntersectMBO/mgalazyn/chore/remove-redundant-astype-usages
Update cardano-cli. Remove redundant AsType constructors usages.
2 parents 5e653fb + 5f27d9b commit e9bb755

File tree

21 files changed

+95
-91
lines changed

21 files changed

+95
-91
lines changed

bench/plutus-scripts-bench/plutus-scripts-bench.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ library
8282
-- IOG dependencies
8383
--------------------------
8484
build-depends:
85-
, cardano-api ^>=10.14
85+
, cardano-api ^>=10.16
8686
, plutus-ledger-api ^>=1.45
8787
, plutus-tx ^>=1.45
8888
, plutus-tx-plugin ^>=1.45

bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ instance ToJSON (SigningKey PaymentKey) where
6969
instance FromJSON (SigningKey PaymentKey) where
7070
parseJSON o = do
7171
te <- parseJSON o
72-
case deserialiseFromTextEnvelope (AsSigningKey AsPaymentKey) te of
72+
case deserialiseFromTextEnvelope te of
7373
Right k -> pure k
7474
Left err -> fail $ show err
7575

bench/tx-generator/tx-generator.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ library
113113
, attoparsec-aeson
114114
, base16-bytestring
115115
, bytestring
116-
, cardano-api ^>= 10.14
116+
, cardano-api ^>= 10.16
117117
, cardano-binary
118-
, cardano-cli ^>= 10.8
118+
, cardano-cli ^>= 10.9
119119
, cardano-crypto-class
120120
, cardano-crypto-wrapper
121121
, cardano-data

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository cardano-haskell-packages
1414
-- you need to run if you change them
1515
index-state:
1616
, hackage.haskell.org 2025-04-16T18:30:40Z
17-
, cardano-haskell-packages 2025-04-29T14:14:35Z
17+
, cardano-haskell-packages 2025-05-15T08:36:14Z
1818

1919
packages:
2020
cardano-node

cardano-node-chairman/cardano-node-chairman.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ test-suite chairman-tests
9090
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T"
9191

9292
build-tool-depends: cardano-node:cardano-node
93-
, cardano-cli:cardano-cli ^>= 10.8
93+
, cardano-cli:cardano-cli ^>= 10.9
9494
, cardano-node-chairman:cardano-node-chairman

cardano-node/cardano-node.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ library
149149
, async
150150
, base16-bytestring
151151
, bytestring
152-
, cardano-api ^>= 10.14
152+
, cardano-api ^>= 10.16
153153
, cardano-crypto-class
154154
, cardano-crypto-wrapper
155155
, cardano-git-rev ^>=0.2.2

cardano-node/src/Cardano/Node/Protocol/Shelley.hs

+9-10
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ readLeaderCredentialsSingleton
150150
shelleyKESFile = Just kesFile
151151
} = do
152152
vrfSKey <-
153-
firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsVrfKey) (File vrfFile))
153+
firstExceptT FileError (newExceptT $ readFileTextEnvelope (File vrfFile))
154154

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

@@ -172,9 +172,9 @@ opCertKesKeyCheck
172172
-> ExceptT PraosLeaderCredentialsError IO (OperationalCertificate, SigningKey KesKey)
173173
opCertKesKeyCheck kesFile certFile = do
174174
opCert <-
175-
firstExceptT FileError (newExceptT $ readFileTextEnvelope AsOperationalCertificate certFile)
175+
firstExceptT FileError (newExceptT $ readFileTextEnvelope certFile)
176176
kesSKey <-
177-
firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsKesKey) kesFile)
177+
firstExceptT FileError (newExceptT $ readFileTextEnvelope kesFile)
178178
let opCertSpecifiedKesKeyhash = verificationKeyHash $ getHotKey opCert
179179
suppliedKesKeyHash = verificationKeyHash $ getVerificationKey kesSKey
180180
-- Specified KES key in operational certificate should match the one
@@ -201,9 +201,9 @@ readLeaderCredentialsBulk ProtocolFilepaths { shelleyBulkCredsFile = mfp } =
201201
-> ExceptT PraosLeaderCredentialsError IO (ShelleyLeaderCredentials StandardCrypto)
202202
parseShelleyCredentials ShelleyCredentials { scCert, scVrf, scKes } = do
203203
mkPraosLeaderCredentials
204-
<$> parseEnvelope AsOperationalCertificate scCert
205-
<*> parseEnvelope (AsSigningKey AsVrfKey) scVrf
206-
<*> parseEnvelope (AsSigningKey AsKesKey) scKes
204+
<$> parseEnvelope scCert
205+
<*> parseEnvelope scVrf
206+
<*> parseEnvelope scKes
207207

208208
readBulkFile
209209
:: Maybe FilePath
@@ -246,12 +246,11 @@ mkPraosLeaderCredentials
246246

247247
parseEnvelope ::
248248
HasTextEnvelope a
249-
=> AsType a
250-
-> (TextEnvelope, String)
249+
=> (TextEnvelope, String)
251250
-> ExceptT PraosLeaderCredentialsError IO a
252-
parseEnvelope as (te, loc) =
251+
parseEnvelope (te, loc) =
253252
firstExceptT (FileError . Api.FileError loc) . hoistEither $
254-
deserialiseFromTextEnvelope as te
253+
deserialiseFromTextEnvelope te
255254

256255

257256
------------------------------------------------------------------------------

cardano-submit-api/cardano-submit-api.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ library
3939
, aeson
4040
, async
4141
, bytestring
42-
, cardano-api ^>= 10.14
42+
, cardano-api ^>= 10.16
4343
, cardano-binary
44-
, cardano-cli ^>= 10.8
44+
, cardano-cli ^>= 10.9
4545
, cardano-crypto-class ^>= 2.2
4646
, http-media
4747
, iohk-monitoring

cardano-testnet/cardano-testnet.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ library
3535
, aeson-pretty
3636
, ansi-terminal
3737
, bytestring
38-
, cardano-api ^>= 10.14
39-
, cardano-cli:{cardano-cli, cardano-cli-test-lib} ^>= 10.8
38+
, cardano-api ^>= 10.16
39+
, cardano-cli:{cardano-cli, cardano-cli-test-lib} ^>= 10.9
4040
, cardano-crypto-class
4141
, cardano-crypto-wrapper
4242
, cardano-git-rev ^>= 0.2.2

cardano-testnet/src/Testnet/Process/Cli/Transaction.hs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE ScopedTypeVariables #-}
4+
{-# LANGUAGE TypeApplications #-}
35

46
module Testnet.Process.Cli.Transaction
57
( mkSimpleSpendOutputsOnlyTx
@@ -23,21 +25,25 @@ import Prelude
2325

2426
import Control.Monad (void)
2527
import Control.Monad.Catch (MonadCatch)
28+
import qualified Data.Aeson.Lens as A
2629
import Data.List (isInfixOf)
30+
import Data.String (fromString)
2731
import qualified Data.Text as T
2832
import Data.Typeable (Typeable)
33+
import qualified Data.Yaml as A
2934
import GHC.IO.Exception (ExitCode (..))
3035
import GHC.Stack
36+
import Lens.Micro
3137
import System.FilePath ((</>))
3238

33-
import Hedgehog (MonadTest)
34-
import qualified Hedgehog.Extras as H
35-
3639
import Testnet.Components.Query (EpochStateView, findLargestUtxoForPaymentKey)
3740
import Testnet.Process.Run (execCli')
3841
import Testnet.Start.Types (anyEraToString)
3942
import Testnet.Types
4043

44+
import Hedgehog (MonadTest)
45+
import qualified Hedgehog.Extras as H
46+
4147
-- Transaction signing
4248
data VoteFile
4349

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

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Plutus/CostCalculation.hs

+11-11
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ import System.Directory (makeAbsolute)
4040
import System.FilePath ((</>))
4141
import qualified System.Info as SYS
4242

43-
import Hedgehog (Property)
44-
import qualified Hedgehog as H
45-
import qualified Hedgehog.Extras.Test.Base as H
46-
import qualified Hedgehog.Extras.Test.File as H
47-
import qualified Hedgehog.Extras.Test.Golden as H
48-
import qualified Hedgehog.Extras.Test.TestWatchdog as H
49-
5043
import Testnet.Components.Query (findLargestUtxoForPaymentKey, getEpochStateView, getTxIx,
5144
watchEpochStateUpdate)
5245
import Testnet.Process.Cli.Transaction (TxOutAddress (..), mkSpendOutputsOnlyTx,
@@ -57,6 +50,13 @@ import Testnet.Start.Types (eraToString)
5750
import Testnet.Types (PaymentKeyInfo (paymentKeyInfoAddr), paymentKeyInfoPair,
5851
verificationKey)
5952

53+
import Hedgehog (Property)
54+
import qualified Hedgehog as H
55+
import qualified Hedgehog.Extras.Test.Base as H
56+
import qualified Hedgehog.Extras.Test.File as H
57+
import qualified Hedgehog.Extras.Test.Golden as H
58+
import qualified Hedgehog.Extras.Test.TestWatchdog as H
59+
6060
-- @DISABLE_RETRIES=1 cabal run cardano-testnet-test -- -p "/Spec.hs.Spec.Ledger Events.Plutus.Cost Calc.Ref Script/"@
6161
hprop_ref_plutus_cost_calculation :: Property
6262
hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus script" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
@@ -183,7 +183,7 @@ hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus scri
183183
execCli'
184184
execConfig
185185
[ eraName
186-
, "transaction", "calculate-plutus-script-cost"
186+
, "transaction", "calculate-plutus-script-cost", "online"
187187
, "--tx-file", unFile signedUnlockTx
188188
, "--out-file", unFile txCostOutput
189189
]
@@ -199,7 +199,7 @@ hprop_ref_plutus_cost_calculation = integrationRetryWorkspace 2 "ref plutus scri
199199
execCli'
200200
execConfig
201201
[ eraName
202-
, "transaction", "calculate-plutus-script-cost"
202+
, "transaction", "calculate-plutus-script-cost", "online"
203203
, "--tx-file", unFile signedUnlockTx
204204
]
205205

@@ -306,7 +306,7 @@ hprop_included_plutus_cost_calculation = integrationRetryWorkspace 2 "included p
306306
execCli'
307307
execConfig
308308
[ eraName
309-
, "transaction", "calculate-plutus-script-cost"
309+
, "transaction", "calculate-plutus-script-cost", "online"
310310
, "--tx-file", unFile signedIncludedScript
311311
, "--out-file", unFile includedScriptCostOutput
312312
]
@@ -421,7 +421,7 @@ hprop_included_simple_script_cost_calculation = integrationRetryWorkspace 2 "inc
421421
execCli'
422422
execConfig
423423
[ eraName
424-
, "transaction", "calculate-plutus-script-cost"
424+
, "transaction", "calculate-plutus-script-cost", "online"
425425
, "--tx-file", unFile signedScriptUnlock
426426
]
427427

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs

+29-24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{-# LANGUAGE OverloadedStrings #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
1010
{-# LANGUAGE TupleSections #-}
11+
{-# LANGUAGE TypeApplications #-}
1112

1213
module Cardano.Testnet.Test.Cli.Query (
1314
hprop_cli_queries
@@ -36,10 +37,10 @@ import qualified Data.Aeson.Encode.Pretty as Aeson
3637
import qualified Data.Aeson.Key as Aeson
3738
import qualified Data.Aeson.KeyMap as Aeson
3839
import qualified Data.Aeson.Lens as Aeson
39-
import Data.Bifunctor (bimap)
4040
import qualified Data.ByteString.Lazy as LBS
4141
import Data.Default.Class
4242
import qualified Data.Map as Map
43+
import Data.Map.Strict (Map)
4344
import Data.String (IsString (fromString))
4445
import Data.Text (Text)
4546
import qualified Data.Text as T
@@ -128,7 +129,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
128129
-- leadership-schedule
129130
do
130131
let spoKeys = Defaults.defaultSpoKeys 1
131-
spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work $ verificationKey $ poolNodeKeysCold spoKeys
132+
spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work $ verificationKey $ poolNodeKeysCold spoKeys
132133
H.noteM_ $ execCli' execConfig [ eraName, "query", "leadership-schedule"
133134
, "--genesis", shelleyGeneisFile
134135
, "--stake-pool-verification-key", T.unpack $ serialiseToBech32 spoVerificationKey
@@ -179,10 +180,11 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
179180
do
180181
-- to stdout
181182
stakePoolsOut <- execCli' execConfig [ eraName, "query", "stake-pools" ]
182-
H.assertWith stakePoolsOut $ \pools ->
183-
NumPools (length $ lines pools) == nPools
183+
stakePools <- H.noteShowM $ H.leftFail $ Aeson.eitherDecode @[String] $ fromString stakePoolsOut
184+
H.assertWith stakePools $ \pools ->
185+
NumPools (length pools) == nPools
184186
-- Light test of the query's answer, the ids should exist:
185-
forM_ (lines stakePoolsOut) $ \stakePoolId -> do
187+
forM_ stakePools $ \stakePoolId -> do
186188
execCli' execConfig [ eraName, "query", "pool-state"
187189
, "--stake-pool-id", stakePoolId ]
188190
-- to a file
@@ -199,22 +201,15 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
199201
do
200202
-- to stdout
201203
stakeDistrOut <- execCli' execConfig [ eraName, "query", "stake-distribution" ]
202-
-- stake addresses with stake
203-
let stakeAddresses :: [(Text, Text)] =
204-
map
205-
( bimap T.strip T.strip
206-
. T.breakOn " " -- separate address and stake
207-
. T.strip
208-
. fromString )
209-
. drop 2 -- drop header
210-
. lines
211-
$ stakeDistrOut
212-
H.assertWith stakeAddresses $ \sa ->
204+
stakeDistr <- H.leftFail $ Aeson.eitherDecode @(Map String Aeson.Value) $ fromString stakeDistrOut
205+
H.note_ stakeDistrOut
206+
let stakePools = Map.keys stakeDistr
207+
H.assertWith stakePools $ \sa ->
213208
NumPools (length sa) == nPools
214209
-- Light test of the query's answer, the ids should exist:
215-
forM_ stakeAddresses $ \(stakePoolId, _) -> do
210+
forM_ stakePools $ \stakePoolId -> do
216211
execCli' execConfig [ eraName, "query", "pool-state"
217-
, "--stake-pool-id", T.unpack stakePoolId ]
212+
, "--stake-pool-id", stakePoolId ]
218213
-- to a file
219214
let stakePoolsOutFile = work </> "stake-distribution-out.json"
220215
H.noteM_ $ execCli' execConfig [ eraName, "query", "stake-distribution"
@@ -244,7 +239,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
244239
fileQueryAmount <- H.evalMaybe $ fileQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number
245240

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

447+
TestQueryEraHistoryCmd -> do
448+
-- TODO @cardano-cli team
449+
pure ()
450+
452451
where
453452
-- | Wait for the part of the epoch when futurePParams are known
454453
waitForFuturePParamsToStabilise
@@ -482,13 +481,19 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.
482481
minSlotInThisEpochToWaitTo = firstSlotOfEpoch + slotsInEpochToWaitOut + 1
483482
in slotNo >= minSlotInThisEpochToWaitTo
484483

485-
readVerificationKeyFromFile :: (HasCallStack, MonadIO m, MonadCatch m, MonadTest m, HasTextEnvelope (VerificationKey keyrole), SerialiseAsBech32 (VerificationKey keyrole))
486-
=> AsType keyrole
487-
-> FilePath
484+
readVerificationKeyFromFile
485+
:: ( HasCallStack
486+
, MonadIO m
487+
, MonadCatch m
488+
, MonadTest m
489+
, HasTextEnvelope (VerificationKey keyrole)
490+
, SerialiseAsBech32 (VerificationKey keyrole)
491+
)
492+
=> FilePath
488493
-> File content direction
489494
-> m (VerificationKey keyrole)
490-
readVerificationKeyFromFile asKey work =
491-
H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile asKey . VerificationKeyFilePath . File . (work </>) . unFile
495+
readVerificationKeyFromFile work =
496+
H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile . VerificationKeyFilePath . File . (work </>) . unFile
492497

493498
_verificationStakeKeyToStakeAddress :: Int -> VerificationKey StakeKey -> StakeAddress
494499
_verificationStakeKeyToStakeAddress testnetMagic delegatorVKey =

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
5252

5353
let
5454
sbe = ShelleyBasedEraConway
55-
txEra = AsConwayEra
5655
era = toCardanoEra sbe
5756
cEra = AnyCardanoEra era
5857
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
@@ -93,8 +92,8 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
9392
, "--out-file", txbodyFp
9493
]
9594
cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp
96-
apiTx <- H.evalEither $ deserialiseFromTextEnvelope (AsTx txEra) cddlUnwitnessedTx
97-
let txFee = L.unCoin $ extractTxFee apiTx
95+
apiTx <- H.evalEither $ deserialiseFromTextEnvelope cddlUnwitnessedTx
96+
let txFee = L.unCoin $ extractTxFee sbe apiTx
9897

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

136-
extractTxFee :: Tx era -> L.Coin
137-
extractTxFee (ShelleyTx sbe ledgerTx) =
135+
extractTxFee :: ShelleyBasedEra era -> Tx era -> L.Coin
136+
extractTxFee _ (ShelleyTx sbe ledgerTx) =
138137
shelleyBasedEraConstraints sbe $ ledgerTx ^. (L.bodyTxL . L.feeTxBodyL)

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import qualified Testnet.Process.Cli.DRep as DRep
4444
import Testnet.Process.Cli.Keys
4545
import qualified Testnet.Process.Cli.SPO as SPO
4646
import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate)
47-
import Testnet.Process.Cli.Transaction
47+
import Testnet.Process.Cli.Transaction (retrieveTransactionId, signTx, submitTx)
4848
import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig)
4949
import Testnet.Property.Util (integrationWorkspace)
5050
import Testnet.Start.Types (GenesisOptions (..), cardanoNumPools)

0 commit comments

Comments
 (0)