Skip to content

Commit

Permalink
Merge pull request #436 from input-output-hk/smelc/fix-assert-file-oc…
Browse files Browse the repository at this point in the history
…curences-2

Replace usages of assertFileOccurences by comparisons with golden files (2/n)
  • Loading branch information
smelc authored Nov 7, 2023
2 parents 66415ff + eb5fa26 commit dbbc570
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Test.Cardano.CLI.Util

import Hedgehog (Property)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Use camelCase" -}

hprop_golden_shelleyStakePoolRegistrationCertificate :: Property
hprop_golden_shelleyStakePoolRegistrationCertificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
hprop_golden_shelley_stake_pool_registration_certificate :: Property
hprop_golden_shelley_stake_pool_registration_certificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
operatorVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/node-pool/operator.vkey"
vrfVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/node-pool/vrf.vkey"
ownerVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/node-pool/owner.vkey"
Expand All @@ -32,6 +32,6 @@ hprop_golden_shelleyStakePoolRegistrationCertificate = propertyOnce . H.moduleWo
, "--out-file", registrationCertFile
]

H.assertFileOccurences 1 "Stake Pool Registration Certificate" registrationCertFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/reg-certificate.json"

H.assertEndsWithSingleNewline registrationCertFile
H.diffFileVsGoldenFile registrationCertFile goldenFile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Test.Cardano.CLI.Util
import Hedgehog (Property)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Use camelCase" -}

Expand All @@ -21,8 +22,8 @@ txOut = "addr1q94cxl99qvtwunsqqv6g9mgj3zrawtpt4edsgwxkjtwpy5dsezcht90tmwfur7t5hc
txIn :: String
txIn = "2392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053#0"

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

Expand All @@ -34,13 +35,12 @@ hprop_golden_shelleyTransactionBuild =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-1.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile

H.assertEndsWithSingleNewline txBodyOutFile


hprop_golden_shelleyTransactionBuild_CertificateScriptWitnessed :: Property
hprop_golden_shelleyTransactionBuild_CertificateScriptWitnessed =
hprop_golden_shelley_transaction_build_certificate_script_witnessed :: Property
hprop_golden_shelley_transaction_build_certificate_script_witnessed =
propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
let deregcert = "test/cardano-cli-golden/files/input/shelley/certificates/stake_address_deregistration_certificate"
scriptWit = "test/cardano-cli-golden/files/input/shelley/multisig/scripts/any"
Expand All @@ -56,12 +56,11 @@ hprop_golden_shelleyTransactionBuild_CertificateScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-2.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile

hprop_golden_shelleyTransactionBuild_Minting :: Property
hprop_golden_shelleyTransactionBuild_Minting =
hprop_golden_shelley_transaction_build_minting :: Property
hprop_golden_shelley_transaction_build_minting =
propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
let scriptWit = "test/cardano-cli-golden/files/input/shelley/multisig/scripts/any"

Expand All @@ -87,12 +86,11 @@ hprop_golden_shelleyTransactionBuild_Minting =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-3.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile

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

Expand All @@ -110,12 +108,11 @@ hprop_golden_shelleyTransactionBuild_WithdrawalScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-4.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile

H.assertEndsWithSingleNewline txBodyOutFile

hprop_golden_shelleyTransactionBuild_TxInScriptWitnessed :: Property
hprop_golden_shelleyTransactionBuild_TxInScriptWitnessed =
hprop_golden_shelley_transaction_build_txin_script_witnessed :: Property
hprop_golden_shelley_transaction_build_txin_script_witnessed =
propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
let scriptWit = "test/cardano-cli-golden/files/input/shelley/multisig/scripts/any"

Expand All @@ -129,12 +126,11 @@ hprop_golden_shelleyTransactionBuild_TxInScriptWitnessed =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx MaryEra" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-5.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile

hprop_golden_shelleyTransactionBuild_TxOutInlineDatum :: Property
hprop_golden_shelleyTransactionBuild_TxOutInlineDatum =
hprop_golden_shelley_transaction_build_txout_inline_datum :: Property
hprop_golden_shelley_transaction_build_txout_inline_datum =
propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
let datum = "test/cardano-cli-golden/files/input/babbage/42.datum"

Expand All @@ -149,6 +145,5 @@ hprop_golden_shelleyTransactionBuild_TxOutInlineDatum =
, "--tx-body-file", txBodyOutFile
]

H.assertFileOccurences 1 "Tx BabbageEra" txBodyOutFile

H.assertEndsWithSingleNewline txBodyOutFile
goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/build-raw-tx-body-out-6.json"
H.diffFileVsGoldenFile txBodyOutFile goldenFile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Test.Cardano.CLI.Util

import Hedgehog (Property)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Use camelCase" -}

hprop_golden_shelleyTransactionSign :: Property
hprop_golden_shelleyTransactionSign = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
hprop_golden_shelley_transaction_sign :: Property
hprop_golden_shelley_transaction_sign = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do
txBodyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/tx/txbody"
initialUtxo1SigningKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/payment_keys/signing_key"
utxoSigningKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/transaction-sign/utxo.skey"
Expand All @@ -33,8 +33,8 @@ hprop_golden_shelleyTransactionSign = propertyOnce $ H.moduleWorkspace "tmp" $ \
, "--tx-file", signedTransactionFile
]

H.assertFileOccurences 1 "Tx MaryEra" signedTransactionFile
H.assertEndsWithSingleNewline signedTransactionFile
goldenFile1 <- H.note "test/cardano-cli-golden/files/golden/shelley/transaction-sign-1.json"
H.diffFileVsGoldenFile signedTransactionFile goldenFile1

-- Sign for a testnet with a testnet network magic of 11, but use two signing keys

Expand All @@ -47,8 +47,7 @@ hprop_golden_shelleyTransactionSign = propertyOnce $ H.moduleWorkspace "tmp" $ \
, "--tx-file", signedTransactionFile
]

H.assertFileOccurences 1 "Tx MaryEra" signedTransactionFile
H.assertEndsWithSingleNewline signedTransactionFile
H.diffFileVsGoldenFile signedTransactionFile goldenFile1

-- Sign a pool registration transaction.
-- TODO: This needs to use an unsigned tx with a registration certificate
Expand All @@ -63,8 +62,8 @@ hprop_golden_shelleyTransactionSign = propertyOnce $ H.moduleWorkspace "tmp" $ \
, "--tx-file", transactionPoolRegSignedFile
]

H.assertFileOccurences 1 "Tx MaryEra" transactionPoolRegSignedFile
H.assertEndsWithSingleNewline transactionPoolRegSignedFile
goldenFile2 <- H.note "test/cardano-cli-golden/files/golden/shelley/transaction-sign-2.json"
H.diffFileVsGoldenFile transactionPoolRegSignedFile goldenFile2

void $ execCardanoCLI
[ "transaction","sign"
Expand All @@ -74,5 +73,5 @@ hprop_golden_shelleyTransactionSign = propertyOnce $ H.moduleWorkspace "tmp" $ \
, "--tx-file", transactionPoolRegSignedFile
]

H.assertFileOccurences 1 "Tx MaryEra" transactionPoolRegSignedFile
H.assertEndsWithSingleNewline transactionPoolRegSignedFile
goldenFile3 <- H.note "test/cardano-cli-golden/files/golden/shelley/transaction-sign-3.json"
H.diffFileVsGoldenFile transactionPoolRegSignedFile goldenFile3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a300818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181825839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf1864020ca0f6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a400818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181825839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf1864020c048182018200581cd0efd9836e62225a47baf9bedfeaccbb86ba3f49d9edc4ac0aa26df5a101818202868200581cd92b712d1882c3b0f75b6f677e0b2cbef4fbc8b8121bb9dde324ff098200581c4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b53218200581c3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf88200581cb12e094d1db7c0fba5121f22db193d0060efed8be43654f861bb68ae8200581c9be49d56442b4b8b16cab4e43e238bbdefc6c803d554c82fcd5facc38200581c622be5fab3b5c3f371a50a535e4d3349c942a98cecee93b24e2fd11df6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a400818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181825839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf821864a1581c69596718df8203759c0f9e86f3f79d1dd45bc9d34109a4fccc824e02a148657468657265756d1832020c09a1581c69596718df8203759c0f9e86f3f79d1dd45bc9d34109a4fccc824e02a148657468657265756d1832a101818202868200581cd92b712d1882c3b0f75b6f677e0b2cbef4fbc8b8121bb9dde324ff098200581c4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b53218200581c3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf88200581cb12e094d1db7c0fba5121f22db193d0060efed8be43654f861bb68ae8200581c9be49d56442b4b8b16cab4e43e238bbdefc6c803d554c82fcd5facc38200581c622be5fab3b5c3f371a50a535e4d3349c942a98cecee93b24e2fd11df6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a400818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181825839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf1864020c05a1581de181b4245f84593f63c0ff2296930254f77a0690fa9de5f969cac27cb01864a101818202868200581cd92b712d1882c3b0f75b6f677e0b2cbef4fbc8b8121bb9dde324ff098200581c4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b53218200581c3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf88200581cb12e094d1db7c0fba5121f22db193d0060efed8be43654f861bb68ae8200581c9be49d56442b4b8b16cab4e43e238bbdefc6c803d554c82fcd5facc38200581c622be5fab3b5c3f371a50a535e4d3349c942a98cecee93b24e2fd11df6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a300818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181825839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf1864020ca101818202868200581cd92b712d1882c3b0f75b6f677e0b2cbef4fbc8b8121bb9dde324ff098200581c4d780ed1bfc88cbd4da3f48de91fe728c3530d662564bf5a284b53218200581c3a94d6d4e786a3f5d439939cafc0536f6abc324fb8404084d6034bf88200581cb12e094d1db7c0fba5121f22db193d0060efed8be43654f861bb68ae8200581c9be49d56442b4b8b16cab4e43e238bbdefc6c803d554c82fcd5facc38200581c622be5fab3b5c3f371a50a535e4d3349c942a98cecee93b24e2fd11df6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Unwitnessed Tx BabbageEra",
"description": "Ledger Cddl Format",
"cborHex": "84a300818258202392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053000181a3005839016b837ca50316ee4e00033482ed128887d72c2bae5b0438d692dc1251b0c8b17595ebdb93c1f974be0a9b1ef26c474649d9c2ae766ed135cf011864028201d81842182a020ca0f5f6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "CertificateShelley",
"description": "Stake Pool Registration Certificate",
"cborHex": "8a03581c4124a0c2ba8a7ba05824b3df23f706a1c8b3239446ab16709ae85aa158206aa5f600f54659d456dc2628997df23d98f8f85681edd3e6f4a9340cb06b8db70000d81e820001581de0749440f878a5ba2ac3ab03dbdec6ae3ad5c89f06fc9c03161194780381581c749440f878a5ba2ac3ab03dbdec6ae3ad5c89f06fc9c03161194780380f6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Witnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a4008182582091999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c300018182581d615dbe1e2117641f8d618034b801a870ca731ce758c3bedd5c7e4429c11a05f5e100021a000f4240031a0007a120a100818258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea42342758409f69aa4bf41acf78deaffb002c4f36157f3bad7c434a19b1ffe7e7df5f98f629e58503a762e83c1f60e54c9eb7eef9885b16c2b42ce1336914f2df9aa63b1407f6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Witnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a4008182582091999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c300018182581d615dbe1e2117641f8d618034b801a870ca731ce758c3bedd5c7e4429c11a05f5e100021a000f4240031a0007a120a100838258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea42342758409f69aa4bf41acf78deaffb002c4f36157f3bad7c434a19b1ffe7e7df5f98f629e58503a762e83c1f60e54c9eb7eef9885b16c2b42ce1336914f2df9aa63b1407825820bd07998bca8de945482d950a3051f0e4d18afedecbc08d4c99c23f1804f3c8e5584005aa65cbc59470743670086a4a769b6ec66db7f1e587b8be962660a32d94a9d25bb38732e3cea546c9b1bfb86bc2c30b9f0c6319a0a838d06e2597836aa215098258200ef55ad974b238209f51d0eed5ffbb00220a9811c0481eaf127ceb1c525f1eb658401712b3dda8b356303ec1689062c0c829ba3ae05c125f988fd87f4a23c0bc32f6ed7e18b5b4bb882e0fa952b8c982a606e3b611ca34cca938403c69165d78bb07f6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Witnessed Tx MaryEra",
"description": "Ledger Cddl Format",
"cborHex": "83a4008182582091999ea21177b33ebe6b8690724a0c026d410a11ad7521caa350abdafa5394c300018182581d615dbe1e2117641f8d618034b801a870ca731ce758c3bedd5c7e4429c11a05f5e100021a000f4240031a0007a120a100818258202b35e914764560fcf7655523d303d8cf27fc8306b6e86891802feedcfa087715584045b312c96ff0f453a387c49be271ca91ddfd724b81ee4511f1d5c3bab27a6d2705b96426c9d3ad717f1ad116c7b8c3d7bebefb5453931ad7e72a4a09b9373205f6"
}

0 comments on commit dbbc570

Please sign in to comment.