Skip to content

Commit

Permalink
Update cardano-cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Apr 8, 2021
1 parent 96b9792 commit 135dbae
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 218 deletions.
5 changes: 4 additions & 1 deletion cardano-api/src/Cardano/Api/TxBody.hs
Expand Up @@ -91,7 +91,7 @@ module Cardano.Api.TxBody (
fromTxOut,

-- * Data family instances
AsType(AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody),
AsType(AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody, AsMaryTxBody),

-- * Conversion functions
fromByronTxIn,
Expand Down Expand Up @@ -944,6 +944,9 @@ pattern AsShelleyTxBody :: AsType (TxBody ShelleyEra)
pattern AsShelleyTxBody = AsTxBody AsShelleyEra
{-# COMPLETE AsShelleyTxBody #-}

pattern AsMaryTxBody :: AsType (TxBody MaryEra)
pattern AsMaryTxBody = AsTxBody AsMaryEra
{-# COMPLETE AsMaryTxBody #-}

instance IsCardanoEra era => SerialiseAsCBOR (TxBody era) where

Expand Down
5 changes: 4 additions & 1 deletion cardano-cli/test/Test/Cli/Pioneers/Exercise2.hs
Expand Up @@ -35,7 +35,10 @@ prop_createTransaction = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- Create transaction body
void $ execCardanoCLI
[ "transaction", "build-raw"
, "--tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--script-file", "test/data/golden/shelley/multisig/scripts/all"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--script-file", "test/data/golden/shelley/multisig/scripts/all"
, "--tx-out", "addr1v9wmu83pzajplrtpsq6tsqdgwr98x888trpmah2u0ezznsge7del3+100000000"
, "--fee", "1000000"
, "--invalid-hereafter", "500000"
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/Test/Cli/Pioneers/Exercise5.hs
Expand Up @@ -35,7 +35,7 @@ prop_createLegacyZeroTxOutTransaction = propertyOnce . H.moduleWorkspace "tmp" $
-- Create transaction body
void $ execCardanoCLI
[ "transaction", "build-raw"
, "--tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--tx-out", "addr1v9wmu83pzajplrtpsq6tsqdgwr98x888trpmah2u0ezznsge7del3+0"
, "--fee", "1000000"
, "--invalid-hereafter", "500000"
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/test/Test/Cli/Pioneers/Exercise6.hs
Expand Up @@ -35,7 +35,7 @@ prop_createZeroLovelaceTxOutTransaction = propertyOnce . H.moduleWorkspace "tmp"
-- Create transaction body
void $ execCardanoCLI
[ "transaction", "build-raw"
, "--tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--tx-out", "addr1v9wmu83pzajplrtpsq6tsqdgwr98x888trpmah2u0ezznsge7del3 0 lovelace"
, "--fee", "1000000"
, "--invalid-hereafter", "500000"
Expand Down
51 changes: 19 additions & 32 deletions cardano-cli/test/Test/Golden/Shelley.hs
Expand Up @@ -21,62 +21,55 @@ import Test.Golden.Shelley.Genesis.KeyGenGenesis (golden_shelleyGenesi
import Test.Golden.Shelley.Genesis.KeyGenUtxo (golden_shelleyGenesisKeyGenUtxo)
import Test.Golden.Shelley.Genesis.KeyHash (golden_shelleyGenesisKeyHash)
import Test.Golden.Shelley.Key.ConvertCardanoAddressKey
(golden_convertCardanoAddressByronSigningKey,
golden_convertCardanoAddressIcarusSigningKey,
golden_convertCardanoAddressShelleyPaymentSigningKey,
golden_convertCardanoAddressShelleyStakeSigningKey)
(golden_convertCardanoAddressByronSigningKey,
golden_convertCardanoAddressIcarusSigningKey,
golden_convertCardanoAddressShelleyPaymentSigningKey,
golden_convertCardanoAddressShelleyStakeSigningKey)
import Test.Golden.Shelley.Node.IssueOpCert (golden_shelleyNodeIssueOpCert)
import Test.Golden.Shelley.Node.KeyGen (golden_shelleyNodeKeyGen)
import Test.Golden.Shelley.Node.KeyGenKes (golden_shelleyNodeKeyGenKes)
import Test.Golden.Shelley.Node.KeyGenVrf (golden_shelleyNodeKeyGenVrf)
import Test.Golden.Shelley.StakeAddress.Build (golden_shelleyStakeAddressBuild)
import Test.Golden.Shelley.StakeAddress.DeregistrationCertificate
(golden_shelleyStakeAddressDeregistrationCertificate)
(golden_shelleyStakeAddressDeregistrationCertificate)
import Test.Golden.Shelley.StakeAddress.KeyGen (golden_shelleyStakeAddressKeyGen)
import Test.Golden.Shelley.StakeAddress.RegistrationCertificate
(golden_shelleyStakeAddressRegistrationCertificate)
(golden_shelleyStakeAddressRegistrationCertificate)
import Test.Golden.Shelley.StakePool.RegistrationCertificate
(golden_shelleyStakePoolRegistrationCertificate)
(golden_shelleyStakePoolRegistrationCertificate)
import Test.Golden.Shelley.TextEnvelope.Certificates.GenesisKeyDelegationCertificate
(golden_shelleyGenesisKeyDelegationCertificate)
(golden_shelleyGenesisKeyDelegationCertificate)
import Test.Golden.Shelley.TextEnvelope.Certificates.MIRCertificate
(golden_shelleyMIRCertificate)
(golden_shelleyMIRCertificate)
import Test.Golden.Shelley.TextEnvelope.Certificates.OperationalCertificate
(golden_shelleyOperationalCertificate)
(golden_shelleyOperationalCertificate)
import Test.Golden.Shelley.TextEnvelope.Certificates.StakeAddressCertificates
(golden_shelleyStakeAddressCertificates)
(golden_shelleyStakeAddressCertificates)
import Test.Golden.Shelley.TextEnvelope.Certificates.StakePoolCertificates
(golden_shelleyStakePoolCertificates)
(golden_shelleyStakePoolCertificates)

import Test.Golden.Shelley.Metadata.StakePoolMetadata (golden_stakePoolMetadataHash)
import Test.Golden.Shelley.MultiSig.Address (golden_shelleyAllMultiSigAddressBuild,
golden_shelleyAnyMultiSigAddressBuild,
golden_shelleyAtLeastMultiSigAddressBuild)
golden_shelleyAnyMultiSigAddressBuild, golden_shelleyAtLeastMultiSigAddressBuild)
import Test.Golden.Shelley.TextEnvelope.Keys.ExtendedPaymentKeys
(golden_shelleyExtendedPaymentKeys)
(golden_shelleyExtendedPaymentKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.GenesisDelegateKeys
(golden_shelleyGenesisDelegateKeys)
(golden_shelleyGenesisDelegateKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.GenesisKeys (golden_shelleyGenesisKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.GenesisUTxOKeys
(golden_shelleyGenesisUTxOKeys)
(golden_shelleyGenesisUTxOKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.KESKeys (golden_shelleyKESKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.PaymentKeys (golden_shelleyPaymentKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.StakeKeys (golden_shelleyStakeKeys)
import Test.Golden.Shelley.TextEnvelope.Keys.VRFKeys (golden_shelleyVRFKeys)
import Test.Golden.Shelley.TextView.DecodeCbor (golden_shelleyTextViewDecodeCbor)
import Test.Golden.Shelley.Transaction.Assemble
(golden_shelleyTransactionAssembleWitness_AllMultiSig,
golden_shelleyTransactionAssembleWitness_AnyMultiSig,
golden_shelleyTransactionAssembleWitness_AtLeastMultiSig,
golden_shelleyTransactionAssembleWitness_SigningKey)
(golden_shelleyTransactionAssembleWitness_SigningKey)
import Test.Golden.Shelley.Transaction.Build (golden_shelleyTransactionBuild)
import Test.Golden.Shelley.Transaction.CalculateMinFee
(golden_shelleyTransactionCalculateMinFee)
(golden_shelleyTransactionCalculateMinFee)
import Test.Golden.Shelley.Transaction.CreateWitness
(golden_shelleyTransactionAllMultiSigWitness,
golden_shelleyTransactionAnyMultiSigWitness,
golden_shelleyTransactionAtLeastMultiSigWitness,
golden_shelleyTransactionSigningKeyWitness)
(golden_shelleyTransactionSigningKeyWitness)
import Test.Golden.Shelley.Transaction.Sign (golden_shelleyTransactionSign)

import Test.Golden.Shelley.TextEnvelope.Tx.Tx (golden_shelleyTx)
Expand Down Expand Up @@ -166,12 +159,6 @@ multiSigTests =
[ ("golden_shelleyAllMultiSigAddressBuild", golden_shelleyAllMultiSigAddressBuild)
, ("golden_shelleyAnyMultiSigAddressBuild", golden_shelleyAnyMultiSigAddressBuild)
, ("golden_shelleyAtLeastMultiSigAddressBuild", golden_shelleyAtLeastMultiSigAddressBuild)
, ("golden_shelleyTransactionAssembleWitness_AllMultiSig", golden_shelleyTransactionAssembleWitness_AllMultiSig)
, ("golden_shelleyTransactionAssembleWitness_AnyMultiSig", golden_shelleyTransactionAssembleWitness_AnyMultiSig)
, ("golden_shelleyTransactionAssembleWitness_AtLeastMultiSig", golden_shelleyTransactionAssembleWitness_AtLeastMultiSig)
, ("golden_shelleyTransactionAssembleWitness_SigningKey", golden_shelleyTransactionAssembleWitness_SigningKey)
, ("golden_shelleyTransactionAllMultiSigWitness", golden_shelleyTransactionAllMultiSigWitness)
, ("golden_shelleyTransactionAnyMultiSigWitness", golden_shelleyTransactionAnyMultiSigWitness)
, ("golden_shelleyTransactionAtLeastMultiSigWitness", golden_shelleyTransactionAtLeastMultiSigWitness)
, ("golden_shelleyTransactionSigningKeyWitness", golden_shelleyTransactionSigningKeyWitness)
]
2 changes: 1 addition & 1 deletion cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Tx/Tx.hs
Expand Up @@ -39,7 +39,7 @@ golden_shelleyTx = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
void $ execCardanoCLI
[ "transaction", "build-raw"
, "--shelley-era"
, "--tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--tx-out", "addr1v9wmu83pzajplrtpsq6tsqdgwr98x888trpmah2u0ezznsge7del3+100000000"
, "--fee", "1000000"
, "--invalid-hereafter", "500000"
Expand Down
Expand Up @@ -26,15 +26,14 @@ golden_shelleyTxBody = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- Create transaction body
void $ execCardanoCLI
[ "transaction", "build-raw"
, "--shelley-era"
, "--tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "tx-in", "91999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c3#0"
, "--tx-out", "addr1v9wmu83pzajplrtpsq6tsqdgwr98x888trpmah2u0ezznsge7del3+100000000"
, "--fee", "1000000"
, "--invalid-hereafter", "500000"
, "--out-file", transactionBodyFile
]

let txBodyType = textEnvelopeType AsShelleyTxBody
let txBodyType = textEnvelopeType AsMaryTxBody

-- Check the newly created files have not deviated from the
-- golden files
Expand Down
49 changes: 2 additions & 47 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/Assemble.hs
@@ -1,10 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Shelley.Transaction.Assemble
( golden_shelleyTransactionAssembleWitness_AllMultiSig
, golden_shelleyTransactionAssembleWitness_AnyMultiSig
, golden_shelleyTransactionAssembleWitness_AtLeastMultiSig
, golden_shelleyTransactionAssembleWitness_SigningKey
( golden_shelleyTransactionAssembleWitness_SigningKey
) where

import Cardano.Prelude
Expand All @@ -18,48 +15,6 @@ import qualified Hedgehog.Extras.Test.File as H

-- Check that we can assemble a txbody and a tx witness to form a transaction

golden_shelleyTransactionAssembleWitness_AllMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AllMultiSig = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
allWitnessTx <- noteTempFile tempDir "all-witness-tx"
txBodyFile <- noteInputFile "test/data/golden/shelley/tx/txbody"
allScriptWitnessFile <- noteInputFile "test/data/golden/shelley/witnesses/allScriptWitness"
void $ execCardanoCLI
[ "transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", allScriptWitnessFile
, "--out-file", allWitnessTx
]

H.assertFileOccurences 1 "TxSignedShelley" allWitnessTx

golden_shelleyTransactionAssembleWitness_AnyMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AnyMultiSig = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
anyWitnessTx <- noteTempFile tempDir "any-witness-tx"
txBodyFile <- noteInputFile "test/data/golden/shelley/tx/txbody"
anyScriptWitnessFile <- noteInputFile "test/data/golden/shelley/witnesses/anyScriptWitness"
void $ execCardanoCLI
[ "transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", anyScriptWitnessFile
, "--out-file", anyWitnessTx
]

H.assertFileOccurences 1 "TxSignedShelley" anyWitnessTx

golden_shelleyTransactionAssembleWitness_AtLeastMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AtLeastMultiSig = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
atLeastWitnessTx <- noteTempFile tempDir "atLeast-witness-tx"
txBodyFile <- noteInputFile "test/data/golden/shelley/tx/txbody"
atLeastScriptWitnessFile <- noteInputFile "test/data/golden/shelley/witnesses/anyScriptWitness"
void $ execCardanoCLI
[ "transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", atLeastScriptWitnessFile
, "--out-file", atLeastWitnessTx
]

H.assertFileOccurences 1 "TxSignedShelley" atLeastWitnessTx

golden_shelleyTransactionAssembleWitness_SigningKey :: Property
golden_shelleyTransactionAssembleWitness_SigningKey = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
witnessTx <- noteTempFile tempDir "single-signing-key-witness-tx"
Expand All @@ -73,4 +28,4 @@ golden_shelleyTransactionAssembleWitness_SigningKey = propertyOnce $ H.moduleWor
, "--out-file", witnessTx
]

H.assertFileOccurences 1 "TxSignedShelley" witnessTx
H.assertFileOccurences 1 "Tx MaryEra" witnessTx
6 changes: 2 additions & 4 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/Build.hs
Expand Up @@ -25,14 +25,12 @@ golden_shelleyTransactionBuild = propertyOnce $ H.moduleWorkspace "tmp" $ \tempD

void $ execCardanoCLI
[ "transaction","build-raw"
, "--shelley-era"
, "--tx-in", txIn
, "tx-in", txIn
, "--tx-out", txOut
, "--invalid-hereafter", "60"
, "--fee", "12"
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "TxUnsignedShelley" txBodyOutFile
H.assertFileOccurences 1 "TxBodyMary" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
Expand Up @@ -16,7 +16,7 @@ import qualified Hedgehog.Extras.Test.File as H
golden_shelleyTransactionCalculateMinFee :: Property
golden_shelleyTransactionCalculateMinFee = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
protocolParamsJsonFile <- noteInputFile "test/data/golden/shelley/transaction-calculate-min-fee/protocol-params.json"
txBodyFile <- noteInputFile "test/data/golden/shelley/transaction-calculate-min-fee/tx-body-file"
txBodyFile <- noteInputFile "test/data/golden/shelley/tx/txbody"
minFeeTxtFile <- noteTempFile tempDir "min-fee.txt"

minFeeTxt <- execCardanoCLI
Expand Down
99 changes: 2 additions & 97 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/CreateWitness.hs
@@ -1,10 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}

module Test.Golden.Shelley.Transaction.CreateWitness
( golden_shelleyTransactionAllMultiSigWitness
, golden_shelleyTransactionAnyMultiSigWitness
, golden_shelleyTransactionAtLeastMultiSigWitness
, golden_shelleyTransactionSigningKeyWitness
( golden_shelleyTransactionSigningKeyWitness
) where

import Cardano.Prelude
Expand All @@ -24,98 +21,6 @@ txIn = "2392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053#0"
txOut :: String
txOut = "addr1q94cxl99qvtwunsqqv6g9mgj3zrawtpt4edsgwxkjtwpy5dsezcht90tmwfur7t5hc9fk8hjd3r5vjwec2h8vmk3xh8s7er7t3+100"

golden_shelleyTransactionAllMultiSigWitness :: Property
golden_shelleyTransactionAllMultiSigWitness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyOutFile <- noteTempFile tempDir "tx-body-out"

-- Create tx body file
void $ execCardanoCLI
[ "transaction","build-raw"
, "--shelley-era"
, "--tx-in", txIn
, "--tx-out", txOut
, "--invalid-hereafter", "60"
, "--fee", "12"
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "TxUnsignedShelley" txBodyOutFile
H.assertEndsWithSingleNewline txBodyOutFile


-- Create all multisig witness
allMultiSigWitnessOutFile <- noteTempFile tempDir "all-multisig-witness"
allScriptWitnessFile <- noteInputFile "test/data/golden/shelley/multisig/scripts/all"
void $ execCardanoCLI
[ "transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--script-file", allScriptWitnessFile
, "--mainnet"
, "--out-file", allMultiSigWitnessOutFile
]

H.assertFileOccurences 1 "TxWitnessShelley" allMultiSigWitnessOutFile
H.assertEndsWithSingleNewline txBodyOutFile


golden_shelleyTransactionAnyMultiSigWitness :: Property
golden_shelleyTransactionAnyMultiSigWitness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyOutFile <- noteTempFile tempDir "tx-body-out"

-- Create tx body file
void $ execCardanoCLI
[ "transaction","build-raw"
, "--shelley-era"
, "--tx-in", txIn
, "--tx-out", txOut
, "--invalid-hereafter", "60"
, "--fee", "12"
, "--tx-body-file", txBodyOutFile
]

-- Create all multisig witness
allMultiSigWitnessOutFile <- noteTempFile tempDir "any-multisig-witness"
anyScriptWitnessFile <- noteInputFile "test/data/golden/shelley/multisig/scripts/any"
void $ execCardanoCLI
[ "transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--script-file", anyScriptWitnessFile
, "--mainnet"
, "--out-file", allMultiSigWitnessOutFile
]

H.assertFileOccurences 1 "TxWitnessShelley" allMultiSigWitnessOutFile
H.assertEndsWithSingleNewline txBodyOutFile

golden_shelleyTransactionAtLeastMultiSigWitness :: Property
golden_shelleyTransactionAtLeastMultiSigWitness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyOutFile <- noteTempFile tempDir "tx-body-out"

-- Create tx body file
void $ execCardanoCLI
[ "transaction","build-raw"
, "--shelley-era"
, "--tx-in", txIn
, "--tx-out", txOut
, "--invalid-hereafter", "60"
, "--fee", "12"
, "--tx-body-file", txBodyOutFile
]

-- Create all multisig witness
atLeastMultiSigWitnessOutFile <- noteTempFile tempDir "atleast-multisig-witness"
atLeastScriptWitnessFile <- noteInputFile "test/data/golden/shelley/multisig/scripts/atleast"
void $ execCardanoCLI
[ "transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--script-file", atLeastScriptWitnessFile
, "--mainnet"
, "--out-file", atLeastMultiSigWitnessOutFile
]

H.assertFileOccurences 1 "TxWitnessShelley" atLeastMultiSigWitnessOutFile
H.assertEndsWithSingleNewline txBodyOutFile

golden_shelleyTransactionSigningKeyWitness :: Property
golden_shelleyTransactionSigningKeyWitness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyOutFile <- noteTempFile tempDir "tx-body-out"
Expand All @@ -124,7 +29,7 @@ golden_shelleyTransactionSigningKeyWitness = propertyOnce $ H.moduleWorkspace "t
void $ execCardanoCLI
[ "transaction","build-raw"
, "--shelley-era"
, "--tx-in", txIn
, "tx-in", txIn
, "--tx-out", txOut
, "--invalid-hereafter", "60"
, "--fee", "12"
Expand Down

0 comments on commit 135dbae

Please sign in to comment.