Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action update-committee: add golden test #383

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "Governance proposal",
"description": "",
"cborHex": "8400581de08f4a3466a404c11eb410313015b88e447d81b60089e25f611600e6058504f680a28200581cc0f2510d2353ee41a508b3c700c807e52697f2813fb014e3bc6982cd18ca8200581cf5ba9ae54a389cf97c54b981513d780877fc888579148044a8e7e7f218fcd81e8218331864826c687474703a2f2f64756d6d795820c9decb4498c4924d4f9804b6fa3425bab8f669f6452cb61f295114c906f3093e"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ConstitutionalCommitteeColdVerificationKey_ed25519",
"description": "Constitutional Committee Cold Verification Key",
"cborHex": "5820b18096da5d51818f8890d6a7c9c7b21d555e03e347f4ec07be09e0ddef96a984"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ConstitutionalCommitteeColdVerificationKey_ed25519",
"description": "Constitutional Committee Cold Verification Key",
"cborHex": "58209f70f7288b9db552db64e42e1442265515ff544cf95beb514d2fcf6c9d9dac6a"
}
Original file line number Diff line number Diff line change
@@ -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.