From bfa174d24b926f98284b61dbbb46bc2d57b0a269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 2 Nov 2023 11:32:25 +0100 Subject: [PATCH 1/4] Governance/Action: simplify a golden test --- .../Test/Golden/Governance/Action.hs | 10 +++------- ...create-constitution-for-stake-address.action.golden | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs index d770888502..50295c69a7 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs @@ -9,11 +9,10 @@ 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 -hprop_golden_governanceActionCreateConstitution :: Property -hprop_golden_governanceActionCreateConstitution = +hprop_golden_governance_action_create_constitution :: Property +hprop_golden_governance_action_create_constitution = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do stakeAddressVKeyFile <- noteTempFile tempDir "stake-address.vkey" stakeAddressSKeyFile <- noteTempFile tempDir "stake-address.skey" @@ -41,14 +40,11 @@ hprop_golden_governanceActionCreateConstitution = goldenActionFile <- H.note "test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden" + -- Remove cbor hex from comparison, as it's not stable H.redactJsonField "cborHex" "" actionFile redactedActionFile H.diffFileVsGoldenFile redactedActionFile goldenActionFile - H.assertFileOccurences 1 "Governance proposal" actionFile - - H.assertEndsWithSingleNewline actionFile - hprop_golden_conway_governance_action_view_constitution_json :: Property hprop_golden_conway_governance_action_view_constitution_json = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden index 0a9e6843a8..7b542f5b7a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/action/create-constitution-for-stake-address.action.golden @@ -2,4 +2,4 @@ "cborHex": "", "description": "", "type": "Governance proposal" -} \ No newline at end of file +} From 012bafb5a1002fbdffbe751e351ff80d8c8e626b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 2 Nov 2023 11:40:27 +0100 Subject: [PATCH 2/4] Governance/DRep: goldenize a test --- .../test/cardano-cli-golden/Test/Golden/Governance/DRep.hs | 4 ++-- .../files/golden/governance/drep/drep_retirement_cert | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs index 44db5fe6eb..3da370227c 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -91,6 +91,7 @@ hprop_golden_governance_drep_retirement_certificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do drepVKeyFile <- noteInputFile "test/cardano-cli-golden/files/input/drep.vkey" certFile <- H.noteTempFile tempDir "drep.retirement.cert" + goldenDRepRetirementCertFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert" void $ execCardanoCLI [ "conway", "governance", "drep", "retirement-certificate" @@ -99,8 +100,7 @@ hprop_golden_governance_drep_retirement_certificate = , "--out-file", certFile ] - H.assertFileOccurences 1 "CertificateShelley" certFile - H.assertFileOccurences 1 "DRep Retirement Certificate" certFile + H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile hprop_golden_governance_drep_metadata_hash :: Property hprop_golden_governance_drep_metadata_hash = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert new file mode 100644 index 0000000000..371c1d3052 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert @@ -0,0 +1,5 @@ +{ + "type": "CertificateShelley", + "description": "DRep Retirement Certificate", + "cborHex": "83118200581ceb09d5556a8bce421074e394d02c79ced96741657b4cf7ca8995294d1a000f4240" +} From 3e4ff34d70980b339cef9c0b9e786db739459e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 2 Nov 2023 11:49:50 +0100 Subject: [PATCH 3/4] Conway/Transaction: goldenize a test --- .../Test/Golden/Conway/Transaction/Assemble.hs | 6 ++++-- .../files/golden/conway/transaction/assemble_out | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction/assemble_out 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 d2a8c0eced..2347172e47 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 @@ -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" -} @@ -27,4 +27,6 @@ hprop_golden_conwayTransactionAssembleWitness_SigningKey = propertyOnce $ H.modu , "--out-file", witnessTx ] - H.assertFileOccurences 1 "Witnessed Tx ConwayEra" witnessTx + goldenFile <- H.note "test/cardano-cli-golden/files/golden/conway/transaction/assemble_out" + + H.diffFileVsGoldenFile witnessTx goldenFile \ No newline at end of file diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction/assemble_out b/cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction/assemble_out new file mode 100644 index 0000000000..9f36beda13 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/conway/transaction/assemble_out @@ -0,0 +1,5 @@ +{ + "type": "Witnessed Tx ConwayEra", + "description": "Ledger Cddl Format", + "cborHex": "84a5008182582054b5f2d5ed0fa142e724c9a982864d9e080b10648a66c8f7956eb3cc2cf16c0000018182581d6052e63f22c5107ed776b70f7b92248b02552fd08f3e747bc7450994411b0000000235cfef6d021a0002ff51031a0099d1dd04828a03581ce6eb963e591bc66401b5e1c763f4c9bc27adf58eb720f63c809981d75820dacc52f2d73542ab0fc3b1f8051d00b0e50f1130935e5a21982bd289705852ae1b000000174876e8001b00000002540be400d81e82010a581de05e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c81581c5e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c818400190bb9447f000001f682783268747470733a2f2f6d792d69702e61742f746573742f636f6e77617974657374706f6f6c2e6d657461646174612e6a736f6e58207cd083e6682892afc2b4e315fca93784f43dccde8bae1daa81db0b587e27155f83028200581c5e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c581ce6eb963e591bc66401b5e1c763f4c9bc27adf58eb720f63c809981d7a10081825820c16f6bf723e38013f88588539fbbf1cd6b57bbbd8bb2cf318e641f00dcd527875840e62f3050bf7ee1d1547badd6f8346c00957b20c8d8f201fc8cf9d64485b3b3c944392afe00619516a00d98c6ccfa44a7de8c1a093efdc10832bb6fdf4cde8e08f5f6" +} From 9d81ccb3c4678f8a29d77f3ec967e82f470cccdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 2 Nov 2023 11:57:56 +0100 Subject: [PATCH 4/4] Governance/CreatePoll: goldenize a test --- .../Test/Golden/EraBased/Governance/CreatePoll.hs | 13 +++++++++---- .../governance/polls/create-poll-long-text-out.json | 5 +++++ .../golden/governance/polls/create-poll-out.json | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-long-text-out.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-out.json diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs index 169e27d07e..c5a9d55cfd 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/EraBased/Governance/CreatePoll.hs @@ -10,6 +10,7 @@ import Hedgehog (Property) import qualified Hedgehog as H 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" -} @@ -30,8 +31,10 @@ hprop_golden_governanceCreatePoll = noteInputFile "test/cardano-cli-golden/files/input/governance/create/basic.json" >>= H.readFile >>= (H.===) stdout - H.assertFileOccurences 1 "GovernancePoll" pollFile - H.assertEndsWithSingleNewline pollFile + + goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/polls/create-poll-out.json" + + H.diffFileVsGoldenFile pollFile goldenFile hprop_golden_governanceCreateLongPoll :: Property hprop_golden_governanceCreateLongPoll = @@ -50,5 +53,7 @@ hprop_golden_governanceCreateLongPoll = noteInputFile "test/cardano-cli-golden/files/input/governance/create/long-text.json" >>= H.readFile >>= (H.===) stdout - H.assertFileOccurences 1 "GovernancePoll" pollFile - H.assertEndsWithSingleNewline pollFile + + goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/polls/create-poll-long-text-out.json" + + H.diffFileVsGoldenFile pollFile goldenFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-long-text-out.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-long-text-out.json new file mode 100644 index 0000000000..fe4480afea --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-long-text-out.json @@ -0,0 +1,5 @@ +{ + "type": "GovernancePoll", + "description": "An on-chain poll for SPOs: What is the most adequate topping to put on a pizza (please consider all possibilities and take time to answer)?", + "cborHex": "a1185ea2008278405768617420697320746865206d6f737420616465717561746520746f7070696e6720746f20707574206f6e20612070697a7a612028706c6561736520636f6e7378306964657220616c6c20706f73736962696c697469657320616e642074616b652074696d6520746f20616e73776572293f0182816a70696e656170706c65738278406f6e6c7920747261646974696f6e616c20746f706963732073686f756c6420676f206f6e20612070697a7a612c20746869732069736e277420726f6f6d20666f6772206a6f6b6573" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-out.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-out.json new file mode 100644 index 0000000000..8bca376771 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/polls/create-poll-out.json @@ -0,0 +1,5 @@ +{ + "type": "GovernancePoll", + "description": "An on-chain poll for SPOs: Pineapples on pizza?", + "cborHex": "a1185ea200817450696e656170706c6573206f6e2070697a7a613f0182816379657381626e6f" +}