From d7b8539ebfc3ca5527fefccc31f98fe552b58ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 12 Apr 2024 10:55:54 +0200 Subject: [PATCH 1/3] cardano-cli-golden: Mateusz' style use of constants --- .../Test/Golden/Governance/Committee.hs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) 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 38c93dfbb9..3bf669bf8f 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 @@ -5,6 +5,7 @@ module Test.Golden.Governance.Committee where import Control.Monad (forM_, void) +import System.FilePath (()) import Test.Cardano.CLI.Aeson (assertHasMappings) import Test.Cardano.CLI.Util @@ -13,6 +14,10 @@ import Hedgehog (Property) 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 @@ -104,10 +109,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" @@ -118,7 +123,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" @@ -141,10 +146,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 @@ -161,10 +166,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 @@ -180,12 +185,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" ) ] From 9c6fbff66e38f97ecca3dffaeea3037cccc52c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 12 Apr 2024 11:39:36 +0200 Subject: [PATCH 2/3] committee key-hash: support extended CC keys --- .../CLI/EraBased/Run/Governance/Committee.hs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index 6914e951b6..99c633eaa7 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -81,7 +81,9 @@ runGovernanceCommitteeKeyGenHot data SomeCommitteeKey = ACommitteeHotKey (VerificationKey CommitteeHotKey) + | ACommitteeHotExtendedKey (VerificationKey CommitteeHotExtendedKey) | ACommitteeColdKey (VerificationKey CommitteeColdKey) + | ACommitteeColdExtendedKey (VerificationKey CommitteeColdExtendedKey) runGovernanceCommitteeKeyHash :: () => Cmd.GovernanceCommitteeKeyHashCmdArgs era @@ -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 @@ -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 From bc91dfa5b1fade03fcb023f3a96399c26077c3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 12 Apr 2024 11:03:49 +0200 Subject: [PATCH 3/3] committee key-hash: test extended CC keys --- .../Test/Golden/Governance/Committee.hs | 21 +++++++++++++++++++ .../committee/cc.extended.cold.vkey | 5 +++++ .../governance/committee/cc.extended.hot.vkey | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.vkey create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.vkey 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 3bf669bf8f..8718f8c270 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 @@ -1,3 +1,4 @@ +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {- HLINT ignore "Use camelCase" -} @@ -8,9 +9,11 @@ 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 @@ -205,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 diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.vkey b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.vkey new file mode 100644 index 0000000000..c2a21b6a0d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.cold.vkey @@ -0,0 +1,5 @@ +{ + "type": "ConstitutionalCommitteeColdExtendedVerificationKey_ed25519_bip32", + "description": "", + "cborHex": "58400a9d35aa5299580a67b1e43a3a4b6d43ef29c94e56c51ce4c17e9a53c1d0f39aa7f68837c38ef680b2dc8f047581707a32f6fcade23d4e02177d389002484798" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.vkey b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.vkey new file mode 100644 index 0000000000..9cb85beea6 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/governance/committee/cc.extended.hot.vkey @@ -0,0 +1,5 @@ +{ + "type": "ConstitutionalCommitteeHotExtendedVerificationKey_ed25519_bip32", + "description": "", + "cborHex": "5840f010c4332699c6ea1e43b427919860277169382d43d2969b28a110cfa08d955c4f178f20955541ce918a6a1352c32536f22677008f9f918d109663e4d2bdc084" +}