Skip to content

Commit

Permalink
Add unit test for deprecated tx body format
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Sep 24, 2022
1 parent 26ba217 commit 81aa6bb
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 9 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -192,6 +192,7 @@ test-suite cardano-cli-test
, yaml

other-modules: Test.Config.Mainnet
Test.Cli.CliIntermediateFormat
Test.Cli.FilePermissions
Test.Cli.ITN
Test.Cli.JSON
Expand Down
4 changes: 1 addition & 3 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Expand Up @@ -451,9 +451,7 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
inputsAndScriptFiles readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts (TxOutChangeAddress changeAddr) mValue mLowerBound mUpperBound
certFiles withdrawals reqSigners metadataSchema scriptFiles metadataFiles mpparams
mUpdatePropFile mOverrideWits outputOptions = do
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError readEnvSocketPath
let localNodeConnInfo = LocalNodeConnectInfo cModeParams networkId sockPath
consensusMode = consensusModeOnly cModeParams
let consensusMode = consensusModeOnly cModeParams
dummyFee = Just $ Lovelace 0
inputsThatRequireWitnessing = [input | (input,_) <- inputsAndScriptFiles]

Expand Down
53 changes: 53 additions & 0 deletions cardano-cli/test/Test/Cli/CliIntermediateFormat.hs
@@ -0,0 +1,53 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Test.Cli.CliIntermediateFormat
( tests
) where

import Cardano.Prelude
import Hedgehog (Property, discover)
import Test.OptParse

import qualified Hedgehog
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H

{- HLINT ignore "Use camelCase" -}

-- | We test to make sure that we can deserialize a tx body in the intermediate format
prop_backwardsCompatibleCliFormat :: Property
prop_backwardsCompatibleCliFormat = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyFile <- noteInputFile "test/data/golden/babbage/deprecated-cli-format.body"
witness <- noteInputFile "test/data/golden/babbage/tx-key-witness"
initialUtxo1SigningKeyFile <- noteInputFile "test/data/golden/shelley/keys/payment_keys/signing_key"
signedTransactionFile <- noteTempFile tempDir "signed.tx"


void $ execCardanoCLI
[ "transaction","sign"
, "--mainnet"
, "--tx-body-file", txBodyFile
, "--signing-key-file", initialUtxo1SigningKeyFile
, "--tx-file", signedTransactionFile
]

H.assertFileOccurences 1 "Tx BabbageEra" signedTransactionFile
H.assertEndsWithSingleNewline signedTransactionFile

void $ execCardanoCLI
[ "transaction","assemble"
, "--tx-body-file", txBodyFile
, "--witness-file", witness
, "--out-file", signedTransactionFile
]

H.assertFileOccurences 1 "Tx BabbageEra" signedTransactionFile
H.assertEndsWithSingleNewline signedTransactionFile

-- -----------------------------------------------------------------------------

tests :: IO Bool
tests =
Hedgehog.checkParallel $$discover

4 changes: 3 additions & 1 deletion cardano-cli/test/cardano-cli-test.hs
Expand Up @@ -2,6 +2,7 @@ import Cardano.Prelude

import Hedgehog.Main (defaultMain)

import qualified Test.Cli.CliIntermediateFormat
import qualified Test.Cli.FilePermissions
import qualified Test.Cli.ITN
import qualified Test.Cli.JSON
Expand All @@ -16,7 +17,8 @@ import qualified Test.Config.Mainnet
main :: IO ()
main =
defaultMain
[ Test.Cli.FilePermissions.tests
[ Test.Cli.CliIntermediateFormat.tests
, Test.Cli.FilePermissions.tests
, Test.Cli.ITN.tests
, Test.Cli.JSON.tests
, Test.Cli.MultiAssetParsing.tests
Expand Down
@@ -0,0 +1,5 @@
{
"type": "TxBodyBabbage",
"description": "",
"cborHex": "86a3008182582097c7a4b969dbab432c66ac034c023fb5861b73d198d700b55b9818b9bb1c2dba000182a200581d604088059bbeb6add02eecd0c6a2a52c06910f2a6b4ba0029e9fe6ed13011a00989680a20058390076619da7963eaa588252c45e960667a4647eed69135f51f5a10f2888d2c20ac07056fc8899c47d825cefd9dcf5efba150236e043262e2b43011b0000011764f7bd57021a00028c299fff8080f5f6"
}
5 changes: 5 additions & 0 deletions cardano-cli/test/data/golden/babbage/tx-key-witness
@@ -0,0 +1,5 @@
{
"type": "TxWitness BabbageEra",
"description": "",
"cborHex": "8200825820de40a0376a4953d0fd0ea543c0f5317269a40258f2986153f6304494b430eaab58403d6fcac7d92c75d564b88415c0df07e6442db08049abfeb11b58d1084db82a3480fdb6aa4cb34564b0dd2abb7e7e7d3acd954d0a2b9145939c80e967e0d5cb07"
}
11 changes: 6 additions & 5 deletions scripts/lite/example-build-cmd.sh
Expand Up @@ -10,8 +10,8 @@ export BASE="${BASE:-.}"
export CARDANO_CLI="${CARDANO_CLI:-cardano-cli}"
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/main.sock}"
export TESTNET_MAGIC="${TESTNET_MAGIC:-42}"
export UTXO_VKEY="${UTXO_VKEY:-example/shelley/utxo-keys/utxo1.vkey}"
export UTXO_SKEY="${UTXO_SKEY:-example/shelley/utxo-keys/utxo1.skey}"
export UTXO_VKEY="${UTXO_VKEY:-example/utxo-keys/utxo1.vkey}"
export UTXO_SKEY="${UTXO_SKEY:-example/utxo-keys/utxo1.skey}"
export RESULT_FILE_TARGET="${RESULT_FILE:-$WORK/target.out}"
export RESULT_FILE_CHANGE="${RESULT_FILE:-$WORK/change.out}"

Expand All @@ -35,19 +35,20 @@ changeaddr=addr_test1qpmxr8d8jcl25kyz2tz9a9sxv7jxglhddyf475045y8j3zxjcg9vquzkljy
targetaddr=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4

$CARDANO_CLI transaction build \
--alonzo-era \
--babbage-era \
--cardano-mode \
--cli-format \
--testnet-magic "$TESTNET_MAGIC" \
--change-address "$changeaddr" \
--tx-in $txin \
--tx-out "$targetaddr+10000000" \
--out-file $WORK/build.body

$CARDANO_CLI transaction sign \
$CARDANO_CLI transaction witness \
--tx-body-file $WORK/build.body \
--testnet-magic "$TESTNET_MAGIC" \
--signing-key-file $UTXO_SKEY \
--out-file $WORK/build.tx
--out-file $WORK/witness.tx

# SUBMIT
$CARDANO_CLI transaction submit --tx-file $WORK/build.tx --testnet-magic "$TESTNET_MAGIC"
Expand Down

0 comments on commit 81aa6bb

Please sign in to comment.