Skip to content

Commit

Permalink
Merge pull request #714 from IntersectMBO/smelc/test-governance-impro…
Browse files Browse the repository at this point in the history
…vements

Improvements to governance tests
  • Loading branch information
smelc authored Apr 12, 2024
2 parents 222a332 + 39402ae commit d24cb3a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 87 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ test-suite cardano-cli-test
, hedgehog
, hedgehog-extras ^>= 0.6.1.0
, exceptions
, regex-tdfa
, tasty
, tasty-hedgehog
, text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ runGovernanceCommitteeKeyGenHot
$ writeLazyByteStringFile vkeyPath
$ textEnvelopeToJSON (Just Key.ccHotVkeyDesc) vkey

data SomeCommitteeKey f
= ACommitteeHotKey (f CommitteeHotKey)
| ACommitteeColdKey (f CommitteeColdKey)
data SomeCommitteeKey
= ACommitteeHotKey (VerificationKey CommitteeHotKey)
| ACommitteeColdKey (VerificationKey CommitteeColdKey)

runGovernanceCommitteeKeyHash :: ()
=> Cmd.GovernanceCommitteeKeyHashCmdArgs era
Expand Down Expand Up @@ -110,7 +110,7 @@ runGovernanceCommitteeKeyHash
liftIO $ BS.putStrLn (renderKeyHash vkey)

where
renderKeyHash :: SomeCommitteeKey VerificationKey -> ByteString
renderKeyHash :: SomeCommitteeKey -> ByteString
renderKeyHash = \case
ACommitteeHotKey vk -> renderVerificationKeyHash vk
ACommitteeColdKey vk -> renderVerificationKeyHash vk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,43 @@
module Test.Golden.Governance.Committee where

import Control.Monad (forM_, void)
import Text.Regex.TDFA ((=~))

import Test.Cardano.CLI.Aeson (assertHasMappings)
import Test.Cardano.CLI.Util

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 =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "committee", "key-gen-cold"
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

H.assertFileOccurences 1 "ConstitutionalCommitteeColdVerificationKey_ed25519" verificationKeyFile
H.assertFileOccurences 1 "ConstitutionalCommitteeColdSigningKey_ed25519" signingKeyFile

H.assertEndsWithSingleNewline verificationKeyFile
H.assertEndsWithSingleNewline signingKeyFile

hprop_golden_governanceCommitteeKeyGenHot :: Property
hprop_golden_governanceCommitteeKeyGenHot =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "committee", "key-gen-hot"
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

H.assertFileOccurences 1 "ConstitutionalCommitteeHotVerificationKey_ed25519" verificationKeyFile
H.assertFileOccurences 1 "ConstitutionalCommitteeHotSigningKey_ed25519" signingKeyFile

H.assertFileOccurences 1 "Constitutional Committee Hot Verification Key" verificationKeyFile
H.assertFileOccurences 1 "Constitutional Committee Hot Signing Key" signingKeyFile

H.assertEndsWithSingleNewline verificationKeyFile
H.assertEndsWithSingleNewline signingKeyFile

hprop_golden_governanceCommitteeKeyHashCold :: Property
hprop_golden_governanceCommitteeKeyHashCold =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "committee", "key-gen-cold"
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

result <- execCardanoCLI
[ "conway", "governance", "committee", "key-hash"
, "--verification-key-file", verificationKeyFile
]

H.assert $ result =~ id @String "^[a-f0-9]{56}$"

hprop_golden_governanceCommitteeKeyHashHot :: Property
hprop_golden_governanceCommitteeKeyHashHot =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance committee key gen/"'@
hprop_golden_governance_committee_key_gen :: Property
hprop_golden_governance_committee_key_gen =
let supplyValues = [ ("key-gen-cold", "Cold")
, ("key-gen-hot", "Hot") ] in
propertyOnce $ forM_ supplyValues $ \(flag, inJson) ->
H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "committee", "key-gen-hot"
H.noteShowM_ $ execCardanoCLI
[ "conway", "governance", "committee", flag
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

result <- execCardanoCLI
[ "conway", "governance", "committee", "key-hash"
, "--verification-key-file", verificationKeyFile
]
assertHasMappings [ ("type", "ConstitutionalCommittee" <> inJson <> "VerificationKey_ed25519")
, ("description", "Constitutional Committee " <> inJson <> " Verification Key")]
verificationKeyFile

H.assert $ result =~ id @String "^[a-f0-9]{56}$"
assertHasMappings [ ("type", "ConstitutionalCommittee" <> inJson <> "SigningKey_ed25519")
, ("description", "Constitutional Committee " <> inJson <> " Signing Key")]
signingKeyFile

hprop_golden_governanceCommitteeCreateHotKeyAuthorizationCertificate :: Property
hprop_golden_governanceCommitteeCreateHotKeyAuthorizationCertificate =
-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance CommitteeCreateHotKeyAuthorizationCertificate/"'@
hprop_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate :: Property
hprop_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
ccColdVKey <- noteTempFile tempDir "cc-cold.vkey"
ccColdSKey <- noteTempFile tempDir "cc-cold.skey"
Expand All @@ -114,18 +62,21 @@ hprop_golden_governanceCommitteeCreateHotKeyAuthorizationCertificate =
, "--signing-key-file", ccHotSKey
]

void $ execCardanoCLI
H.noteShowM_ $ execCardanoCLI
[ "conway", "governance", "committee", "create-hot-key-authorization-certificate"
, "--cold-verification-key-file", ccColdVKey
, "--hot-key-file", ccHotVKey
, "--out-file", certFile
]

H.assertFileOccurences 1 "CertificateConway" certFile
H.assertFileOccurences 1 "Constitutional Committee Hot Key Registration Certificate" certFile
assertHasMappings [ ("type", "CertificateConway")
, ("description", "Constitutional Committee Hot Key Registration Certificate")]
certFile

hprop_golden_governanceCommitteeCreateColdKeyResignationCertificate :: Property
hprop_golden_governanceCommitteeCreateColdKeyResignationCertificate =
-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance CommitteeCreateColdKeyResignationCertificate/"'@
hprop_golden_governance_CommitteeCreateColdKeyResignationCertificate :: Property
hprop_golden_governance_CommitteeCreateColdKeyResignationCertificate =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
ccColdVKey <- noteTempFile tempDir "cold.vkey"
ccColdSKey <- noteTempFile tempDir "cold.skey"
Expand All @@ -144,11 +95,14 @@ hprop_golden_governanceCommitteeCreateColdKeyResignationCertificate =
, "--out-file", certFile
]

H.assertFileOccurences 1 "CertificateConway" certFile
H.assertFileOccurences 1 "Constitutional Committee Cold Key Resignation Certificate" certFile
assertHasMappings [ ("type", "CertificateConway")
, ("description", "Constitutional Committee Cold Key Resignation Certificate")]
certFile

hprop_golden_governanceUpdateCommittee :: Property
hprop_golden_governanceUpdateCommittee =
-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance UpdateCommittee/"'@
hprop_golden_governance_UpdateCommittee :: Property
hprop_golden_governance_UpdateCommittee =
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"
Expand Down
27 changes: 26 additions & 1 deletion cardano-cli/test/cardano-cli-test/Test/Cli/Governance/Hash.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{- HLINT ignore "Use camelCase" -}
{-# LANGUAGE TypeApplications #-}

module Test.Cli.Governance.Hash where

import Control.Monad (void)
import Control.Monad (forM_, void)
import Text.Regex.TDFA ((=~))

import Test.Cardano.CLI.Util

Expand Down Expand Up @@ -40,3 +42,26 @@ governance_hash_trip_fun input =
hashFromFile <- H.readFile hashFile

H.diff hash (==) hashFromFile

-- | Execute me with:
-- @cabal test cardano-cli-test --test-options '-p "/governance committee key hash/"'@
hprop_governance_committee_key_hash :: Property
hprop_governance_committee_key_hash =
let supplyValues = [ "key-gen-cold", "key-gen-hot" ] in
propertyOnce $ forM_ supplyValues $ \flag ->
H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "committee", flag
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

result <- execCardanoCLI
[ "conway", "governance", "committee", "key-hash"
, "--verification-key-file", verificationKeyFile
]

H.assert $ result =~ id @String "^[a-f0-9]{56}$"

0 comments on commit d24cb3a

Please sign in to comment.