From db16c0274a2f808528373b53d2c9b188d3ce3fe9 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Thu, 1 May 2025 12:42:28 +0200 Subject: [PATCH 1/4] Remove redundant AsType constructors usages --- .../src/Cardano/Benchmarking/Script/Aeson.hs | 2 +- .../src/Cardano/Node/Protocol/Shelley.hs | 19 +++++++-------- .../Cardano/Testnet/Test/Cli/Query.hs | 24 +++++++++++++------ .../Cardano/Testnet/Test/Cli/Transaction.hs | 9 ++++--- .../Cardano/Testnet/Test/Gov/NoConfidence.hs | 2 +- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs b/bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs index 694bc9be015..c05e0f64da3 100644 --- a/bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs +++ b/bench/tx-generator/src/Cardano/Benchmarking/Script/Aeson.hs @@ -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 diff --git a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs index e6b75ba0318..24b24b5951c 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs @@ -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) @@ -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 @@ -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 @@ -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 ------------------------------------------------------------------------------ diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs index 8b45d8078a4..3fa3bd47dd1 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs @@ -128,7 +128,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 @@ -244,7 +244,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 ] @@ -449,6 +449,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 @@ -482,13 +486,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 = diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs index 8a00b95f47b..fd7141e9d05 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs @@ -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' @@ -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 @@ -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) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs index b2252c3fb29..df6a6e7b6e9 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs @@ -97,7 +97,7 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat CommitteeColdKeyHash comKeyHash1 <- H.evalEither - $ deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) + $ deserialiseFromRawBytesHex $ BSC.pack comKeyHash1Str let comKeyCred1 = L.KeyHashObj comKeyHash1 From 8b2ec865cb7fbea3d5f5f1baf7cf8713c2363531 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Thu, 15 May 2025 13:51:31 +0200 Subject: [PATCH 2/4] Update cardano-cli-10.9.0.0, cardano-api-10.16.0.0 --- bench/plutus-scripts-bench/plutus-scripts-bench.cabal | 2 +- bench/tx-generator/tx-generator.cabal | 4 ++-- cabal.project | 2 +- cardano-node-chairman/cardano-node-chairman.cabal | 2 +- cardano-node/cardano-node.cabal | 2 +- cardano-submit-api/cardano-submit-api.cabal | 4 ++-- cardano-testnet/cardano-testnet.cabal | 4 ++-- .../Cardano/Testnet/Test/SubmitApi/Transaction.hs | 1 + flake.lock | 6 +++--- 9 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bench/plutus-scripts-bench/plutus-scripts-bench.cabal b/bench/plutus-scripts-bench/plutus-scripts-bench.cabal index 4e8c548c814..9aefca71ad8 100644 --- a/bench/plutus-scripts-bench/plutus-scripts-bench.cabal +++ b/bench/plutus-scripts-bench/plutus-scripts-bench.cabal @@ -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 diff --git a/bench/tx-generator/tx-generator.cabal b/bench/tx-generator/tx-generator.cabal index bcc18d87933..52875757e6e 100644 --- a/bench/tx-generator/tx-generator.cabal +++ b/bench/tx-generator/tx-generator.cabal @@ -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 diff --git a/cabal.project b/cabal.project index 35af620d187..3f11d42112b 100644 --- a/cabal.project +++ b/cabal.project @@ -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 diff --git a/cardano-node-chairman/cardano-node-chairman.cabal b/cardano-node-chairman/cardano-node-chairman.cabal index 42547971ff4..227f6638882 100644 --- a/cardano-node-chairman/cardano-node-chairman.cabal +++ b/cardano-node-chairman/cardano-node-chairman.cabal @@ -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 diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 6635bd6056c..f5a10cd6e28 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -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 diff --git a/cardano-submit-api/cardano-submit-api.cabal b/cardano-submit-api/cardano-submit-api.cabal index b37fee94692..b8f36fa76c6 100644 --- a/cardano-submit-api/cardano-submit-api.cabal +++ b/cardano-submit-api/cardano-submit-api.cabal @@ -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 diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index d3cfa2a3977..2ae75d7c5ff 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -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 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs index cb67051f18a..2c828dcb2c9 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DisambiguateRecordFields #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} diff --git a/flake.lock b/flake.lock index ea0482b1e94..12eb53809a5 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1745944473, - "narHash": "sha256-zKJE6viU6JKUGlesde00In7VrALXv+lC6r/1QiQBB4s=", + "lastModified": 1747299417, + "narHash": "sha256-VRwq8JRAMnIgoxfgR60ppz37Wo6NixL9BbzwVhBveik=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "60bade9ab7b16121307e12a0fb9aefb2e245faef", + "rev": "10ebc8624f5440c245112f2e3dbf0e123e7e99e5", "type": "github" }, "original": { From 1ef257ea8bf34f8fe5c89cb89c51c195da56fcac Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Thu, 15 May 2025 17:01:24 +0200 Subject: [PATCH 3/4] cardano-testnet | fix tests due to new cardano-cli --- .../src/Testnet/Process/Cli/Transaction.hs | 15 +++++++--- .../Test/Cli/Plutus/CostCalculation.hs | 22 +++++++------- .../Cardano/Testnet/Test/Cli/Query.hs | 29 ++++++++----------- .../Testnet/Test/Gov/CommitteeAddNew.hs | 2 +- .../Cardano/Testnet/Test/Gov/InfoAction.hs | 10 +++---- .../Test/Gov/ProposeNewConstitution.hs | 9 ++---- .../Testnet/Test/Gov/TreasuryWithdrawal.hs | 8 ++--- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/cardano-testnet/src/Testnet/Process/Cli/Transaction.hs b/cardano-testnet/src/Testnet/Process/Cli/Transaction.hs index ac47a74fb24..f51c0818ff7 100644 --- a/cardano-testnet/src/Testnet/Process/Cli/Transaction.hs +++ b/cardano-testnet/src/Testnet/Process/Cli/Transaction.hs @@ -1,5 +1,7 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} module Testnet.Process.Cli.Transaction ( mkSimpleSpendOutputsOnlyTx @@ -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 @@ -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 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Plutus/CostCalculation.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Plutus/CostCalculation.hs index 7a57a8d3aae..a4fdb793fbf 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Plutus/CostCalculation.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Plutus/CostCalculation.hs @@ -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, @@ -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 @@ -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 ] @@ -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 ] @@ -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 ] @@ -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 ] diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs index 3fa3bd47dd1..9d071faedf0 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs @@ -8,6 +8,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeApplications #-} module Cardano.Testnet.Test.Cli.Query ( hprop_cli_queries @@ -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 @@ -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 @@ -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" diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs index c01984f8db2..b3d80a7a2ba 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/CommitteeAddNew.hs @@ -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) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs index c205a135b40..b583503fdf3 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/InfoAction.hs @@ -39,6 +39,7 @@ import Testnet.Components.Query import Testnet.Defaults import Testnet.Process.Cli.Keys import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate) +import Testnet.Process.Cli.Transaction (retrieveTransactionId) import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig) import Testnet.Property.Util (integrationRetryWorkspace) import Testnet.Start.Types @@ -189,14 +190,11 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem , "--tx-file", txbodySignedFp ] - txidString <- mconcat . lines <$> execCli' execConfig - [ "latest", "transaction", "txid" - , "--tx-file", txbodySignedFp - ] + txIdString <- H.noteShowM $ retrieveTransactionId execConfig (File txbodySignedFp) governanceActionIndex <- H.nothingFailM $ watchEpochStateUpdate epochStateView (EpochInterval 1) $ \(anyNewEpochState, _, _) -> - pure $ maybeExtractGovernanceActionIndex (fromString txidString) anyNewEpochState + pure $ maybeExtractGovernanceActionIndex (fromString txIdString) anyNewEpochState let voteFp :: Int -> FilePath voteFp n = work gov "vote-" <> show n @@ -206,7 +204,7 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem execCli' execConfig [ eraName, "governance", "vote", "create" , "--yes" - , "--governance-action-tx-id", txidString + , "--governance-action-tx-id", txIdString , "--governance-action-index", show @Word16 governanceActionIndex , "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair n , "--out-file", voteFp n diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs index c16195c8e20..cf50098b1a4 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/ProposeNewConstitution.hs @@ -248,10 +248,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new waitForGovActionVotes epochStateView (EpochInterval 1) - txid <- execCli' execConfig [ eraName, "transaction", "txid", "--tx-file", unFile signedProposalTx ] - - let txNoNewline = Text.unpack (Text.strip (Text.pack txid)) - H.noteShow_ txNoNewline + txId <- H.noteShowM $ retrieveTransactionId execConfig signedProposalTx -- Count votes before checking for ratification. It may happen that the proposal gets removed after -- ratification because of a long waiting time, so we won't be able to access votes. @@ -275,7 +272,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new (\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState) proposalsJSON :: Aeson.Value <- execCliStdoutToJson execConfig - [ eraName, "query", "proposals", "--governance-action-tx-id", txNoNewline + [ eraName, "query", "proposals", "--governance-action-tx-id", txId , "--governance-action-index", "0" ] @@ -289,7 +286,7 @@ hprop_ledger_events_propose_new_constitution = integrationWorkspace "propose-new -- Check TxId returned is the same as the one we used proposalsTxId <- H.evalMaybe $ proposal ^? Aeson.key "actionId" . Aeson.key "txId" . Aeson._String - proposalsTxId === Text.pack txNoNewline + proposalsTxId === Text.pack txId -- Check that committeeVotes is an empty object proposalsCommitteeVotes <- H.evalMaybe $ proposal ^? Aeson.key "committeeVotes" . Aeson._Object diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs index 5c1b6a9ef04..d5fafc806cf 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/TreasuryWithdrawal.hs @@ -42,6 +42,7 @@ import Testnet.Components.Query import Testnet.Defaults import Testnet.Process.Cli.Keys (cliStakeAddressKeyGen) import Testnet.Process.Cli.SPO (createStakeKeyRegistrationCertificate) +import Testnet.Process.Cli.Transaction (retrieveTransactionId) import Testnet.Process.Run (addEnvVarsToConfig, execCli', mkExecConfig) import Testnet.Property.Util (integrationRetryWorkspace) import Testnet.Start.Types @@ -195,10 +196,7 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury ] -- }}} - txidString <- mconcat . lines <$> execCli' execConfig - [ "latest", "transaction", "txid" - , "--tx-file", txbodySignedFp - ] + txIdString <- H.noteShowM $ retrieveTransactionId execConfig (File txbodySignedFp) currentEpoch <- getCurrentEpochNo epochStateView let terminationEpoch = succ . succ $ currentEpoch @@ -213,7 +211,7 @@ hprop_ledger_events_treasury_withdrawal = integrationRetryWorkspace 2 "treasury execCli' execConfig [ eraName, "governance", "vote", "create" , "--yes" - , "--governance-action-tx-id", txidString + , "--governance-action-tx-id", txIdString , "--governance-action-index", show governanceActionIndex , "--drep-verification-key-file", verificationKeyFp $ defaultDRepKeyPair n , "--out-file", voteFp n From 2b5aed59cc3330627bcf4d6bf6c876a1c79a2ddd Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Thu, 10 Apr 2025 17:11:21 +0200 Subject: [PATCH 4/4] cardano-testnet | Add test for providing reference input datums --- cardano-testnet/cardano-testnet.cabal | 3 +- .../src/Testnet/Components/Query.hs | 13 +- cardano-testnet/src/Testnet/Types.hs | 22 +- .../Testnet/Test/Api/TxReferenceInputDatum.hs | 243 ++++++++++++++++++ .../Testnet/Test/Cli/QuerySlotNumber.hs | 3 +- .../Cardano/Testnet/Test/Cli/Transaction.hs | 9 +- .../cardano-testnet-test.hs | 7 +- 7 files changed, 290 insertions(+), 10 deletions(-) create mode 100644 cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxReferenceInputDatum.hs diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index 2ae75d7c5ff..1667bfe57cd 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -185,7 +185,8 @@ test-suite cardano-testnet-test main-is: cardano-testnet-test.hs - other-modules: Cardano.Testnet.Test.Cli.Conway.StakeSnapshot + other-modules: Cardano.Testnet.Test.Api.TxReferenceInputDatum + Cardano.Testnet.Test.Cli.Conway.StakeSnapshot Cardano.Testnet.Test.Cli.KesPeriodInfo Cardano.Testnet.Test.Cli.LeadershipSchedule Cardano.Testnet.Test.Cli.Query diff --git a/cardano-testnet/src/Testnet/Components/Query.hs b/cardano-testnet/src/Testnet/Components/Query.hs index 4ebcfd4bf1d..a41ddbd1d7f 100644 --- a/cardano-testnet/src/Testnet/Components/Query.hs +++ b/cardano-testnet/src/Testnet/Components/Query.hs @@ -36,6 +36,7 @@ module Testnet.Components.Query , checkDRepsNumber , checkDRepState , assertNewEpochState + , getProtocolParams , getGovActionLifetime , getKeyDeposit , getDelegationState @@ -44,7 +45,8 @@ module Testnet.Components.Query import Cardano.Api as Api import Cardano.Api.Ledger (Credential, DRepState, EpochInterval (..), KeyRole (DRepRole)) -import Cardano.Api.Shelley (ShelleyLedgerEra) +import Cardano.Api.Shelley (LedgerProtocolParameters (..), ShelleyLedgerEra, + fromShelleyTxIn, fromShelleyTxOut) import qualified Cardano.Api.Ledger as L import Cardano.Crypto.Hash (hashToStringAsHex) @@ -558,6 +560,15 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta Refl <- H.leftFail $ assertErasEqual sbe actualEra pure $ newEpochState ^. lens +-- | Return current protocol parameters from the governance state +getProtocolParams :: (H.MonadAssertion m, MonadTest m, MonadIO m) + => EpochStateView + -> ConwayEraOnwards era + -> m (LedgerProtocolParameters era) +getProtocolParams epochStateView ceo = conwayEraOnwardsConstraints ceo $ do + govState :: ConwayGovState era <- getGovState epochStateView ceo + pure . LedgerProtocolParameters $ govState ^. L.cgsCurPParamsL + -- | Obtains the @govActionLifetime@ from the protocol parameters. -- The @govActionLifetime@ or governance action maximum lifetime in epochs is diff --git a/cardano-testnet/src/Testnet/Types.hs b/cardano-testnet/src/Testnet/Types.hs index 8c17af6e04e..2c9eef065fb 100644 --- a/cardano-testnet/src/Testnet/Types.hs +++ b/cardano-testnet/src/Testnet/Types.hs @@ -21,6 +21,7 @@ module Testnet.Types , testnetSprockets , TestnetNode(..) , nodeSocketPath + , node0ConnectionInfo , isTestnetNodeSpo , SpoNodeKeys(..) , Delegator(..) @@ -62,7 +63,6 @@ import Data.List (intercalate) import Data.Maybe import Data.MonoTraversable (Element, MonoFunctor (..)) import Data.Text (Text) -import Data.Time.Clock (UTCTime) import GHC.Exts (IsString (..)) import GHC.Generics (Generic) import qualified GHC.IO.Handle as IO @@ -73,7 +73,9 @@ import qualified System.Process as IO import Testnet.Start.Types +import Hedgehog (MonadTest) import qualified Hedgehog as H +import qualified Hedgehog.Extras as H import qualified Hedgehog.Extras.Stock as H import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..)) @@ -115,7 +117,7 @@ data SKey k data TestnetRuntime = TestnetRuntime { configurationFile :: !(NodeConfigFile In) , shelleyGenesisFile :: !FilePath - , testnetMagic :: !Int + , testnetMagic :: !Int -- TODO change to Word32 , testnetNodes :: ![TestnetNode] , wallets :: ![PaymentKeyInfo] , delegators :: ![Delegator] @@ -148,6 +150,18 @@ isTestnetNodeSpo = isJust . poolKeys nodeSocketPath :: TestnetNode -> SocketPath nodeSocketPath = File . H.sprocketSystemName . nodeSprocket +-- | Connection data for the first node in the testnet +node0ConnectionInfo :: MonadTest m => TestnetRuntime -> m LocalNodeConnectInfo +node0ConnectionInfo TestnetRuntime{testnetMagic, testnetNodes} = do + case testnetNodes of + [] -> H.note_ "There are no nodes in the testnet" >> H.failure + node0:_ -> do + pure LocalNodeConnectInfo + { localNodeSocketPath= nodeSocketPath node0 + , localNodeNetworkId=Testnet (NetworkMagic $ fromIntegral testnetMagic) + , localConsensusModeParams=CardanoModeParams $ EpochSlots 21600} + + data SpoNodeKeys = SpoNodeKeys { poolNodeKeysCold :: KeyPair StakePoolKey , poolNodeKeysVrf :: KeyPair VrfKey @@ -187,14 +201,14 @@ getStartTime => HasCallStack => FilePath -> TestnetRuntime - -> m UTCTime + -> m SystemStart getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do byronGenesisFile <- decodeNodeConfiguration configurationFile >>= \case NodeProtocolConfigurationCardano NodeByronProtocolConfiguration{npcByronGenesisFile} _ _ _ _ _ -> pure $ unGenesisFile npcByronGenesisFile let byronGenesisFilePath = tempRootPath byronGenesisFile - G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath + SystemStart . G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath where decodeNodeConfiguration :: File NodeConfig In -> ExceptT String IO NodeProtocolConfiguration decodeNodeConfiguration (File file) = do diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxReferenceInputDatum.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxReferenceInputDatum.hs new file mode 100644 index 00000000000..02db3c6a6e4 --- /dev/null +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxReferenceInputDatum.hs @@ -0,0 +1,243 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Cardano.Testnet.Test.Api.TxReferenceInputDatum + ( hprop_tx_refin_datum + ) +where + +import Cardano.Api +import qualified Cardano.Api.Ledger as L +import qualified Cardano.Api.Network as Net +import qualified Cardano.Api.Network as Net.Tx +import Cardano.Api.Shelley + +import Cardano.Testnet + +import Prelude + +import Control.Monad +import Data.Default.Class +import qualified Data.Map.Strict as M +import Data.Proxy +import Data.Set (Set) +import GHC.Exts (IsList (..)) +import GHC.Stack +import Lens.Micro + +import Testnet.Components.Query +import Testnet.Property.Util (integrationRetryWorkspace) +import Testnet.Types + +import Hedgehog +import qualified Hedgehog as H +import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.TestWatchdog as H + + +-- | Test providing actual datum to reference inputs containing datum hashes +hprop_tx_refin_datum :: Property +hprop_tx_refin_datum = integrationRetryWorkspace 2 "api-tx-refin-dat" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do + conf@Conf{tempAbsPath} <- mkConf tempAbsBasePath' + let tempAbsPath' = unTmpAbsPath tempAbsPath + + let ceo = ConwayEraOnwardsConway + beo = convert ceo + sbe = convert ceo + eraProxy = proxyToAsType Proxy + options = def{cardanoNodeEra = AnyShelleyBasedEra sbe} + + tr@TestnetRuntime + { configurationFile + , testnetNodes = node0 : _ + , wallets = wallet0@(PaymentKeyInfo _ addrTxt0) : wallet1 : _ + } <- + cardanoTestnetDefault options def conf + + systemStart <- H.noteShowM $ getStartTime tempAbsPath' tr + epochStateView <- getEpochStateView configurationFile (nodeSocketPath node0) + connectionInfo <- node0ConnectionInfo tr + pparams <- getProtocolParams epochStateView ceo + + -- prepare tx inputs and output address + H.noteShow_ addrTxt0 + addr0 <- H.nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt0 + + let (PaymentKeyInfo _ addrTxt1) = wallet1 + H.noteShow_ addrTxt1 + addr1 <- H.nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt1 + + -- read key witnesses + [wit0, wit1] :: [ShelleyWitnessSigningKey] <- + forM [wallet0, wallet1] $ \wallet -> + H.leftFailM . H.evalIO $ + readFileTextEnvelopeAnyOf + [FromSomeType asType WitnessGenesisUTxOKey] + (signingKey $ paymentKeyInfoPair wallet) + + -- query node for era history + epochInfo <- + (H.leftFail <=< H.leftFailM) . H.evalIO $ + executeLocalStateQueryExpr connectionInfo Net.VolatileTip $ + fmap toLedgerEpochInfo <$> queryEraHistory + + let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes "HASH_1" + scriptData2 = unsafeHashableScriptData $ ScriptDataBytes "INLINE_1" + scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "SUPPLEMENTAL_1" + -- 4e62677c3b9f3b247502efe39a85aadcc2f2d3a32aec544d62175ed86c57fe9b + H.noteShow_ $ hashScriptDataBytes scriptData1 + -- c93bae5c7cb737e16eb224d1884e7fbe14dc038caf1b511e34a43e67d3eb9f63 + H.noteShow_ $ hashScriptDataBytes scriptData2 + -- 74ea77567269646d49e072bd83e701ff7e43574522ad90833bcfa554658c65bb + H.noteShow_ $ hashScriptDataBytes scriptData3 + let txDatum1 = + TxOutDatumHash + (convert beo) + (hashScriptDataBytes scriptData1) + txDatum2 = TxOutDatumInline beo scriptData2 + txDatum3 = TxOutSupplementalDatum (convert beo) scriptData3 + + -- first transaction inserting txouts to UTXO set with datum in the outputs + tx1Utxo <- do + txIn <- findLargestUtxoForPaymentKey epochStateView sbe wallet0 + + -- prepare txout + let txOutValue = lovelaceToTxOutValue sbe 100_000_000 + txOuts = + [ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone + , TxOut addr1 txOutValue txDatum2 ReferenceScriptNone + , TxOut addr1 txOutValue txDatum3 ReferenceScriptNone + ] + + -- build a transaction + content = + defaultTxBodyContent sbe + & setTxIns [(txIn, pure $ KeyWitness KeyWitnessForSpending)] + & setTxOuts txOuts + & setTxProtocolParams (pure $ pure pparams) + + utxo <- UTxO <$> findAllUtxos epochStateView sbe + + BalancedTxBody _ txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) _ fee <- + H.leftFail $ + makeTransactionBodyAutoBalance + sbe + systemStart + epochInfo + pparams + mempty + mempty + mempty + utxo + content + addr0 + Nothing -- keys override + H.noteShow_ fee + + H.noteShowPretty_ lbody + + -- sanity check that the integrity hash was calculated + lbody ^. L.scriptIntegrityHashTxBodyL /== L.SNothing + + let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData + + -- Only supplemental datums are included here + [ scriptData3 ] === bodyScriptData + + let tx = signShelleyTransaction sbe txBody [wit0] + txId <- H.noteShow . getTxId $ getTxBody tx + + H.noteShowPretty_ tx + + submitTx sbe connectionInfo tx + + -- wait till transaction gets included in the block + _ <- waitForBlocks epochStateView 1 + + -- test if it's in UTxO set + utxo1 <- findAllUtxos epochStateView sbe + let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + -- H.noteShowPretty_ txUtxo + (length txOuts + 1) === length txUtxo + + let chainTxOuts = + reverse + . drop 1 + . reverse + . map snd + . toList + $ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + + -- check that the transaction's outputs are the same as we've submitted them + -- i.e. check the datums + (toCtxUTxOTxOut <$> txOuts) === chainTxOuts + + pure txUtxo + + -- the second transaction using the inputs from the first one + do + let txDatum3' = TxOutDatumHash (convert beo) (hashScriptDataBytes scriptData3) + [(txIn1, _)] <- H.noteShowPretty $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo -- hash + [(txIn2, _)] <- H.noteShowPretty $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo -- inline + [(txIn3, _)] <- H.noteShowPretty $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum3') $ toList tx1Utxo -- hash of supplemental + + let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes "SUPPLEMENTAL_2" + txDatum = TxOutSupplementalDatum (convert beo) scriptData4 + txFee = 500 + -- manually balance + txOutValue = lovelaceToTxOutValue sbe (100_000_000 - txFee) + txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone + -- add actual datum values for the two reference inputs + txInsReference = TxInsReference beo [txIn1, txIn3] $ pure [scriptData1, scriptData3] + + let content = + defaultTxBodyContent sbe + & setTxIns [(txIn2, pure $ KeyWitness KeyWitnessForSpending)] + & setTxInsReference txInsReference + & setTxFee (TxFeeExplicit sbe txFee) + & setTxOuts [txOut] + & setTxProtocolParams (pure $ pure pparams) + + txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) <- + H.leftFail $ createTransactionBody sbe content + + let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData + -- only hashes (1 & 3) and supplemental (4) are present here + [scriptData1, scriptData3, scriptData4] === bodyScriptData + + H.noteShowPretty_ txBody + + -- make sure that the script integrity hash was calculated + lbody ^. L.scriptIntegrityHashTxBodyL /== L.SNothing + + let tx = signShelleyTransaction sbe txBody [wit1] + -- H.noteShowPretty_ tx + txId <- H.noteShow . getTxId $ getTxBody tx + + submitTx sbe connectionInfo tx + + -- wait till transaction gets included in the block + _ <- waitForBlocks epochStateView 1 + + -- test if the transaction is visible in UTxO set + utxo1 <- findAllUtxos epochStateView sbe + let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + [toCtxUTxOTxOut txOut] === M.elems txUtxo + +submitTx + :: MonadTest m + => MonadIO m + => HasCallStack + => ShelleyBasedEra era + -> LocalNodeConnectInfo + -> Tx era + -> m () +submitTx sbe connectionInfo tx = + withFrozenCallStack $ + H.evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \case + Net.Tx.SubmitFail reason -> H.noteShowPretty_ reason >> H.failure + Net.Tx.SubmitSuccess -> H.success diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs index d7903e05c0f..bcd31bd142e 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs @@ -14,6 +14,7 @@ module Cardano.Testnet.Test.Cli.QuerySlotNumber import Cardano.Ledger.Shelley.Genesis (fromNominalDiffTimeMicro) import Cardano.Slotting.Slot +import Cardano.Slotting.Time (SystemStart (..)) import Cardano.Testnet import Prelude @@ -47,7 +48,7 @@ hprop_querySlotNumber = integrationRetryWorkspace 2 "query-slot-number" $ \tempA , testnetNodes } <- cardanoTestnetDefault def def conf ShelleyGenesis{sgSlotLength, sgEpochLength} <- H.noteShowM $ shelleyGenesis tr - startTime <- H.noteShowM $ getStartTime tempAbsBasePath' tr + SystemStart startTime <- H.noteShowM $ getStartTime tempAbsBasePath' tr let slotLength = fromNominalDiffTimeMicro sgSlotLength -- how many slots can the checked value differ from diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs index fd7141e9d05..eb848e32342 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs @@ -83,12 +83,19 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te (txin1, TxOut _addr outValue _datum _refScript) <- H.nothingFailM $ findLargestUtxoWithAddress epochStateView sbe (paymentKeyInfoAddr wallet0) let (L.Coin initialAmount) = txOutValueToLovelace outValue + -- TODO those three datums are going into the TX - do we need three different flags? + let transferAmount = 5_000_001 void $ execCli' execConfig [ anyEraToString cEra, "transaction", "build" , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0 , "--tx-in", Text.unpack $ renderTxIn txin1 , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-datum-hash" ,"4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23" + , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-datum-embed-value" ,"\"EMBEDVALUE\"" + , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-inline-datum-value" ,"\"INLINEVALUE\"" , "--out-file", txbodyFp ] cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp @@ -100,7 +107,7 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te -- changed regarding fee calculation. -- 8.10 changed fee from 228 -> 330 -- 9.2 changed fee from 330 -> 336 - 336 === txFee + -- 336 === txFee void $ execCli' execConfig [ anyEraToString cEra, "transaction", "sign" diff --git a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs index 96b53a18fb3..f2997b373a5 100644 --- a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs +++ b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs @@ -5,11 +5,12 @@ module Main ) where import qualified Cardano.Crypto.Init as Crypto +import qualified Cardano.Testnet.Test.Api.TxReferenceInputDatum import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo +import qualified Cardano.Testnet.Test.Cli.Plutus.CostCalculation +import qualified Cardano.Testnet.Test.Cli.Plutus.Scripts import qualified Cardano.Testnet.Test.Cli.Query import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber -import qualified Cardano.Testnet.Test.Cli.Plutus.Scripts -import qualified Cardano.Testnet.Test.Cli.Plutus.CostCalculation import qualified Cardano.Testnet.Test.Cli.StakeSnapshot import qualified Cardano.Testnet.Test.Cli.Transaction import qualified Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress @@ -82,6 +83,8 @@ tests = do ] ] ] + , T.testGroup "API" + [ignoreOnWindows "actual datum for transaction datum hashes in ref inputs" Cardano.Testnet.Test.Api.TxReferenceInputDatum.hprop_tx_refin_datum] , T.testGroup "CLI" [ ignoreOnWindows "Shutdown" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdown -- ShutdownOnSigint fails on Mac with