Skip to content

Commit 5ed7206

Browse files
committed
Add unit test for deprecated tx body format
1 parent fc25683 commit 5ed7206

File tree

6 files changed

+74
-7
lines changed

6 files changed

+74
-7
lines changed

Diff for: cardano-cli/cardano-cli.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ test-suite cardano-cli-test
194194
, yaml
195195

196196
other-modules: Test.Config.Mainnet
197+
Test.Cli.CliIntermediateFormat
197198
Test.Cli.FilePermissions
198199
Test.Cli.ITN
199200
Test.Cli.JSON

Diff for: cardano-cli/test/Test/Cli/CliIntermediateFormat.hs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
4+
module Test.Cli.CliIntermediateFormat
5+
( tests
6+
) where
7+
8+
import Cardano.Prelude
9+
import Hedgehog (Property, discover)
10+
import Test.OptParse
11+
12+
import qualified Hedgehog
13+
import qualified Hedgehog.Extras.Test.Base as H
14+
import qualified Hedgehog.Extras.Test.File as H
15+
16+
{- HLINT ignore "Use camelCase" -}
17+
18+
-- | We test to make sure that we can deserialize a tx body in the intermediate format
19+
prop_backwardsCompatibleCliFormat :: Property
20+
prop_backwardsCompatibleCliFormat = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
21+
txBodyFile <- noteInputFile "test/data/golden/babbage/deprecated-cli-format.body"
22+
witness <- noteInputFile "test/data/golden/babbage/tx-key-witness"
23+
initialUtxo1SigningKeyFile <- noteInputFile "test/data/golden/shelley/keys/payment_keys/signing_key"
24+
signedTransactionFile <- noteTempFile tempDir "signed.tx"
25+
26+
27+
void $ execCardanoCLI
28+
[ "transaction","sign"
29+
, "--mainnet"
30+
, "--tx-body-file", txBodyFile
31+
, "--signing-key-file", initialUtxo1SigningKeyFile
32+
, "--tx-file", signedTransactionFile
33+
]
34+
35+
H.assertFileOccurences 1 "Tx BabbageEra" signedTransactionFile
36+
H.assertEndsWithSingleNewline signedTransactionFile
37+
38+
void $ execCardanoCLI
39+
[ "transaction","assemble"
40+
, "--tx-body-file", txBodyFile
41+
, "--witness-file", witness
42+
, "--out-file", signedTransactionFile
43+
]
44+
45+
H.assertFileOccurences 1 "Tx BabbageEra" signedTransactionFile
46+
H.assertEndsWithSingleNewline signedTransactionFile
47+
48+
-- -----------------------------------------------------------------------------
49+
50+
tests :: IO Bool
51+
tests =
52+
Hedgehog.checkParallel $$discover
53+

Diff for: cardano-cli/test/cardano-cli-test.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Cardano.Prelude
22

33
import Hedgehog.Main (defaultMain)
44

5+
import qualified Test.Cli.CliIntermediateFormat
56
import qualified Test.Cli.FilePermissions
67
import qualified Test.Cli.ITN
78
import qualified Test.Cli.JSON
@@ -16,7 +17,8 @@ import qualified Test.Config.Mainnet
1617
main :: IO ()
1718
main =
1819
defaultMain
19-
[ Test.Cli.FilePermissions.tests
20+
[ Test.Cli.CliIntermediateFormat.tests
21+
, Test.Cli.FilePermissions.tests
2022
, Test.Cli.ITN.tests
2123
, Test.Cli.JSON.tests
2224
, Test.Cli.MultiAssetParsing.tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "TxBodyBabbage",
3+
"description": "",
4+
"cborHex": "86a3008182582097c7a4b969dbab432c66ac034c023fb5861b73d198d700b55b9818b9bb1c2dba000182a200581d604088059bbeb6add02eecd0c6a2a52c06910f2a6b4ba0029e9fe6ed13011a00989680a20058390076619da7963eaa588252c45e960667a4647eed69135f51f5a10f2888d2c20ac07056fc8899c47d825cefd9dcf5efba150236e043262e2b43011b0000011764f7bd57021a00028c299fff8080f5f6"
5+
}

Diff for: cardano-cli/test/data/golden/babbage/tx-key-witness

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "TxWitness BabbageEra",
3+
"description": "",
4+
"cborHex": "8200825820de40a0376a4953d0fd0ea543c0f5317269a40258f2986153f6304494b430eaab58403d6fcac7d92c75d564b88415c0df07e6442db08049abfeb11b58d1084db82a3480fdb6aa4cb34564b0dd2abb7e7e7d3acd954d0a2b9145939c80e967e0d5cb07"
5+
}

Diff for: scripts/lite/example-build-cmd.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export BASE="${BASE:-.}"
1010
export CARDANO_CLI="${CARDANO_CLI:-cardano-cli}"
1111
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/main.sock}"
1212
export TESTNET_MAGIC="${TESTNET_MAGIC:-42}"
13-
export UTXO_VKEY="${UTXO_VKEY:-example/shelley/utxo-keys/utxo1.vkey}"
14-
export UTXO_SKEY="${UTXO_SKEY:-example/shelley/utxo-keys/utxo1.skey}"
13+
export UTXO_VKEY="${UTXO_VKEY:-example/utxo-keys/utxo1.vkey}"
14+
export UTXO_SKEY="${UTXO_SKEY:-example/utxo-keys/utxo1.skey}"
1515
export RESULT_FILE_TARGET="${RESULT_FILE:-$WORK/target.out}"
1616
export RESULT_FILE_CHANGE="${RESULT_FILE:-$WORK/change.out}"
1717

@@ -36,22 +36,23 @@ changeaddr=addr_test1qpmxr8d8jcl25kyz2tz9a9sxv7jxglhddyf475045y8j3zxjcg9vquzkljy
3636
targetaddr=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4
3737

3838
$CARDANO_CLI transaction build \
39-
--alonzo-era \
39+
--babbage-era \
4040
--cardano-mode \
41+
--cli-format \
4142
--testnet-magic "$TESTNET_MAGIC" \
4243
--change-address "$changeaddr" \
4344
--tx-in $txin \
4445
--tx-out "$targetaddr+10000000" \
4546
--out-file $WORK/build.body
4647

47-
$CARDANO_CLI transaction sign \
48+
$CARDANO_CLI transaction witness \
4849
--tx-body-file $WORK/build.body \
4950
--testnet-magic "$TESTNET_MAGIC" \
5051
--signing-key-file $UTXO_SKEY \
51-
--out-file $WORK/build.tx
52+
--out-file $WORK/witness.tx
5253

5354
# SUBMIT
54-
$CARDANO_CLI transaction submit --tx-file $WORK/build.tx --testnet-magic "$TESTNET_MAGIC"
55+
#$CARDANO_CLI transaction submit --tx-file $WORK/build.tx --testnet-magic "$TESTNET_MAGIC"
5556
echo "Pausing for 5 seconds..."
5657
sleep 5
5758

0 commit comments

Comments
 (0)