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 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..358e5c675f --- /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": "8400581de08f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058504f680a28200581cc0f2510d2353ee41a508b3c700c807e52697f2813fb014e3bc6982cd18ca8200581cf5ba9ae54a389cf97c54b981513d780877fc888579148044a8e7e7f218fcd81e8218331864826c687474703a2f2f64756d6d795820c9decb4498c4924d4f9804b6fa3425bab8f669f6452cb61f295114c906f3093e" +} 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..9158bce2b4 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc-proposal.txt @@ -0,0 +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