From 7878d68d613d6e0f6ea10789b63b6fabe3e4bfbd Mon Sep 17 00:00:00 2001 From: John Ky Date: Tue, 21 Nov 2023 05:40:42 +1100 Subject: [PATCH 1/5] Delete use of AnyConsensusMode --- cardano-submit-api/src/Cardano/TxSubmit/Types.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs index 834de750f48..901ddbbd42a 100644 --- a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs +++ b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs @@ -16,7 +16,7 @@ module Cardano.TxSubmit.Types , renderTxCmdError ) where -import Cardano.Api (Error (..), TxId, textShow) +import Cardano.Api (AnyCardanoEra, Error (..), TxId, textShow) import Cardano.Api.Pretty import Cardano.Binary (DecoderError) import Data.Aeson (ToJSON (..), Value (..)) @@ -54,6 +54,7 @@ newtype EnvSocketError = CliEnvVarLookup Text deriving (Eq, Show) data TxCmdError = TxCmdSocketEnvError EnvSocketError + | TxCmdEraConsensusModeMismatch !AnyCardanoEra | TxCmdTxReadError !RawCborDecodeError | TxCmdTxSubmitError !Text | TxCmdTxSubmitErrorEraMismatch !EraMismatch @@ -66,6 +67,7 @@ convertJson = String . renderTxSubmitWebApiError renderTxCmdError :: TxCmdError -> Text renderTxCmdError (TxCmdSocketEnvError socketError) = "socket env error " <> textShow socketError +renderTxCmdError (TxCmdEraConsensusModeMismatch era) = "era consensus mode mismatch " <> textShow era renderTxCmdError (TxCmdTxReadError envelopeError) = "transaction read error " <> textShow envelopeError renderTxCmdError (TxCmdTxSubmitError msg) = "transaction submit error " <> msg renderTxCmdError (TxCmdTxSubmitErrorEraMismatch eraMismatch) = "transaction submit era mismatch" <> textShow eraMismatch From 3c29bc52851d80553486c0362ca1297726797c8d Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 9 Dec 2023 23:03:14 +1100 Subject: [PATCH 2/5] ToJSON instances for error types --- cardano-submit-api/cardano-submit-api.cabal | 3 +- .../src/Cardano/TxSubmit/ErrorRender.hs | 21 ------ .../src/Cardano/TxSubmit/Orphans.hs | 20 ++++++ .../src/Cardano/TxSubmit/Types.hs | 65 +++++++++++-------- .../src/Cardano/TxSubmit/Web.hs | 23 +++---- cardano-testnet/cardano-testnet.cabal | 1 + .../Test/SubmitApi/Babbage/Transaction.hs | 11 +++- .../files/golden/tx.failed.response.golden | 1 - .../golden/tx.failed.response.yaml.golden | 21 ++++++ nix/haskell.nix | 2 +- 10 files changed, 102 insertions(+), 66 deletions(-) delete mode 100644 cardano-submit-api/src/Cardano/TxSubmit/ErrorRender.hs create mode 100644 cardano-submit-api/src/Cardano/TxSubmit/Orphans.hs delete mode 100644 cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.golden create mode 100644 cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden diff --git a/cardano-submit-api/cardano-submit-api.cabal b/cardano-submit-api/cardano-submit-api.cabal index 1ade42cb153..18b58389eda 100644 --- a/cardano-submit-api/cardano-submit-api.cabal +++ b/cardano-submit-api/cardano-submit-api.cabal @@ -43,7 +43,6 @@ library , cardano-binary , cardano-cli ^>= 8.18.0.0 , cardano-crypto-class ^>= 2.1.2 - , formatting , http-media , iohk-monitoring , mtl @@ -68,8 +67,8 @@ library other-modules: Cardano.TxSubmit.CLI.Parsers , Cardano.TxSubmit.CLI.Types , Cardano.TxSubmit.Config - , Cardano.TxSubmit.ErrorRender , Cardano.TxSubmit.Metrics + , Cardano.TxSubmit.Orphans , Cardano.TxSubmit.Rest.Parsers , Cardano.TxSubmit.Rest.Types , Cardano.TxSubmit.Rest.Web diff --git a/cardano-submit-api/src/Cardano/TxSubmit/ErrorRender.hs b/cardano-submit-api/src/Cardano/TxSubmit/ErrorRender.hs deleted file mode 100644 index a6dc1537deb..00000000000 --- a/cardano-submit-api/src/Cardano/TxSubmit/ErrorRender.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedStrings #-} - -module Cardano.TxSubmit.ErrorRender - ( renderEraMismatch - ) where - --- This file contains error renders. They should have been defined at a lower level, with the error --- type definitions, but for some reason have not been. --- They will be defined here for now and then moved where they are supposed to be once they --- are working. - -import Data.Text (Text) -import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) - -renderEraMismatch :: EraMismatch -> Text -renderEraMismatch EraMismatch{ledgerEraName, otherEraName} = - "The era of the node and the tx do not match. " <> - "The node is running in the " <> ledgerEraName <> - " era, but the transaction is for the " <> otherEraName <> " era." - diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Orphans.hs b/cardano-submit-api/src/Cardano/TxSubmit/Orphans.hs new file mode 100644 index 00000000000..afcfb0d52f7 --- /dev/null +++ b/cardano-submit-api/src/Cardano/TxSubmit/Orphans.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE StandaloneDeriving #-} + +{-# OPTIONS_GHC -Wno-orphans #-} + +module Cardano.TxSubmit.Orphans + ( + ) where + +import Cardano.Api +import Cardano.Binary (DecoderError) +import Data.Aeson (ToJSON (..)) +import qualified Data.Aeson as Aeson +import Ouroboros.Consensus.Cardano.Block + +instance ToJSON DecoderError where + toJSON = Aeson.String . textShow + +deriving anyclass instance ToJSON EraMismatch diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs index 901ddbbd42a..ee3a34279c6 100644 --- a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs +++ b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs @@ -1,7 +1,11 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeOperators #-} module Cardano.TxSubmit.Types @@ -12,36 +16,39 @@ module Cardano.TxSubmit.Types , EnvSocketError(..) , TxCmdError(..) , RawCborDecodeError(..) - , renderTxSubmitWebApiError , renderTxCmdError ) where -import Cardano.Api (AnyCardanoEra, Error (..), TxId, textShow) +import Cardano.Api (AnyCardanoEra, Error (..), TxId, TxValidationErrorInCardanoMode (..), + textShow) import Cardano.Api.Pretty import Cardano.Binary (DecoderError) -import Data.Aeson (ToJSON (..), Value (..)) +import Cardano.TxSubmit.Orphans () +import Data.Aeson (ToJSON (..), Value (..), (.=)) +import qualified Data.Aeson as Aeson import Data.ByteString.Char8 (ByteString) import Data.Text (Text) -import Formatting (build, sformat) import GHC.Generics (Generic) import Network.HTTP.Media ((//)) -import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) import Servant (Accept (..), JSON, MimeRender (..), MimeUnrender (..), PostAccepted, ReqBody, (:>)) import Servant.API.Generic (ToServantApi, (:-)) import qualified Data.ByteString.Lazy.Char8 as LBS +import qualified Data.Text as T newtype TxSubmitPort = TxSubmitPort Int -- | The errors that the raw CBOR transaction parsing\/decoding functions can return. -- newtype RawCborDecodeError = RawCborDecodeError [DecoderError] - deriving (Eq, Show) + deriving (Eq, Generic, Show) instance Error RawCborDecodeError where prettyError (RawCborDecodeError decodeErrors) = "RawCborDecodeError decode error: " <> pshow (fmap pshow decodeErrors) +deriving anyclass instance ToJSON RawCborDecodeError + -- | An error that can occur in the transaction submission web API. data TxSubmitWebApiError = TxSubmitDecodeHex @@ -50,36 +57,40 @@ data TxSubmitWebApiError | TxSubmitBadTx !Text | TxSubmitFail TxCmdError -newtype EnvSocketError = CliEnvVarLookup Text deriving (Eq, Show) +deriving instance Generic TxSubmitWebApiError + +deriving anyclass instance ToJSON TxSubmitWebApiError + +newtype EnvSocketError = CliEnvVarLookup Text + deriving (Eq, Generic, Show) + +instance ToJSON EnvSocketError where + toJSON (CliEnvVarLookup msg) = Aeson.object + [ "message" .= String msg + ] data TxCmdError = TxCmdSocketEnvError EnvSocketError | TxCmdEraConsensusModeMismatch !AnyCardanoEra | TxCmdTxReadError !RawCborDecodeError - | TxCmdTxSubmitError !Text - | TxCmdTxSubmitErrorEraMismatch !EraMismatch + | TxCmdTxSubmitValidationError !TxValidationErrorInCardanoMode -instance ToJSON TxSubmitWebApiError where - toJSON = convertJson +deriving instance Generic TxCmdError -convertJson :: TxSubmitWebApiError -> Value -convertJson = String . renderTxSubmitWebApiError +deriving anyclass instance ToJSON TxCmdError renderTxCmdError :: TxCmdError -> Text -renderTxCmdError (TxCmdSocketEnvError socketError) = "socket env error " <> textShow socketError -renderTxCmdError (TxCmdEraConsensusModeMismatch era) = "era consensus mode mismatch " <> textShow era -renderTxCmdError (TxCmdTxReadError envelopeError) = "transaction read error " <> textShow envelopeError -renderTxCmdError (TxCmdTxSubmitError msg) = "transaction submit error " <> msg -renderTxCmdError (TxCmdTxSubmitErrorEraMismatch eraMismatch) = "transaction submit era mismatch" <> textShow eraMismatch - -renderTxSubmitWebApiError :: TxSubmitWebApiError -> Text -renderTxSubmitWebApiError st = - case st of - TxSubmitDecodeHex -> "Provided data was hex encoded and this webapi expects raw binary" - TxSubmitEmpty -> "Provided transaction has zero length" - TxSubmitDecodeFail err -> sformat build err - TxSubmitBadTx tt -> mconcat ["Transactions of type '", tt, "' not supported"] - TxSubmitFail err -> renderTxCmdError err +renderTxCmdError = \case + TxCmdSocketEnvError socketError -> + "socket env error " <> textShow socketError + TxCmdEraConsensusModeMismatch era -> + "era consensus mode mismatch " <> textShow era + TxCmdTxReadError envelopeError -> + "transaction read error " <> textShow envelopeError + TxCmdTxSubmitValidationError e -> + case e of + TxValidationErrorInCardanoMode err -> "transaction submit error " <> T.pack (show err) + TxValidationEraMismatch eraMismatch -> "transaction submit era mismatch" <> textShow eraMismatch -- | Servant API which provides access to tx submission webapi type TxSubmitApi = "api" :> ToServantApi TxSubmitApiRecord diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Web.hs b/cardano-submit-api/src/Cardano/TxSubmit/Web.hs index 924badf66ba..895d7f83684 100644 --- a/cardano-submit-api/src/Cardano/TxSubmit/Web.hs +++ b/cardano-submit-api/src/Cardano/TxSubmit/Web.hs @@ -26,14 +26,14 @@ import qualified Cardano.Crypto.Hash.Class as Crypto import Cardano.TxSubmit.Metrics (TxSubmitMetrics (..)) import Cardano.TxSubmit.Rest.Types (WebserverConfig (..), toWarpSettings) import qualified Cardano.TxSubmit.Rest.Web as Web -import Cardano.TxSubmit.Types (EnvSocketError (..), RawCborDecodeError (..), - TxCmdError (TxCmdTxReadError, TxCmdTxSubmitError, TxCmdTxSubmitErrorEraMismatch), - TxSubmitApi, TxSubmitApiRecord (..), TxSubmitWebApiError (TxSubmitFail), - renderTxCmdError) + import Cardano.TxSubmit.Util (logException) import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx +import Cardano.TxSubmit.Types (EnvSocketError (..), RawCborDecodeError (..), + TxCmdError (..), TxSubmitApi, TxSubmitApiRecord (..), + TxSubmitWebApiError (TxSubmitFail), renderTxCmdError) import Control.Applicative (Applicative (pure), (<$>)) import Control.Monad (Functor (fmap), Monad (return), (=<<)) import Control.Monad.Except (ExceptT, MonadError (throwError), runExceptT) @@ -59,17 +59,16 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.IO as T +import qualified Servant +import Servant (Application, Handler, ServerError (..), err400, throwError) +import Servant.API.Generic (toServant) +import Servant.Server.Generic (AsServerT) import System.Environment (lookupEnv) import qualified System.IO as IO import System.IO (IO) import qualified System.Metrics.Prometheus.Metric.Gauge as Gauge import Text.Show (Show (show)) -import qualified Servant -import Servant (Application, Handler, ServerError (..), err400, throwError) -import Servant.API.Generic (toServant) -import Servant.Server.Generic (AsServerT) - runTxSubmitServer :: Trace IO Text -> TxSubmitMetrics @@ -147,10 +146,8 @@ txSubmitPost trace metrics p@(CardanoModeParams cModeParams) networkId socketPat Net.Tx.SubmitSuccess -> do liftIO $ T.putStrLn "Transaction successfully submitted." return $ getTxId (getTxBody tx) - Net.Tx.SubmitFail reason -> - case reason of - TxValidationErrorInCardanoMode err -> left . TxCmdTxSubmitError . T.pack $ show err - TxValidationEraMismatch mismatchErr -> left $ TxCmdTxSubmitErrorEraMismatch mismatchErr + Net.Tx.SubmitFail e -> + left $ TxCmdTxSubmitValidationError e where handle :: ExceptT TxCmdError IO TxId -> Handler TxId handle f = do diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index f6d591abae9..06fd95aa84a 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -207,6 +207,7 @@ test-suite cardano-testnet-test , time , transformers , transformers-except + , yaml ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs index 5ba974db8b0..ba8ab60f63a 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs @@ -43,11 +43,13 @@ import qualified Testnet.Property.Utils as H import Testnet.Runtime import qualified Cardano.Api.Ledger as L +import qualified Data.Aeson as Aeson import qualified Data.Aeson.Lens as Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Lazy as LBS import qualified Data.List as List +import qualified Data.Yaml as Yaml import qualified Hedgehog.Extras.Test.Golden as H import Lens.Micro import Testnet.SubmitApi @@ -93,6 +95,7 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio txbodySignedFp <- H.note $ work "tx.body.signed" txbodySignedBinFp <- H.note $ work "tx.body.signed.bin" txFailedResponseFp <- H.note $ work "tx.failed.response" + txFailedResponseYamlFp <- H.note $ work "tx.failed.response.yaml" void $ execCli' execConfig [ "babbage", "query", "utxo" @@ -190,7 +193,13 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio H.evalIO $ LBS.writeFile txFailedResponseFp $ redactHashLbs $ getResponseBody response - H.diffFileVsGoldenFile txFailedResponseFp "test/cardano-testnet-test/files/golden/tx.failed.response.golden" + v <- H.leftFailM $ H.evalIO $ Aeson.eitherDecodeFileStrict @Aeson.Value txFailedResponseFp + + let opts = Yaml.defaultEncodeOptions + + H.evalIO $ Yaml.encodeFileWith opts txFailedResponseYamlFp v + + H.diffFileVsGoldenFile txFailedResponseYamlFp "test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden" redactHashLbs :: LBS.ByteString -> LBS.ByteString diff --git a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.golden b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.golden deleted file mode 100644 index acae46f5c44..00000000000 --- a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.golden +++ /dev/null @@ -1 +0,0 @@ -"transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue (Coin 0) (MultiAsset (fromList []))) (MaryValue (Coin 300000000000) (MultiAsset (fromList [])))))),UtxowFailure (UtxoFailure (AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn (TxId {unTxId = SafeHash \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}) (TxIx 0)]))))])" \ No newline at end of file diff --git a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden new file mode 100644 index 00000000000..6b37ef39bab --- /dev/null +++ b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden @@ -0,0 +1,21 @@ +contents: + contents: + contents: + era: ShelleyBasedEraBabbage + error: + - contents: + contents: AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue + (Coin 0) (MultiAsset (fromList []))) (MaryValue (Coin 300000000000) (MultiAsset + (fromList [])))) + tag: UtxoFailure + tag: UtxowFailure + - contents: + contents: AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn + (TxId {unTxId = SafeHash "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}) + (TxIx 0)])) + tag: UtxoFailure + tag: UtxowFailure + kind: ShelleyTxValidationError + tag: TxValidationErrorInCardanoMode + tag: TxCmdTxSubmitValidationError +tag: TxSubmitFail diff --git a/nix/haskell.nix b/nix/haskell.nix index ff46a35b966..8b3fbae7b37 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -197,7 +197,7 @@ let "cardano-testnet/test/cardano-testnet-golden/files/golden/mary_node_default_config.json" "cardano-testnet/test/cardano-testnet-golden/files/golden/shelley_node_default_config.json" "cardano-testnet/test/cardano-testnet-golden/files/golden/shelley_node_default_config.json" - "cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.golden" + "cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden" "cardano-testnet/files/data/alonzo/genesis.alonzo.spec.json" "cardano-testnet/files/data/conway/genesis.conway.spec.json" ]; From 1a9b39578e1ea72a2c9400296d1b468866568154 Mon Sep 17 00:00:00 2001 From: John Ky Date: Tue, 12 Dec 2023 18:32:05 +1100 Subject: [PATCH 3/5] Use JSON instead of YAML for the golden file --- cardano-testnet/cardano-testnet.cabal | 2 +- .../Test/SubmitApi/Babbage/Transaction.hs | 12 ++++---- .../golden/tx.failed.response.json.golden | 29 +++++++++++++++++++ .../golden/tx.failed.response.yaml.golden | 21 -------------- nix/haskell.nix | 2 +- 5 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.json.golden delete mode 100644 cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index 06fd95aa84a..7bb06d45927 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -184,6 +184,7 @@ test-suite cardano-testnet-test type: exitcode-stdio-1.0 build-depends: aeson + , aeson-pretty , async , base16-bytestring , bytestring @@ -207,7 +208,6 @@ test-suite cardano-testnet-test , time , transformers , transformers-except - , yaml ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs index ba8ab60f63a..603241e3fa2 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Babbage/Transaction.hs @@ -44,12 +44,12 @@ import Testnet.Runtime import qualified Cardano.Api.Ledger as L import qualified Data.Aeson as Aeson +import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Aeson.Lens as Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Lazy as LBS import qualified Data.List as List -import qualified Data.Yaml as Yaml import qualified Hedgehog.Extras.Test.Golden as H import Lens.Micro import Testnet.SubmitApi @@ -95,7 +95,8 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio txbodySignedFp <- H.note $ work "tx.body.signed" txbodySignedBinFp <- H.note $ work "tx.body.signed.bin" txFailedResponseFp <- H.note $ work "tx.failed.response" - txFailedResponseYamlFp <- H.note $ work "tx.failed.response.yaml" + txFailedResponseYamlFp <- H.note $ work "tx.failed.response.json" + txFailedResponseYamlGoldenFp <- H.note "test/cardano-testnet-test/files/golden/tx.failed.response.json.golden" void $ execCli' execConfig [ "babbage", "query", "utxo" @@ -195,12 +196,9 @@ hprop_transaction = H.integrationRetryWorkspace 0 "submit-api-babbage-transactio v <- H.leftFailM $ H.evalIO $ Aeson.eitherDecodeFileStrict @Aeson.Value txFailedResponseFp - let opts = Yaml.defaultEncodeOptions - - H.evalIO $ Yaml.encodeFileWith opts txFailedResponseYamlFp v - - H.diffFileVsGoldenFile txFailedResponseYamlFp "test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden" + H.evalIO $ LBS.writeFile txFailedResponseYamlFp $ Aeson.encodePretty v + H.diffFileVsGoldenFile txFailedResponseYamlFp txFailedResponseYamlGoldenFp redactHashLbs :: LBS.ByteString -> LBS.ByteString redactHashLbs = id diff --git a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.json.golden b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.json.golden new file mode 100644 index 00000000000..8561163b649 --- /dev/null +++ b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.json.golden @@ -0,0 +1,29 @@ +{ + "contents": { + "contents": { + "contents": { + "era": "ShelleyBasedEraBabbage", + "error": [ + { + "contents": { + "contents": "AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue (Coin 0) (MultiAsset (fromList []))) (MaryValue (Coin 300000000000) (MultiAsset (fromList []))))", + "tag": "UtxoFailure" + }, + "tag": "UtxowFailure" + }, + { + "contents": { + "contents": "AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn (TxId {unTxId = SafeHash \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}) (TxIx 0)]))", + "tag": "UtxoFailure" + }, + "tag": "UtxowFailure" + } + ], + "kind": "ShelleyTxValidationError" + }, + "tag": "TxValidationErrorInCardanoMode" + }, + "tag": "TxCmdTxSubmitValidationError" + }, + "tag": "TxSubmitFail" +} \ No newline at end of file diff --git a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden b/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden deleted file mode 100644 index 6b37ef39bab..00000000000 --- a/cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden +++ /dev/null @@ -1,21 +0,0 @@ -contents: - contents: - contents: - era: ShelleyBasedEraBabbage - error: - - contents: - contents: AlonzoInBabbageUtxoPredFailure (ValueNotConservedUTxO (MaryValue - (Coin 0) (MultiAsset (fromList []))) (MaryValue (Coin 300000000000) (MultiAsset - (fromList [])))) - tag: UtxoFailure - tag: UtxowFailure - - contents: - contents: AlonzoInBabbageUtxoPredFailure (BadInputsUTxO (fromList [TxIn - (TxId {unTxId = SafeHash "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}) - (TxIx 0)])) - tag: UtxoFailure - tag: UtxowFailure - kind: ShelleyTxValidationError - tag: TxValidationErrorInCardanoMode - tag: TxCmdTxSubmitValidationError -tag: TxSubmitFail diff --git a/nix/haskell.nix b/nix/haskell.nix index 8b3fbae7b37..ab144a6aa62 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -197,7 +197,7 @@ let "cardano-testnet/test/cardano-testnet-golden/files/golden/mary_node_default_config.json" "cardano-testnet/test/cardano-testnet-golden/files/golden/shelley_node_default_config.json" "cardano-testnet/test/cardano-testnet-golden/files/golden/shelley_node_default_config.json" - "cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.yaml.golden" + "cardano-testnet/test/cardano-testnet-test/files/golden/tx.failed.response.json.golden" "cardano-testnet/files/data/alonzo/genesis.alonzo.spec.json" "cardano-testnet/files/data/conway/genesis.conway.spec.json" ]; From b5438be053429e4de470a8fedc9af9bb5fc20199 Mon Sep 17 00:00:00 2001 From: John Ky Date: Tue, 12 Dec 2023 18:34:41 +1100 Subject: [PATCH 4/5] Remove unused constructor --- cardano-submit-api/src/Cardano/TxSubmit/Types.hs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs index ee3a34279c6..ed94197b8ec 100644 --- a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs +++ b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs @@ -19,8 +19,7 @@ module Cardano.TxSubmit.Types , renderTxCmdError ) where -import Cardano.Api (AnyCardanoEra, Error (..), TxId, TxValidationErrorInCardanoMode (..), - textShow) +import Cardano.Api (Error (..), TxId, TxValidationErrorInCardanoMode (..), textShow) import Cardano.Api.Pretty import Cardano.Binary (DecoderError) import Cardano.TxSubmit.Orphans () @@ -71,7 +70,6 @@ instance ToJSON EnvSocketError where data TxCmdError = TxCmdSocketEnvError EnvSocketError - | TxCmdEraConsensusModeMismatch !AnyCardanoEra | TxCmdTxReadError !RawCborDecodeError | TxCmdTxSubmitValidationError !TxValidationErrorInCardanoMode @@ -83,8 +81,6 @@ renderTxCmdError :: TxCmdError -> Text renderTxCmdError = \case TxCmdSocketEnvError socketError -> "socket env error " <> textShow socketError - TxCmdEraConsensusModeMismatch era -> - "era consensus mode mismatch " <> textShow era TxCmdTxReadError envelopeError -> "transaction read error " <> textShow envelopeError TxCmdTxSubmitValidationError e -> From b070859e9244219d4c10d4a1989c92f0c731cd85 Mon Sep 17 00:00:00 2001 From: John Ky Date: Thu, 4 Jan 2024 13:07:55 +1100 Subject: [PATCH 5/5] Explicit ToJSON instance for TxSubmitWebApiError --- .../src/Cardano/TxSubmit/Types.hs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs index ed94197b8ec..b39b77b7509 100644 --- a/cardano-submit-api/src/Cardano/TxSubmit/Types.hs +++ b/cardano-submit-api/src/Cardano/TxSubmit/Types.hs @@ -58,7 +58,26 @@ data TxSubmitWebApiError deriving instance Generic TxSubmitWebApiError -deriving anyclass instance ToJSON TxSubmitWebApiError +instance ToJSON TxSubmitWebApiError where + toJSON = \case + TxSubmitDecodeHex -> Aeson.object + [ "tag" .= String "TxSubmitDecodeHex" + ] + TxSubmitEmpty -> Aeson.object + [ "tag" .= String "TxSubmitEmpty" + ] + TxSubmitDecodeFail err -> Aeson.object + [ "tag" .= String "TxSubmitDecodeFail" + , "contents" .= toJSON err + ] + TxSubmitBadTx err -> Aeson.object + [ "tag" .= String "TxSubmitBadTx" + , "contents" .= toJSON err + ] + TxSubmitFail err -> Aeson.object + [ "tag" .= String "TxSubmitFail" + , "contents" .= toJSON err + ] newtype EnvSocketError = CliEnvVarLookup Text deriving (Eq, Generic, Show)