From 0d3c6266c5883a38c54a9b1a05f7adc387dd2ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 18 Oct 2023 15:22:03 +0200 Subject: [PATCH 1/3] action update-committee: add golden test --- .../Test/Golden/Governance/Committee.hs | 29 +++++++++++++++++++ .../committee/update-committee-answer.json | 5 ++++ .../input/governance/committee/cc-cold1.vkey | 5 ++++ .../input/governance/committee/cc-cold2.vkey | 5 ++++ .../governance/committee/cc-proposal.txt | 4 +++ 5 files changed, 48 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold1.vkey create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold2.vkey create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs index 722517b6ae..4378379bf3 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Committee.hs @@ -13,6 +13,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 hprop_golden_governanceCommitteeKeyGenCold :: Property hprop_golden_governanceCommitteeKeyGenCold = @@ -145,3 +146,31 @@ hprop_golden_governanceCommitteeCreateColdKeyResignationCertificate = H.assertFileOccurences 1 "CertificateShelley" certFile H.assertFileOccurences 1 "Constitutional Committee Cold Key Resignation Certificate" certFile + +hprop_golden_governanceUpdateCommittee :: Property +hprop_golden_governanceUpdateCommittee = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + stakeVkey <- noteInputFile "test/cardano-cli-golden/files/input/governance/stake-address.vkey" + ccProposal <- noteInputFile "test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt" + coldCCVkey1 <- noteInputFile "test/cardano-cli-golden/files/input/governance/committee/cc-cold1.vkey" + coldCCVkey2 <- noteInputFile "test/cardano-cli-golden/files/input/governance/committee/cc-cold2.vkey" + + outFile <- H.noteTempFile tempDir "answer-file.json" + + goldenAnswerFile <- H.note "test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json" + + void $ execCardanoCLI + [ "conway", "governance", "action", "update-committee" + , "--testnet", "--governance-action-deposit", "0" + , "--stake-verification-key-file", stakeVkey + , "--proposal-anchor-url", "http://dummy" + , "--proposal-anchor-metadata-file", ccProposal + , "--add-cc-cold-verification-key-file", coldCCVkey1 + , "--epoch", "202" + , "--add-cc-cold-verification-key-file", coldCCVkey2 + , "--epoch", "252" + , "--quorum", "51/100" + , "--out-file", outFile + ] + + H.diffFileVsGoldenFile outFile goldenAnswerFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json new file mode 100644 index 0000000000..623cd4e065 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json @@ -0,0 +1,5 @@ +{ + "type": "Governance proposal", + "description": "", + "cborHex": "8400581de08f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058504f680a28200581cc0f2510d2353ee41a508b3c700c807e52697f2813fb014e3bc6982cd18ca8200581cf5ba9ae54a389cf97c54b981513d780877fc888579148044a8e7e7f218fcd81e8218331864826c687474703a2f2f64756d6d7958203d2a9d15382c14f5ca260a2f5bfb645fe148bfe10c1d0e1d305b7b1393e2bd97" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold1.vkey b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold1.vkey new file mode 100644 index 0000000000..8832ca53bc --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold1.vkey @@ -0,0 +1,5 @@ +{ + "type": "ConstitutionalCommitteeColdVerificationKey_ed25519", + "description": "Constitutional Committee Cold Verification Key", + "cborHex": "5820b18096da5d51818f8890d6a7c9c7b21d555e03e347f4ec07be09e0ddef96a984" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold2.vkey b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold2.vkey new file mode 100644 index 0000000000..55c9ae48c2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-cold2.vkey @@ -0,0 +1,5 @@ +{ + "type": "ConstitutionalCommitteeColdVerificationKey_ed25519", + "description": "Constitutional Committee Cold Verification Key", + "cborHex": "58209f70f7288b9db552db64e42e1442265515ff544cf95beb514d2fcf6c9d9dac6a" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt new file mode 100644 index 0000000000..fd64cd90d1 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt @@ -0,0 +1,4 @@ +WE, THE PEOPLE of Barataria, in order to maintain peace and harmony among us, establish this Constitution for our +precious Insula of Barataria: + +Article 1. The person who waters wine or changes the label should lose his life for it. \ No newline at end of file From b6bd23269a6543b37cdd2c1fea86c6389f1ac008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Wed, 18 Oct 2023 17:25:31 +0200 Subject: [PATCH 2/3] Remove CR, to be deterministic on Windows too --- .../golden/governance/committee/update-committee-answer.json | 2 +- .../files/input/governance/committee/cc-proposal.txt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json index 623cd4e065..358e5c675f 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json +++ b/cardano-cli/test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json @@ -1,5 +1,5 @@ { "type": "Governance proposal", "description": "", - "cborHex": "8400581de08f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058504f680a28200581cc0f2510d2353ee41a508b3c700c807e52697f2813fb014e3bc6982cd18ca8200581cf5ba9ae54a389cf97c54b981513d780877fc888579148044a8e7e7f218fcd81e8218331864826c687474703a2f2f64756d6d7958203d2a9d15382c14f5ca260a2f5bfb645fe148bfe10c1d0e1d305b7b1393e2bd97" + "cborHex": "8400581de08f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058504f680a28200581cc0f2510d2353ee41a508b3c700c807e52697f2813fb014e3bc6982cd18ca8200581cf5ba9ae54a389cf97c54b981513d780877fc888579148044a8e7e7f218fcd81e8218331864826c687474703a2f2f64756d6d795820c9decb4498c4924d4f9804b6fa3425bab8f669f6452cb61f295114c906f3093e" } diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt index fd64cd90d1..9158bce2b4 100644 --- a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt @@ -1,4 +1,2 @@ WE, THE PEOPLE of Barataria, in order to maintain peace and harmony among us, establish this Constitution for our -precious Insula of Barataria: - -Article 1. The person who waters wine or changes the label should lose his life for it. \ No newline at end of file +precious Insula of Barataria: Article 1. The person who waters wine or changes the label should lose his life for it. \ No newline at end of file From e011dd5c5cd1c5dac8dbb12e2f39ddad9f258060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 19 Oct 2023 16:25:59 +0200 Subject: [PATCH 3/3] DO NOT MERGE: read proposal file as text, not binary, to test. --- cardano-cli/src/Cardano/CLI/Read.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 499fa84616..ab7a084f0f 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -137,8 +137,9 @@ import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import qualified Data.Text.Encoding.Error as Text +import qualified Data.Text.IO as Text import Data.Word -import GHC.IO.Handle (hClose, hIsSeekable,) +import GHC.IO.Handle (hClose, hIsSeekable) import GHC.IO.Handle.FD (openFileBlocking) import qualified Options.Applicative as Opt import System.IO (IOMode (ReadMode)) @@ -803,7 +804,7 @@ readVoteHashSource = \case VoteHashSourceHash h -> return h VoteHashSourceText c -> return $ Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 c VoteHashSourceFile fp -> do - cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp + cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp _utf8EncodedText <- firstExceptT VoteErrorTextNotUnicode . hoistEither $ Text.decodeUtf8' cBs return $ Ledger.hashAnchorData $ Ledger.AnchorData cBs @@ -858,9 +859,8 @@ proposalHashSourceToHash :: () proposalHashSourceToHash proposalHashSource = do case proposalHashSource of ProposalHashSourceFile fp -> do - cBs <- liftIO $ BS.readFile $ unFile fp - _utf8EncodedText <- firstExceptT ProposalNotUnicodeError . hoistEither $ Text.decodeUtf8' cBs - pure $ Ledger.hashAnchorData $ Ledger.AnchorData cBs + text <- liftIO $ Text.readFile $ unFile fp + pure $ Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 text ProposalHashSourceText c -> do pure $ Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 c