diff --git a/hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs b/hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs index 23512a1f5d4..130000a69d4 100644 --- a/hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs +++ b/hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs @@ -22,7 +22,7 @@ import Test.QuickCheck (generate) spec :: Spec spec = describe "cardano-cli" $ do - it "cardano-cli can accept a draft commit tx in text-envelope format" $ + it "cardano-cli can accept a draft commit tx" $ withTempDir "hydra-cluster" $ \tmpDir -> do let txFile = tmpDir "tx.raw" draftCommitResponse <- DraftCommitTxResponse <$> generate (arbitrary :: Gen Tx) diff --git a/hydra-node/src/Hydra/Ledger/Cardano.hs b/hydra-node/src/Hydra/Ledger/Cardano.hs index 3c0fd972eea..1fb3242835c 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano.hs @@ -32,7 +32,7 @@ import Codec.CBOR.Decoding qualified as CBOR import Codec.CBOR.Encoding qualified as CBOR import Control.Lens (set) import Control.Monad (foldM) -import Data.Aeson (object, (.:), (.:?), (.=)) +import Data.Aeson (object, (.:), (.=)) import Data.Aeson qualified as Aeson import Data.Aeson.Types (withObject) import Data.ByteString qualified as BS diff --git a/hydra-node/test/Hydra/API/ClientInputSpec.hs b/hydra-node/test/Hydra/API/ClientInputSpec.hs index 3996668863a..1983301d5ee 100644 --- a/hydra-node/test/Hydra/API/ClientInputSpec.hs +++ b/hydra-node/test/Hydra/API/ClientInputSpec.hs @@ -3,9 +3,10 @@ module Hydra.API.ClientInputSpec where import Hydra.Prelude import Test.Hydra.Prelude -import Data.Aeson (Result (..), fromJSON) +import Control.Lens ((^.)) +import Data.Aeson.Lens (key, _String) import Hydra.API.ClientInput (ClientInput) -import Hydra.Cardano.Api (serialiseToTextEnvelope) +import Hydra.Cardano.Api (ShelleyBasedEra (..), deserialiseTxLedgerCddl, serialiseTxLedgerCddl) import Hydra.Ledger.Cardano (Tx) import Hydra.Ledger.Simple (SimpleTx) import Test.Aeson.GenericSpecs ( @@ -13,7 +14,7 @@ import Test.Aeson.GenericSpecs ( defaultSettings, roundtripAndGoldenSpecsWithSettings, ) -import Test.QuickCheck (counterexample, forAll, property) +import Test.QuickCheck (counterexample, forAll, (.&&.), (===)) spec :: Spec spec = parallel $ do @@ -26,11 +27,16 @@ spec = parallel $ do describe "FromJSON (ValidatedTx era)" $ do prop "accepts transactions produced via cardano-cli" $ - forAll (arbitrary @Tx) $ \tx -> - let envelope = toJSON $ serialiseToTextEnvelope (Just "Tx Babbage") tx - in case fromJSON @Tx envelope of - Success{} -> property True - Error e -> counterexample (toString $ toText e) $ property False + forAll arbitrary $ \tx -> do + let transactionCDDL = serialiseTxLedgerCddl ShelleyBasedEraBabbage tx + let transaction = toJSON tx + let deserialisedTx = deserialiseTxLedgerCddl ShelleyBasedEraBabbage transactionCDDL + let getKey txJson k = txJson ^. key k . _String + ( deserialisedTx == Right tx .&&. toJSON transactionCDDL `getKey` "cborHex" === transaction `getKey` "cborHex" + .&&. toJSON transactionCDDL `getKey` "type" === transaction `getKey` "type" + ) + & counterexample ("Transaction JSON: " <> show transaction) + & counterexample ("Transaction CDDL JSON: " <> show (toJSON transactionCDDL)) settings :: Settings settings = diff --git a/hydra-node/test/Hydra/API/HTTPServerSpec.hs b/hydra-node/test/Hydra/API/HTTPServerSpec.hs index 95be609ad9b..f05d64f7d78 100644 --- a/hydra-node/test/Hydra/API/HTTPServerSpec.hs +++ b/hydra-node/test/Hydra/API/HTTPServerSpec.hs @@ -9,8 +9,9 @@ import Data.Aeson.Lens (key, nth) import Hydra.API.HTTPServer (DraftCommitTxRequest (..), DraftCommitTxResponse (..), SubmitTxRequest (..), TransactionSubmitted, httpApp) import Hydra.API.ServerSpec (dummyChainHandle) import Hydra.Cardano.Api ( + ShelleyBasedEra (..), fromLedgerPParams, - serialiseToTextEnvelope, + serialiseTxLedgerCddl, shelleyBasedEra, ) import Hydra.Chain (Chain (draftCommitTx), PostTxError (..)) @@ -77,9 +78,9 @@ spec = do in case fromJSON @(SubmitTxRequest Tx) json of Success{} -> property True Error e -> counterexample (toString $ toText e) $ property False - prop "accepts transaction encoded as TextEnvelope" $ + prop "accepts transaction encoded as Ledger CDDL" $ forAll (arbitrary @Tx) $ \tx -> - let json = toJSON $ serialiseToTextEnvelope Nothing tx + let json = toJSON $ serialiseTxLedgerCddl ShelleyBasedEraBabbage tx in case fromJSON @(SubmitTxRequest Tx) json of Success{} -> property True Error e -> counterexample (toString $ toText e) $ property False