Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if cardano-cli works with DraftCommitTxResponse json output #1180

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading