Skip to content

Commit

Permalink
Implement tests for witness creation and assembly of tx body and witness
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 authored and intricate committed Sep 14, 2020
1 parent 4c0a76a commit e44d1a1
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cardano-cli/cardano-cli.cabal
Expand Up @@ -263,8 +263,10 @@ test-suite cardano-cli-golden
Test.Golden.Shelley.TextEnvelope.Tx.TxBody
Test.Golden.Shelley.TextEnvelope.Tx.Witness
Test.Golden.Shelley.TextView.DecodeCbor
Test.Golden.Shelley.Transaction.Assemble
Test.Golden.Shelley.Transaction.Build
Test.Golden.Shelley.Transaction.CalculateMinFee
Test.Golden.Shelley.Transaction.CreateWitness
Test.Golden.Shelley.Transaction.Sign
Test.Golden.Version
Test.OptParse
Expand Down
18 changes: 18 additions & 0 deletions cardano-cli/test/Test/Golden/Shelley.hs
Expand Up @@ -58,9 +58,19 @@ import Test.Golden.Shelley.TextEnvelope.Keys.PaymentKeys (golden_shell
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)
import Test.Golden.Shelley.Transaction.Build (golden_shelleyTransactionBuild)
import Test.Golden.Shelley.Transaction.CalculateMinFee
(golden_shelleyTransactionCalculateMinFee)
import Test.Golden.Shelley.Transaction.CreateWitness
(golden_shelleyTransactionAllMultiSigWitness,
golden_shelleyTransactionAnyMultiSigWitness,
golden_shelleyTransactionAtLeastMultiSigWitness,
golden_shelleyTransactionSigningKeyWitness)
import Test.Golden.Shelley.Transaction.Sign (golden_shelleyTransactionSign)

import Test.Golden.Shelley.TextEnvelope.Tx.Tx (golden_shelleyTx)
Expand Down Expand Up @@ -140,4 +150,12 @@ 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)
]
6 changes: 3 additions & 3 deletions cardano-cli/test/Test/Golden/Shelley/MultiSig/Address.hs
Expand Up @@ -17,7 +17,7 @@ golden_shelleyAllMultiSigAddressBuild = propertyOnce . moduleWorkspace "tmp" $ \
allMultiSigFp <- noteInputFile "test/data/golden/shelley/multisig/scripts/all"

allMultiSigAddress <- execCardanoCLI
[ "shelley", "address", "build-script"
[ "shelley", "address", "build-multisig"
, "--script-file", allMultiSigFp
, "--mainnet"
]
Expand All @@ -33,7 +33,7 @@ golden_shelleyAnyMultiSigAddressBuild = propertyOnce . moduleWorkspace "tmp" $ \
anyMultiSigFp <- noteInputFile "test/data/golden/shelley/multisig/scripts/any"

anyMultiSigAddress <- execCardanoCLI
[ "shelley", "address", "build-script"
[ "shelley", "address", "build-multisig"
, "--script-file", anyMultiSigFp
, "--mainnet"
]
Expand All @@ -49,7 +49,7 @@ golden_shelleyAtLeastMultiSigAddressBuild = propertyOnce . moduleWorkspace "tmp"
atLeastMultiSigFp <- noteInputFile "test/data/golden/shelley/multisig/scripts/atleast"

atLeastMultiSigAddress <- execCardanoCLI
[ "shelley", "address", "build-script"
[ "shelley", "address", "build-multisig"
, "--script-file", atLeastMultiSigFp
, "--mainnet"
]
Expand Down
73 changes: 73 additions & 0 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/Assemble.hs
@@ -0,0 +1,73 @@
{-# LANGUAGE OverloadedStrings #-}

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

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

{- HLINT ignore "Use camelCase" -}

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

golden_shelleyTransactionAssembleWitness_AllMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AllMultiSig = propertyOnce $ 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
[ "shelley","transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", allScriptWitnessFile
, "--out-file", allWitnessTx
]

assertFileOccurences 1 "TxSignedShelley" allWitnessTx

golden_shelleyTransactionAssembleWitness_AnyMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AnyMultiSig = propertyOnce $ 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
[ "shelley","transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", anyScriptWitnessFile
, "--out-file", anyWitnessTx
]

assertFileOccurences 1 "TxSignedShelley" anyWitnessTx

golden_shelleyTransactionAssembleWitness_AtLeastMultiSig :: Property
golden_shelleyTransactionAssembleWitness_AtLeastMultiSig = propertyOnce $ 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
[ "shelley","transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", atLeastScriptWitnessFile
, "--out-file", atLeastWitnessTx
]

assertFileOccurences 1 "TxSignedShelley" atLeastWitnessTx

golden_shelleyTransactionAssembleWitness_SigningKey :: Property
golden_shelleyTransactionAssembleWitness_SigningKey = propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do
witnessTx <- noteTempFile tempDir "single-signing-key-witness-tx"
txBodyFile <- noteInputFile "test/data/golden/shelley/tx/txbody"
signingKeyWitnessFile <- noteInputFile "test/data/golden/shelley/witnesses/singleSigningKeyWitness"
void $ execCardanoCLI
[ "shelley","transaction","sign-witness"
, "--tx-body-file", txBodyFile
, "--witness-file", signingKeyWitnessFile
, "--witness-file", signingKeyWitnessFile
, "--out-file", witnessTx
]

assertFileOccurences 1 "TxSignedShelley" witnessTx
140 changes: 140 additions & 0 deletions cardano-cli/test/Test/Golden/Shelley/Transaction/CreateWitness.hs
@@ -0,0 +1,140 @@
{-# LANGUAGE OverloadedStrings #-}

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

import Cardano.Prelude
import Prelude (String)

import Hedgehog (Property)
import Test.OptParse


{- HLINT ignore "Use camelCase" -}

txIn :: String
txIn = "2392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053#0"

txOut :: String
txOut = "addr1q94cxl99qvtwunsqqv6g9mgj3zrawtpt4edsgwxkjtwpy5dsezcht90tmwfur7t5hc9fk8hjd3r5vjwec2h8vmk3xh8s7er7t3+100"

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

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

assertFileOccurences 1 "TxUnsignedShelley" txBodyOutFile
assertEndsWithSingleNewline txBodyOutFile


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

assertFileOccurences 1 "TxWitnessShelley" allMultiSigWitnessOutFile
assertEndsWithSingleNewline txBodyOutFile


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

-- Create tx body file
void $ execCardanoCLI
[ "shelley","transaction","build-raw"
, "--tx-in", txIn
, "--tx-out", txOut
, "--ttl", "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
[ "shelley","transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--script-file", anyScriptWitnessFile
, "--mainnet"
, "--out-file", allMultiSigWitnessOutFile
]

assertFileOccurences 1 "TxWitnessShelley" allMultiSigWitnessOutFile
assertEndsWithSingleNewline txBodyOutFile

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

-- Create tx body file
void $ execCardanoCLI
[ "shelley","transaction","build-raw"
, "--tx-in", txIn
, "--tx-out", txOut
, "--ttl", "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
[ "shelley","transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--script-file", atLeastScriptWitnessFile
, "--mainnet"
, "--out-file", atLeastMultiSigWitnessOutFile
]

assertFileOccurences 1 "TxWitnessShelley" atLeastMultiSigWitnessOutFile
assertEndsWithSingleNewline txBodyOutFile

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

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

-- Create all multisig witness
witnessOutFile <- noteTempFile tempDir "signingkey-witness"
signingKeyFile <- noteInputFile "test/data/golden/shelley/keys/payment_keys/signing_key"
void $ execCardanoCLI
[ "shelley","transaction","witness"
, "--tx-body-file", txBodyOutFile
, "--signing-key-file", signingKeyFile
, "--mainnet"
, "--out-file", witnessOutFile
]

assertFileOccurences 1 "TxWitnessShelley" witnessOutFile
assertEndsWithSingleNewline txBodyOutFile
@@ -0,0 +1,5 @@
{
"type": "TxWitnessShelley",
"description": "",
"cborHex": "820282008201888200581ce09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a8200581ca687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb9517568200581c0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d8200581cdd0044a26cf7d4491ecea720fda11afb59d5725b53afa605fdf695e68200581ccf223afe150cc8e89f11edaacbbd55b011ba44fbedef66fbd37d8c9d8200581c372643e7ef4b41fd2649ada30a89d35cb90b7c14cb5de252e6ce6cb78200581caa453dc184c5037d60e3fbbadb023f4a41bac112f249b76be9bb37ad8200581c6b732c60c267bab894854d6dd57a04a94e603fcc4c36274c9ed75952"
}
@@ -0,0 +1,5 @@
{
"type": "TxWitnessShelley",
"description": "",
"cborHex": "820282008202868200581cd92b712d1882c3b0f75b6f677e0b2cbef4fbc8b8121bb9dde324ff098200581c4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b53218200581c3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf88200581cb12e094d1db7c0fba5121f22db193d0060efed8be43654f861bb68ae8200581c9be49d56442b4b8b16cab4e43e238bbdefc6c803d554c82fcd5facc38200581c622be5fab3b5c3f371a50a535e4d3349c942a98cecee93b24e2fd11d"
}
@@ -0,0 +1,5 @@
{
"type": "TxWitnessShelley",
"description": "",
"cborHex": "82028200830302848200581c2f3d4cf10d0471a1db9f2d2907de867968c27bca6272f062cd1c24138200581cf856c0c5839bab22673747d53f1ae9eed84afafb085f086e8e9886148200581cb275b08c999097247f7c17e77007c7010cd19f20cc086ad99d3985388200581c686024aecb5884d73a11b9ae4e63931112ba737e878d74638b78513a"
}
@@ -0,0 +1,5 @@
{
"type": "TxWitnessShelley",
"description": "",
"cborHex": "82008258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea42342758409f69aa4bf41acf78deaffb002c4f36157f3bad7c434a19b1ffe7e7df5f98f629e58503a762e83c1f60e54c9eb7eef9885b16c2b42ce1336914f2df9aa63b1407"
}

0 comments on commit e44d1a1

Please sign in to comment.