Skip to content

Commit

Permalink
Merge pull request #717 from IntersectMBO/smelc/governance-committee-…
Browse files Browse the repository at this point in the history
…key-hash-support-more-keys

conway governance committe key-hash: support extended CC keys
  • Loading branch information
smelc authored Apr 15, 2024
2 parents d24cb3a + bc91dfa commit ad12f22
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 21 deletions.
20 changes: 14 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ runGovernanceCommitteeKeyGenHot

data SomeCommitteeKey
= ACommitteeHotKey (VerificationKey CommitteeHotKey)
| ACommitteeHotExtendedKey (VerificationKey CommitteeHotExtendedKey)
| ACommitteeColdKey (VerificationKey CommitteeColdKey)
| ACommitteeColdExtendedKey (VerificationKey CommitteeColdExtendedKey)

runGovernanceCommitteeKeyHash :: ()
=> Cmd.GovernanceCommitteeKeyHashCmdArgs era
Expand All @@ -94,15 +96,19 @@ runGovernanceCommitteeKeyHash
case vkeySource of
AnyVerificationKeySourceOfText vkText -> do
let asTypes =
[ FromSomeType (AsVerificationKey AsCommitteeHotKey ) ACommitteeHotKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdKey
[ FromSomeType (AsVerificationKey AsCommitteeHotKey) ACommitteeHotKey
, FromSomeType (AsVerificationKey AsCommitteeHotExtendedKey) ACommitteeHotExtendedKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdKey
, FromSomeType (AsVerificationKey AsCommitteeColdExtendedKey) ACommitteeColdExtendedKey
]
pure (deserialiseAnyOfFromBech32 asTypes (unAnyVerificationKeyText vkText))
& onLeft (left . GovernanceCommitteeCmdKeyDecodeError . InputBech32DecodeError)
AnyVerificationKeySourceOfFile vkeyPath -> do
let asTypes =
[ FromSomeType (AsVerificationKey AsCommitteeHotKey ) ACommitteeHotKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdKey
[ FromSomeType (AsVerificationKey AsCommitteeHotKey) ACommitteeHotKey
, FromSomeType (AsVerificationKey AsCommitteeHotExtendedKey) ACommitteeHotExtendedKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdKey
, FromSomeType (AsVerificationKey AsCommitteeColdExtendedKey) ACommitteeColdExtendedKey
]
readFileTextEnvelopeAnyOf asTypes vkeyPath
& firstExceptT GovernanceCommitteeCmdTextEnvReadFileError . newExceptT
Expand All @@ -112,8 +118,10 @@ runGovernanceCommitteeKeyHash
where
renderKeyHash :: SomeCommitteeKey -> ByteString
renderKeyHash = \case
ACommitteeHotKey vk -> renderVerificationKeyHash vk
ACommitteeColdKey vk -> renderVerificationKeyHash vk
ACommitteeHotKey vk -> renderVerificationKeyHash vk
ACommitteeHotExtendedKey vk -> renderVerificationKeyHash vk
ACommitteeColdKey vk -> renderVerificationKeyHash vk
ACommitteeColdExtendedKey vk -> renderVerificationKeyHash vk

renderVerificationKeyHash :: Key keyrole => VerificationKey keyrole -> ByteString
renderVerificationKeyHash = serialiseToRawBytesHex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

{- HLINT ignore "Use camelCase" -}

module Test.Golden.Governance.Committee where

import Control.Monad (forM_, void)
import System.FilePath ((</>))

import Test.Cardano.CLI.Aeson (assertHasMappings)
import qualified Test.Cardano.CLI.Util as H hiding (noteTempFile)
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.Golden as H

goldenDir, inputDir :: FilePath
goldenDir = "test/cardano-cli-golden/files/golden"
inputDir = "test/cardano-cli-golden/files/input"

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance committee key gen/"'@
hprop_golden_governance_committee_key_gen :: Property
Expand Down Expand Up @@ -104,10 +112,10 @@ hprop_golden_governance_CommitteeCreateColdKeyResignationCertificate =
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"
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"
stakeVkey <- noteInputFile $ inputDir </> "governance/stake-address.vkey"
ccProposal <- noteInputFile $ inputDir </> "governance/committee/cc-proposal.txt"
coldCCVkey1 <- noteInputFile $ inputDir </> "governance/committee/cc-cold1.vkey"
coldCCVkey2 <- noteInputFile $ inputDir </> "governance/committee/cc-cold2.vkey"

outFile <- H.noteTempFile tempDir "answer-file.json"

Expand All @@ -118,7 +126,7 @@ hprop_golden_governance_UpdateCommittee =
H.note_ proposalHash
H.note_ $ show $ length proposalHash

goldenAnswerFile <- H.note "test/cardano-cli-golden/files/golden/governance/committee/update-committee-answer.json"
goldenAnswerFile <- H.note $ goldenDir </> "governance/committee/update-committee-answer.json"

void $ execCardanoCLI
[ "conway", "governance", "action", "update-committee"
Expand All @@ -141,10 +149,10 @@ hprop_golden_governance_UpdateCommittee =
hprop_golden_governance_committee_cold_extended_key_signing :: Property
hprop_golden_governance_committee_cold_extended_key_signing =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
skeyFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.skey"
txBody <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/extended-key-signing/tx.body"
skeyFile <- noteInputFile $ inputDir </> "governance/committee/cc.extended.cold.skey"
txBody <- noteInputFile $ inputDir </> "governance/drep/extended-key-signing/tx.body"

outGold <- H.note "test/cardano-cli-golden/files/golden/governance/committee/tx.cold.extended.signed"
outGold <- H.note $ goldenDir </> "governance/committee/tx.cold.extended.signed"
outFile <- H.noteTempFile tempDir "outFile"

H.noteM_ $ execCardanoCLI
Expand All @@ -161,10 +169,10 @@ hprop_golden_governance_committee_cold_extended_key_signing =
hprop_golden_governance_committee_hot_extended_key_signing :: Property
hprop_golden_governance_committee_hot_extended_key_signing =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
skeyFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.skey"
txBody <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/extended-key-signing/tx.body"
skeyFile <- noteInputFile $ inputDir </> "governance/committee/cc.extended.hot.skey"
txBody <- noteInputFile $ inputDir </> "governance/drep/extended-key-signing/tx.body"

outGold <- H.note "test/cardano-cli-golden/files/golden/governance/committee/tx.hot.extended.signed"
outGold <- H.note $ goldenDir </> "governance/committee/tx.hot.extended.signed"
outFile <- H.noteTempFile tempDir "outFile"

H.noteM_ $ execCardanoCLI
Expand All @@ -180,12 +188,12 @@ hprop_golden_governance_committee_hot_extended_key_signing =
-- @cabal test cardano-cli-golden --test-options '-p "/golden verification key committee/"'@
hprop_golden_verification_key_committee :: Property
hprop_golden_verification_key_committee = do
let values = [ ( "test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.skey"
, "test/cardano-cli-golden/files/golden/governance/committee/cc.extended.hot.vkey"
let values = [ ( inputDir </> "governance/committee/cc.extended.hot.skey"
, goldenDir </> "governance/committee/cc.extended.hot.vkey"
)
,
( "test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.skey"
, "test/cardano-cli-golden/files/golden/governance/committee/cc.extended.cold.vkey"
( inputDir </> "governance/committee/cc.extended.cold.skey"
, goldenDir </> "governance/committee/cc.extended.cold.vkey"
)
]

Expand All @@ -200,3 +208,21 @@ hprop_golden_verification_key_committee = do
]

H.diffFileVsGoldenFile vkeyFileOut vkeyGolden

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance extended committee key hash/"'@
hprop_golden_governance_extended_committee_key_hash :: Property
hprop_golden_governance_extended_committee_key_hash =
let supplyValues = [ (inputDir </> "governance/committee/cc.extended.cold.vkey", "9fe92405abcd903d34e21a97328e7cd222eebd4ced5995a95777f7a3\n")
, (inputDir </> "governance/committee/cc.extended.hot.vkey", "4eb7202ffcc6d5513dba5edc618bd7b582a257c76d6b0cd83975f4e6\n")
] in
propertyOnce $ forM_ supplyValues $ \(extendedKeyFile, expected) ->
H.moduleWorkspace "tmp" $ \_tempDir -> do
verificationKeyFile <- H.noteInputFile extendedKeyFile

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

result H.=== expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ConstitutionalCommitteeColdExtendedVerificationKey_ed25519_bip32",
"description": "",
"cborHex": "58400a9d35aa5299580a67b1e43a3a4b6d43ef29c94e56c51ce4c17e9a53c1d0f39aa7f68837c38ef680b2dc8f047581707a32f6fcade23d4e02177d389002484798"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ConstitutionalCommitteeHotExtendedVerificationKey_ed25519_bip32",
"description": "",
"cborHex": "5840f010c4332699c6ea1e43b427919860277169382d43d2969b28a110cfa08d955c4f178f20955541ce918a6a1352c32536f22677008f9f918d109663e4d2bdc084"
}

0 comments on commit ad12f22

Please sign in to comment.