Skip to content

Commit

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

Replace usages of assertFileOccurences by comparisons with golden files (1/n)
  • Loading branch information
newhoggy authored Nov 3, 2023
2 parents b9579f6 + 9d81ccb commit 92115ee
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}

Expand All @@ -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 =
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" "<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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Witnessed Tx ConwayEra",
"description": "Ledger Cddl Format",
"cborHex": "84a5008182582054b5f2d5ed0fa142e724c9a982864d9e080b10648a66c8f7956eb3cc2cf16c0000018182581d6052e63f22c5107ed776b70f7b92248b02552fd08f3e747bc7450994411b0000000235cfef6d021a0002ff51031a0099d1dd04828a03581ce6eb963e591bc66401b5e1c763f4c9bc27adf58eb720f63c809981d75820dacc52f2d73542ab0fc3b1f8051d00b0e50f1130935e5a21982bd289705852ae1b000000174876e8001b00000002540be400d81e82010a581de05e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c81581c5e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c818400190bb9447f000001f682783268747470733a2f2f6d792d69702e61742f746573742f636f6e77617974657374706f6f6c2e6d657461646174612e6a736f6e58207cd083e6682892afc2b4e315fca93784f43dccde8bae1daa81db0b587e27155f83028200581c5e35891efec9c4a4e08d2a6a6d03598056d014e287618548e2556f8c581ce6eb963e591bc66401b5e1c763f4c9bc27adf58eb720f63c809981d7a10081825820c16f6bf723e38013f88588539fbbf1cd6b57bbbd8bb2cf318e641f00dcd527875840e62f3050bf7ee1d1547badd6f8346c00957b20c8d8f201fc8cf9d64485b3b3c944392afe00619516a00d98c6ccfa44a7de8c1a093efdc10832bb6fdf4cde8e08f5f6"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"cborHex": "<cborHex>",
"description": "",
"type": "Governance proposal"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "CertificateShelley",
"description": "DRep Retirement Certificate",
"cborHex": "83118200581ceb09d5556a8bce421074e394d02c79ced96741657b4cf7ca8995294d1a000f4240"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "GovernancePoll",
"description": "An on-chain poll for SPOs: Pineapples on pizza?",
"cborHex": "a1185ea200817450696e656170706c6573206f6e2070697a7a613f0182816379657381626e6f"
}

0 comments on commit 92115ee

Please sign in to comment.