Skip to content

Commit

Permalink
Remove redundant cardano-cli test and add diagnostic output
Browse files Browse the repository at this point in the history
The removed test is pointless as it does compare the output of using
cardano-api with using cardano-cli. We do not care whether those are
consistent, but rather that the output matches our expectations.
  • Loading branch information
ch1bo committed Jan 3, 2024
1 parent af3f4ab commit a1ac9d1
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
module Test.Hydra.Cluster.CardanoCliSpec where

import Hydra.Prelude hiding (toString)
import Hydra.Prelude
import Test.Hydra.Prelude

import Cardano.Ledger.Core (PParams)
import CardanoClient (RunningNode (..))
import CardanoNode (withCardanoNodeDevnet)
import Control.Lens ((^?))
import Data.Aeson (eitherDecode', encode, encodeFile)
import Data.Aeson (eitherDecode', encodeFile)
import Data.Aeson.Lens (key, _String)
import Data.ByteString.Lazy.Char8 (pack)
import Hydra.API.HTTPServer (DraftCommitTxResponse (DraftCommitTxResponse))
import Hydra.Cardano.Api (LedgerEra, Tx, unFile, unNetworkMagic)
import Hydra.Cardano.Api.Prelude (NetworkId (Testnet))
import Hydra.Logging (showLogsOnFailure)
import Hydra.Prelude (toString)
import System.Exit (ExitCode (..))
import System.FilePath ((</>))
import System.Process (proc, readCreateProcessWithExitCode, readProcess)
Expand All @@ -40,26 +39,23 @@ spec =
readProcess "cardano-cli" ["--version"] "" >>= (`shouldContain` "8.17.0.0")

around (showLogsOnFailure "CardanoCliSpec") $ do
it "query PParams using cardano-node and check JSON roundtrip" $ \tracer ->
withTempDir "queryProtocolParameters" $ \tmpDir ->
withCardanoNodeDevnet tracer tmpDir $ \RunningNode{pparams} ->
case eitherDecode' (encode pparams) :: Either String (PParams LedgerEra) of
Left e -> expectationFailure e
Right parsedPParams -> pparams `shouldBe` parsedPParams

it "queried ProtocolParameters is compatible with our Json instance" $ \tracer ->
it "query protocol-parameters is compatible with our FromJSON instance" $ \tracer ->
withTempDir "cardano-cli-pparams" $ \tmpDir -> do
withCardanoNodeDevnet tracer tmpDir $ \RunningNode{nodeSocket, networkId, pparams} -> do
case networkId of
Testnet networkId' -> do
(exitCode, output, _errors) <-
readCreateProcessWithExitCode
(cardanoCliQueryPParams (toString $ unFile nodeSocket) (show $ unNetworkMagic networkId')) ""
(cardanoCliQueryPParams (unFile nodeSocket) (show $ unNetworkMagic networkId'))
""
exitCode `shouldBe` ExitSuccess
case eitherDecode' (pack output) :: Either String (PParams LedgerEra) of
Left e -> expectationFailure e
Left e -> failure $ "Failed to decode JSON: " <> e <> "\n" <> output
Right parsedPParams -> parsedPParams `shouldBe` pparams
_ -> expectationFailure "Should only run on Testnet"
_ -> failure "Should only run on Testnet"

it "query protocol-parameters matches our schema" $ \_tracer ->
pendingWith "TODO"
where
cardanoCliSign txFile =
proc
Expand Down

0 comments on commit a1ac9d1

Please sign in to comment.