Skip to content

Commit

Permalink
Merge pull request #1180 from input-output-hk/cardano-cli-text-envelo…
Browse files Browse the repository at this point in the history
…pe-format

Check if cardano-cli works with DraftCommitTxResponse json output
  • Loading branch information
v0d1ch authored Nov 27, 2023
2 parents 8f4aedc + e607e47 commit bad1bc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ test-suite tests
Test.DirectChainSpec
Test.EndToEndSpec
Test.GeneratorSpec
Test.Hydra.Cluster.CardanoCliSpec
Test.Hydra.Cluster.FaucetSpec
Test.Ledger.Cardano.ConfigurationSpec
Test.LogFilterSpec
Expand Down
45 changes: 45 additions & 0 deletions hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Test.Hydra.Cluster.CardanoCliSpec where

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

import Control.Lens ((^?))
import Data.Aeson (encodeFile)
import Data.Aeson.Lens (key, _String)
import Hydra.API.HTTPServer (DraftCommitTxResponse (DraftCommitTxResponse))
import Hydra.Cardano.Api (Tx)
import System.Exit (ExitCode (..))
import System.FilePath ((</>))
import System.Process (proc, readCreateProcessWithExitCode)
import Test.QuickCheck (generate)

spec :: Spec
spec =
describe "cardano-cli" $
it "cardano-cli can accept a draft commit tx in text-envelope format" $
withTempDir "cardano-cli" $ \tmpDir -> do
let txFile = tmpDir </> "tx.raw"
draftCommitResponse <- DraftCommitTxResponse <$> generate (arbitrary :: Gen Tx)
encodeFile txFile draftCommitResponse

(exitCode, output, _errors) <- readCreateProcessWithExitCode (cardanoCliSign txFile) ""
exitCode `shouldBe` ExitSuccess
output
^? key "type" . _String `shouldSatisfy` \case
Nothing -> False
Just something -> something == "Witnessed Tx BabbageEra"
where
cardanoCliSign txFile =
proc
"cardano-cli"
[ "transaction"
, "sign"
, "--tx-file"
, txFile
, "--signing-key-file"
, "config/credentials/alice.sk"
, "--testnet-magic"
, "42"
, "--out-file"
, "/dev/stdout"
]
1 change: 1 addition & 0 deletions nix/hydra/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ rec {
nativePkgs.hydra-cluster.components.tests.tests
hydra-node
cardano-node.packages.${system}.cardano-node
cardano-node.packages.${system}.cardano-cli
hydra-chain-observer
];
};
Expand Down

0 comments on commit bad1bc1

Please sign in to comment.