From 4534ec591593d09dde4c8d1fff13d58b22900513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 7 Nov 2023 11:12:19 +0100 Subject: [PATCH 1/5] Shelley/Transaction: goldenize a test --- .../Test/Golden/Shelley/Transaction/CreateWitness.hs | 11 ++++++----- .../files/golden/shelley/witness-out.json | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/witness-out.json diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CreateWitness.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CreateWitness.hs index fc48d92236..36cc1f56db 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CreateWitness.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CreateWitness.hs @@ -8,7 +8,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" -} @@ -18,8 +18,8 @@ txIn = "2392d2b1200b5139fe555c81261697b29a8ccf561c5c783d46e78a479d977053#0" txOut :: String txOut = "addr1q94cxl99qvtwunsqqv6g9mgj3zrawtpt4edsgwxkjtwpy5dsezcht90tmwfur7t5hc9fk8hjd3r5vjwec2h8vmk3xh8s7er7t3+100" -hprop_golden_shelleyTransactionSigningKeyWitness :: Property -hprop_golden_shelleyTransactionSigningKeyWitness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_shelley_transaction_signing_key_witness :: Property +hprop_golden_shelley_transaction_signing_key_witness = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do txBodyOutFile <- noteTempFile tempDir "tx-body-out" -- Create tx body file @@ -35,6 +35,7 @@ hprop_golden_shelleyTransactionSigningKeyWitness = propertyOnce $ H.moduleWorksp -- Create all multisig witness witnessOutFile <- noteTempFile tempDir "signingkey-witness" signingKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/payment_keys/signing_key" + void $ execCardanoCLI [ "transaction","witness" , "--tx-body-file", txBodyOutFile @@ -43,5 +44,5 @@ hprop_golden_shelleyTransactionSigningKeyWitness = propertyOnce $ H.moduleWorksp , "--out-file", witnessOutFile ] - H.assertFileOccurences 1 "TxWitness ShelleyEra" witnessOutFile - H.assertEndsWithSingleNewline txBodyOutFile + goldenFile <- H.note "test/cardano-cli-golden/files/golden/shelley/witness-out.json" + H.diffFileVsGoldenFile witnessOutFile goldenFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/witness-out.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/witness-out.json new file mode 100644 index 0000000000..dc72376a87 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/witness-out.json @@ -0,0 +1,5 @@ +{ + "type": "TxWitness ShelleyEra", + "description": "Key Witness ShelleyEra", + "cborHex": "8258208dc60533b5dfa60a530955a696323a2ef4f14e8bc95a8f84cf6c441fea4234275840a20a2c8b1ffc2151eee3f659fc4076f9859d7d4d073933275470f270128736d231a2fb5e1bc2a6058ef2e58bc98266d192c55d6435ab591ce72cb165a7ec4e03" +} From 076bf9e779fd24de9e9bdcaad16d88b31dc6fd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 7 Nov 2023 11:13:45 +0100 Subject: [PATCH 2/5] Conway/Transaction: use camelCase naming --- .../Test/Golden/Conway/Transaction/Assemble.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Conway/Transaction/Assemble.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Conway/Transaction/Assemble.hs index 2347172e47..9c7848aac2 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Conway/Transaction/Assemble.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Conway/Transaction/Assemble.hs @@ -14,11 +14,12 @@ import qualified Hedgehog.Extras.Test.Golden as H -- Check that we can assemble a txbody and a tx witness to form a transaction -hprop_golden_conwayTransactionAssembleWitness_SigningKey :: Property -hprop_golden_conwayTransactionAssembleWitness_SigningKey = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_conway_transaction_assemble_witness_signing_key :: Property +hprop_golden_conway_transaction_assemble_witness_signing_key = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do witnessTx <- noteTempFile tempDir "single-signing-key-witness-tx" txBodyFile <- noteInputFile "test/cardano-cli-golden/files/input/conway/txbody" signingKeyWitnessFile <- noteInputFile "test/cardano-cli-golden/files/input/conway/singleSigningKeyWitness" + void $ execCardanoCLI [ "conway", "transaction", "assemble" , "--tx-body-file", txBodyFile @@ -28,5 +29,4 @@ hprop_golden_conwayTransactionAssembleWitness_SigningKey = propertyOnce $ H.modu ] goldenFile <- H.note "test/cardano-cli-golden/files/golden/conway/transaction/assemble_out" - H.diffFileVsGoldenFile witnessTx goldenFile \ No newline at end of file From bd50f91a6d1afdd335299c8c21ed71e13c135b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 7 Nov 2023 11:22:43 +0100 Subject: [PATCH 3/5] Shelley/Transaction: make a test more precise (but no new golden file this time) --- .../Golden/Shelley/Transaction/CalculateMinFee.hs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CalculateMinFee.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CalculateMinFee.hs index c0f741dd31..220da1a6f9 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CalculateMinFee.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Transaction/CalculateMinFee.hs @@ -6,16 +6,14 @@ module Test.Golden.Shelley.Transaction.CalculateMinFee 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 as H {- HLINT ignore "Use camelCase" -} -hprop_golden_shelleyTransactionCalculateMinFee :: Property -hprop_golden_shelleyTransactionCalculateMinFee = propertyOnce $ H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_shelley_transaction_calculate_min_fee :: Property +hprop_golden_shelley_transaction_calculate_min_fee = propertyOnce $ do protocolParamsJsonFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/transaction-calculate-min-fee/protocol-params.json" txBodyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/tx/txbody" - minFeeTxtFile <- noteTempFile tempDir "min-fee.txt" minFeeTxt <- execCardanoCLI [ "transaction","calculate-min-fee" @@ -28,8 +26,4 @@ hprop_golden_shelleyTransactionCalculateMinFee = propertyOnce $ H.moduleWorkspac , "--tx-body-file", txBodyFile ] - H.writeFile minFeeTxtFile minFeeTxt - - H.assertFileOccurences 1 "5083100" minFeeTxtFile - H.assertFileLines (== 1) minFeeTxtFile - H.assertEndsWithSingleNewline minFeeTxtFile + H.diff minFeeTxt (==) "5083100 Lovelace\n" \ No newline at end of file From 728dcc097a2afa9f351890b26f582700e1218b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 7 Nov 2023 11:27:14 +0100 Subject: [PATCH 4/5] Shelley/StakeAddress: goldenize a test --- .../StakeAddress/DeregistrationCertificate.hs | 14 +++++++------- .../files/golden/shelley/dereg-cert-1.json | 5 +++++ .../files/golden/shelley/dereg-cert-2.json | 5 +++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-1.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-2.json diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/DeregistrationCertificate.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/DeregistrationCertificate.hs index 1196bbc34c..8afa30d7de 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/DeregistrationCertificate.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/DeregistrationCertificate.hs @@ -9,13 +9,13 @@ 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.Process as H +import qualified Hedgehog.Extras.Test.Golden as H {- HLINT ignore "Use camelCase" -} -hprop_golden_shelleyStakeAddressDeregistrationCertificate :: Property -hprop_golden_shelleyStakeAddressDeregistrationCertificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_shelley_stake_address_deregistration_certificate :: Property +hprop_golden_shelley_stake_address_deregistration_certificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do base <- H.getProjectBase verificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/stake_keys/verification_key" @@ -29,7 +29,8 @@ hprop_golden_shelleyStakeAddressDeregistrationCertificate = propertyOnce . H.mod , "--out-file", deregistrationCertFile ] - H.assertFileOccurences 1 "Stake Address Deregistration Certificate" deregistrationCertFile + goldenFile1 <- H.note "test/cardano-cli-golden/files/golden/shelley/dereg-cert-1.json" + H.diffFileVsGoldenFile deregistrationCertFile goldenFile1 void $ execCardanoCLI [ "babbage", "stake-address","deregistration-certificate" @@ -37,6 +38,5 @@ hprop_golden_shelleyStakeAddressDeregistrationCertificate = propertyOnce . H.mod , "--out-file", scriptDeregistrationCertFile ] - H.assertFileOccurences 1 "Stake Address Deregistration Certificate" scriptDeregistrationCertFile - - H.assertEndsWithSingleNewline deregistrationCertFile + goldenFile2 <- H.note "test/cardano-cli-golden/files/golden/shelley/dereg-cert-2.json" + H.diffFileVsGoldenFile scriptDeregistrationCertFile goldenFile2 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-1.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-1.json new file mode 100644 index 0000000000..50f7db10ec --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-1.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "Stake Address Deregistration Certificate", + "cborHex": "82018200581c81b4245f84593f63c0ff2296930254f77a0690fa9de5f969cac27cb0" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-2.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-2.json new file mode 100644 index 0000000000..9de219e346 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/dereg-cert-2.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "Stake Address Deregistration Certificate", + "cborHex": "82018201581cb9ff787a6dedf9ebe602a26352803778805428c7521b99ec7542aa01" +} From 1a70b235757f4ddb90e8ff13fc71ccc96d67a3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 7 Nov 2023 11:40:44 +0100 Subject: [PATCH 5/5] Shelley/StakeAddress: goldenize a test --- .../StakeAddress/RegistrationCertificate.hs | 24 +++++++++++-------- .../shelley/stake-address/build-raw-out.json | 5 ++++ .../stake-address/reg-certificate-1.json | 5 ++++ .../stake-address/reg-certificate-2.json | 5 ++++ .../stake-address/script-reg-certificate.json | 5 ++++ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-1.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-2.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/script-reg-certificate.json diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs index 03f93799c5..179ff1c49c 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/RegistrationCertificate.hs @@ -9,13 +9,13 @@ import Test.Cardano.CLI.Util import Hedgehog import qualified Hedgehog.Extras.Test.Base as H -import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Process as H +import qualified Hedgehog.Extras.Test.Golden as H {- HLINT ignore "Use camelCase" -} -hprop_golden_shelleyStakeAddressRegistrationCertificate :: Property -hprop_golden_shelleyStakeAddressRegistrationCertificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_shelley_stake_address_registration_certificate :: Property +hprop_golden_shelley_stake_address_registration_certificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do base <- H.getProjectBase keyGenStakingVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/stake_keys/verification_key" @@ -29,7 +29,8 @@ hprop_golden_shelleyStakeAddressRegistrationCertificate = propertyOnce . H.modul , "--out-file", registrationCertFile ] - H.assertFileOccurences 1 "Stake Address Registration Certificate" registrationCertFile + goldenFile1 <- H.note "test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-1.json" + H.diffFileVsGoldenFile registrationCertFile goldenFile1 void $ execCardanoCLI [ "babbage", "stake-address", "registration-certificate" @@ -37,12 +38,11 @@ hprop_golden_shelleyStakeAddressRegistrationCertificate = propertyOnce . H.modul , "--out-file", scriptRegistrationCertFile ] - H.assertFileOccurences 1 "Stake Address Registration Certificate" scriptRegistrationCertFile + goldenFile2 <- H.note "test/cardano-cli-golden/files/golden/shelley/stake-address/script-reg-certificate.json" + H.diffFileVsGoldenFile scriptRegistrationCertFile goldenFile2 - H.assertEndsWithSingleNewline registrationCertFile - -hprop_golden_shelleyStakeAddressRegistrationCertificateWithBuildRaw :: Property -hprop_golden_shelleyStakeAddressRegistrationCertificateWithBuildRaw = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do +hprop_golden_shelley_stake_address_registration_certificate_with_build_raw :: Property +hprop_golden_shelley_stake_address_registration_certificate_with_build_raw = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do keyGenStakingVerificationKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/shelley/keys/stake_keys/verification_key" registrationCertFile <- noteTempFile tempDir "registration.cert" txRawFile <- noteTempFile tempDir "tx.raw" @@ -54,7 +54,8 @@ hprop_golden_shelleyStakeAddressRegistrationCertificateWithBuildRaw = propertyOn , "--out-file", registrationCertFile ] - H.assertFileOccurences 1 "Stake Address Registration Certificate" registrationCertFile + goldenFile1 <- H.note "test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-2.json" + H.diffFileVsGoldenFile registrationCertFile goldenFile1 void $ execCardanoCLI [ "conway", "transaction", "build-raw" @@ -63,3 +64,6 @@ hprop_golden_shelleyStakeAddressRegistrationCertificateWithBuildRaw = propertyOn , "--certificate-file", registrationCertFile , "--out-file", txRawFile ] + + goldenFile2 <- H.note "test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json" + H.diffFileVsGoldenFile txRawFile goldenFile2 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json new file mode 100644 index 0000000000..6c1ac2504a --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/build-raw-out.json @@ -0,0 +1,5 @@ +{ + "type": "Unwitnessed Tx ConwayEra", + "description": "Ledger Cddl Format", + "cborHex": "84a40081825820bdfa7d91a29ffe071c028c0143c5d278c0a7ddb829c1e95f54a1676915fd82c2000180020104d901028183078200581c81b4245f84593f63c0ff2296930254f77a0690fa9de5f969cac27cb01a001e8480a0f5f6" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-1.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-1.json new file mode 100644 index 0000000000..814c664698 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-1.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "Stake Address Registration Certificate", + "cborHex": "82008200581c81b4245f84593f63c0ff2296930254f77a0690fa9de5f969cac27cb0" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-2.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-2.json new file mode 100644 index 0000000000..033bdb92d4 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/reg-certificate-2.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "Stake Address Registration Certificate", + "cborHex": "83078200581c81b4245f84593f63c0ff2296930254f77a0690fa9de5f969cac27cb01a001e8480" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/script-reg-certificate.json b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/script-reg-certificate.json new file mode 100644 index 0000000000..54bfdcb568 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/stake-address/script-reg-certificate.json @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "Stake Address Registration Certificate", + "cborHex": "82008201581cb9ff787a6dedf9ebe602a26352803778805428c7521b99ec7542aa01" +}