44
55module Test.Golden.Governance.Committee where
66
7- import Control.Monad (forM_ , void )
7+ import Control.Monad (void )
8+ import Data.Map qualified as Map
89import Data.Monoid (Last (.. ))
910import System.Environment qualified as IO
1011import System.Exit (ExitCode (.. ))
1112import System.FilePath ((</>) )
1213
13- import Test.Cardano.CLI.Aeson (assertHasMappings )
14+ import Test.Cardano.CLI.Aeson (redactJsonFieldsInFile )
1415import Test.Cardano.CLI.Hash
1516 ( exampleAnchorDataHash
1617 , exampleAnchorDataIpfsHash
@@ -25,59 +26,28 @@ import Hedgehog qualified as H
2526import Hedgehog.Extras (UnitIO )
2627import Hedgehog.Extras qualified as H
2728import Hedgehog.Internal.Property ((===) )
29+ import Test.Golden.Util
2830
29- goldenDir , inputDir :: FilePath
30- goldenDir = " test/cardano-cli-golden/files/golden"
31+ inputDir :: FilePath
3132inputDir = " test/cardano-cli-golden/files/input"
3233
3334-- | Execute me with:
34- -- @cabal test cardano-cli-golden --test-options '-p "/golden governance committee key gen/"'@
35- tasty_golden_governance_committee_key_gen :: UnitIO ()
36- tasty_golden_governance_committee_key_gen =
37- let supplyValues =
38- [ (" key-gen-cold" , " Cold" )
39- , (" key-gen-hot" , " Hot" )
40- ]
41- in forM_ supplyValues $ \ (flag, inJson) ->
42- H. moduleWorkspace " tmp" $ \ tempDir -> do
43- verificationKeyFile <- noteTempFile tempDir " key-gen.vkey"
44- signingKeyFile <- noteTempFile tempDir " key-gen.skey"
45-
46- H. noteShowM_ $
47- execCardanoCLI
48- [ " conway"
49- , " governance"
50- , " committee"
51- , flag
52- , " --verification-key-file"
53- , verificationKeyFile
54- , " --signing-key-file"
55- , signingKeyFile
56- ]
57-
58- assertHasMappings
59- [ (" type" , " ConstitutionalCommittee" <> inJson <> " VerificationKey_ed25519" )
60- , (" description" , " Constitutional Committee " <> inJson <> " Verification Key" )
61- ]
62- verificationKeyFile
63-
64- assertHasMappings
65- [ (" type" , " ConstitutionalCommittee" <> inJson <> " SigningKey_ed25519" )
66- , (" description" , " Constitutional Committee " <> inJson <> " Signing Key" )
67- ]
68- signingKeyFile
69-
70- -- | Execute me with:
71- -- @cabal test cardano-cli-golden --test-options '-p "/golden governance CommitteeCreateHotKeyAuthorizationCertificate/"'@
72- tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate :: UnitIO ()
73- tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
35+ -- @cabal test cardano-cli-golden --test-options '-p "/golden_governance_committee_KeyGenCold/"'@
36+ tasty_golden_governance_committee_KeyGenCold :: UnitIO ()
37+ tasty_golden_governance_committee_KeyGenCold =
7438 H. moduleWorkspace " tmp" $ \ tempDir -> do
75- ccColdVKey <- noteTempFile tempDir " cc-cold.vkey"
76- ccColdSKey <- noteTempFile tempDir " cc-cold.skey"
77- ccHotVKey <- noteTempFile tempDir " cc-hot.vkey"
78- ccHotSKey <- noteTempFile tempDir " cc-hot.skey"
79-
80- certFile <- noteTempFile tempDir " hot-auth.cert"
39+ H. note_ tempDir
40+ ccColdVKey <- noteTempFile tempDir " cold.vkey"
41+ ccColdSKey <- noteTempFile tempDir " cold.skey"
42+ ccColdVKeyRedacted <- noteTempFile tempDir " cold.vkey.redacted"
43+ ccColdSKeyRedacted <- noteTempFile tempDir " cold.skey.redacted"
44+ ccColdVKeyRedactedGoldenFile <- noteGoldenFile " cold.vkey.redacted"
45+ ccColdSKeyRedactedGoldenFile <- noteGoldenFile " cold.skey.redacted"
46+
47+ let redactions =
48+ Map. fromList
49+ [ (" cborHex" , " <redacted>" )
50+ ]
8151
8252 void $
8353 execCardanoCLI
@@ -91,6 +61,30 @@ tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
9161 , ccColdSKey
9262 ]
9363
64+ redactJsonFieldsInFile redactions ccColdVKey ccColdVKeyRedacted
65+ redactJsonFieldsInFile redactions ccColdSKey ccColdSKeyRedacted
66+
67+ H. diffFileVsGoldenFile ccColdVKeyRedacted ccColdVKeyRedactedGoldenFile
68+ H. diffFileVsGoldenFile ccColdSKeyRedacted ccColdSKeyRedactedGoldenFile
69+
70+ -- | Execute me with:
71+ -- @cabal test cardano-cli-golden --test-options '-p "/golden_governance_committee_KeyGenHot/"'@
72+ tasty_golden_governance_committee_KeyGenHot :: UnitIO ()
73+ tasty_golden_governance_committee_KeyGenHot =
74+ H. moduleWorkspace " tmp" $ \ tempDir -> do
75+ H. note_ tempDir
76+ ccHotVKey <- noteTempFile tempDir " hot.vkey"
77+ ccHotSKey <- noteTempFile tempDir " hot.skey"
78+ ccHotVKeyRedacted <- noteTempFile tempDir " hot.vkey.redacted"
79+ ccHotSKeyRedacted <- noteTempFile tempDir " hot.skey.redacted"
80+ ccHotVKeyRedactedGoldenFile <- noteGoldenFile " hot.vkey.redacted"
81+ ccHotSKeyRedactedGoldenFile <- noteGoldenFile " hot.skey.redacted"
82+
83+ let redactions =
84+ Map. fromList
85+ [ (" cborHex" , " <redacted>" )
86+ ]
87+
9488 void $
9589 execCardanoCLI
9690 [ " conway"
@@ -103,6 +97,23 @@ tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
10397 , ccHotSKey
10498 ]
10599
100+ redactJsonFieldsInFile redactions ccHotVKey ccHotVKeyRedacted
101+ redactJsonFieldsInFile redactions ccHotSKey ccHotSKeyRedacted
102+
103+ H. diffFileVsGoldenFile ccHotVKeyRedacted ccHotVKeyRedactedGoldenFile
104+ H. diffFileVsGoldenFile ccHotSKeyRedacted ccHotSKeyRedactedGoldenFile
105+
106+ -- | Execute me with:
107+ -- @cabal test cardano-cli-golden --test-options '-p "/golden governance CommitteeCreateHotKeyAuthorizationCertificate/"'@
108+ tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate :: UnitIO ()
109+ tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
110+ H. moduleWorkspace " tmp" $ \ tempDir -> do
111+ ccColdVKey <- noteInputFile $ inputDir </> " governance/cc-cold.vkey"
112+ ccHotVKey <- noteInputFile $ inputDir </> " governance/cc-hot.vkey"
113+
114+ certFile <- noteTempFile tempDir " hot-auth.cert"
115+ goldenCertFile <- noteGoldenFile " hot-key-authorization-certificate.cert"
116+
106117 H. noteShowM_ $
107118 execCardanoCLI
108119 [ " conway"
@@ -117,33 +128,16 @@ tasty_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
117128 , certFile
118129 ]
119130
120- assertHasMappings
121- [ (" type" , " CertificateConway" )
122- , (" description" , " Constitutional Committee Hot Key Registration Certificate" )
123- ]
124- certFile
131+ H. diffFileVsGoldenFile certFile goldenCertFile
125132
126133-- | Execute me with:
127134-- @cabal test cardano-cli-golden --test-options '-p "/golden governance CommitteeCreateColdKeyResignationCertificate/"'@
128135tasty_golden_governance_CommitteeCreateColdKeyResignationCertificate :: UnitIO ()
129136tasty_golden_governance_CommitteeCreateColdKeyResignationCertificate =
130137 H. moduleWorkspace " tmp" $ \ tempDir -> do
131- ccColdVKey <- noteTempFile tempDir " cold.vkey"
132- ccColdSKey <- noteTempFile tempDir " cold.skey"
133-
138+ ccColdVKey <- noteInputFile $ inputDir </> " governance/cc-cold.vkey"
134139 certFile <- noteTempFile tempDir " hot-auth.cert"
135-
136- void $
137- execCardanoCLI
138- [ " conway"
139- , " governance"
140- , " committee"
141- , " key-gen-cold"
142- , " --verification-key-file"
143- , ccColdVKey
144- , " --signing-key-file"
145- , ccColdSKey
146- ]
140+ goldenCertFile <- noteGoldenFile " cold-key-resignation-certificate.cert"
147141
148142 void $
149143 execCardanoCLI
@@ -157,11 +151,7 @@ tasty_golden_governance_CommitteeCreateColdKeyResignationCertificate =
157151 , certFile
158152 ]
159153
160- assertHasMappings
161- [ (" type" , " CertificateConway" )
162- , (" description" , " Constitutional Committee Cold Key Resignation Certificate" )
163- ]
164- certFile
154+ H. diffFileVsGoldenFile certFile goldenCertFile
165155
166156-- | Execute me with:
167157-- @cabal test cardano-cli-golden --test-options '-p "/golden governance UpdateCommittee/"'@
@@ -186,7 +176,7 @@ tasty_golden_governance_UpdateCommittee =
186176 H. note_ proposalHash
187177 H. note_ $ show $ length proposalHash
188178
189- goldenAnswerFile <- H. note $ goldenDir </> " governance/committee/ update-committee-answer.json"
179+ goldenAnswerFile <- noteGoldenFile " update-committee-answer.json"
190180
191181 void $
192182 execCardanoCLI
@@ -227,9 +217,10 @@ tasty_golden_governance_committee_cold_extended_key_signing =
227217 skeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.cold.skey"
228218 txBody <- noteInputFile $ inputDir </> " governance/drep/extended-key-signing/tx.body"
229219
230- outGold <- H. note $ goldenDir </> " governance/committee/tx.cold.extended.signed"
231220 outFile <- H. noteTempFile tempDir " outFile"
232221
222+ goldenFile <- noteGoldenFile " tx.cold.extended.signed"
223+
233224 H. noteM_ $
234225 execCardanoCLI
235226 [ " conway"
@@ -243,7 +234,7 @@ tasty_golden_governance_committee_cold_extended_key_signing =
243234 , outFile
244235 ]
245236
246- H. diffFileVsGoldenFile outFile outGold
237+ H. diffFileVsGoldenFile outFile goldenFile
247238
248239-- | Execute me with:
249240-- @cabal test cardano-cli-golden --test-options '-p "/golden governance committee hot extended key signing/"'@
@@ -253,9 +244,10 @@ tasty_golden_governance_committee_hot_extended_key_signing =
253244 skeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.hot.skey"
254245 txBody <- noteInputFile $ inputDir </> " governance/drep/extended-key-signing/tx.body"
255246
256- outGold <- H. note $ goldenDir </> " governance/committee/tx.hot.extended.signed"
257247 outFile <- H. noteTempFile tempDir " outFile"
258248
249+ goldenFile <- noteGoldenFile " tx.hot.extended.signed"
250+
259251 H. noteM_ $
260252 execCardanoCLI
261253 [ " conway"
@@ -269,69 +261,91 @@ tasty_golden_governance_committee_hot_extended_key_signing =
269261 , outFile
270262 ]
271263
272- H. diffFileVsGoldenFile outFile outGold
264+ H. diffFileVsGoldenFile outFile goldenFile
273265
274266-- | Execute me with:
275- -- @cabal test cardano-cli-golden --test-options '-p "/golden verification key committee/"'@
276- tasty_golden_verification_key_committee :: UnitIO ()
277- tasty_golden_verification_key_committee = do
278- let values =
279- [
280- ( inputDir </> " governance/committee/cc.extended.hot.skey"
281- , goldenDir </> " governance/committee/cc.extended.hot.vkey"
282- )
283- ,
284- ( inputDir </> " governance/committee/cc.extended.cold.skey"
285- , goldenDir </> " governance/committee/cc.extended.cold.vkey"
286- )
267+ -- @cabal test cardano-cli-golden --test-options '-p "/golden hot verification key committee/"'@
268+ tasty_golden_hot_verification_key_committee :: UnitIO ()
269+ tasty_golden_hot_verification_key_committee =
270+ H. moduleWorkspace " tmp" $ \ tempDir -> do
271+ skeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.hot.skey"
272+ goldenFile <- noteGoldenFile " cc.extended.hot.vkey"
273+ vkeyFileOut <- noteTempFile tempDir " cc.extended.vkey"
274+
275+ H. noteM_ $
276+ execCardanoCLI
277+ [ " conway"
278+ , " key"
279+ , " verification-key"
280+ , " --signing-key-file"
281+ , skeyFile
282+ , " --verification-key-file"
283+ , vkeyFileOut
287284 ]
288285
289- forM_ values $ \ (skeyFile, vkeyGolden) ->
290- H. moduleWorkspace " tmp" $ \ tempDir -> do
291- vkeyFileOut <- noteTempFile tempDir " cc.extended.vkey"
286+ H. diffFileVsGoldenFile vkeyFileOut goldenFile
292287
293- H. noteM_ $
294- execCardanoCLI
295- [ " conway"
296- , " key"
297- , " verification-key"
298- , " --signing-key-file"
299- , skeyFile
300- , " --verification-key-file"
301- , vkeyFileOut
302- ]
288+ -- | Execute me with:
289+ -- @cabal test cardano-cli-golden --test-options '-p "/golden cold verification key committee/"'@
290+ tasty_golden_cold_verification_key_committee :: UnitIO ()
291+ tasty_golden_cold_verification_key_committee =
292+ H. moduleWorkspace " tmp" $ \ tempDir -> do
293+ skeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.cold.skey"
294+ goldenFile <- noteGoldenFile " cc.extended.cold.vkey"
295+ vkeyFileOut <- noteTempFile tempDir " cc.extended.vkey"
303296
304- H. diffFileVsGoldenFile vkeyFileOut vkeyGolden
297+ H. noteM_ $
298+ execCardanoCLI
299+ [ " conway"
300+ , " key"
301+ , " verification-key"
302+ , " --signing-key-file"
303+ , skeyFile
304+ , " --verification-key-file"
305+ , vkeyFileOut
306+ ]
307+
308+ H. diffFileVsGoldenFile vkeyFileOut goldenFile
305309
306310-- | Execute me with:
307- -- @cabal test cardano-cli-golden --test-options '-p "/golden governance extended committee key hash/"'@
308- tasty_golden_governance_extended_committee_key_hash :: UnitIO ()
309- tasty_golden_governance_extended_committee_key_hash =
310- let supplyValues =
311- [
312- ( inputDir </> " governance/committee/ cc.extended.cold .vkey"
313- , " 9fe92405abcd903d34e21a97328e7cd222eebd4ced5995a95777f7a3 \n "
314- )
315- ,
316- ( inputDir </> " governance/committee/cc.extended.hot.vkey "
317- , " 4eb7202ffcc6d5513dba5edc618bd7b582a257c76d6b0cd83975f4e6 \n "
318- )
319- ]
320- in forM_ supplyValues $ \ (extendedKeyFile, expected) ->
321- H. moduleWorkspace " tmp " $ \ _tempDir -> do
322- verificationKeyFile <- H. noteInputFile extendedKeyFile
311+ -- @cabal test cardano-cli-golden --test-options '-p "/golden governance extended hot committee key hash/"'@
312+ tasty_golden_governance_extended_hot_committee_key_hash :: UnitIO ()
313+ tasty_golden_governance_extended_hot_committee_key_hash = do
314+ extendedKeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.hot.vkey "
315+ verificationKeyFile <- H. noteInputFile extendedKeyFile
316+ goldenFile <- noteGoldenFile " cc.extended.hot .vkey.hash "
317+
318+ result <-
319+ execCardanoCLI
320+ [ " conway "
321+ , " governance "
322+ , " committee "
323+ , " key-hash "
324+ , " --verification-key-file "
325+ , verificationKeyFile
326+ ]
323327
324- result <-
325- execCardanoCLI
326- [ " conway"
327- , " governance"
328- , " committee"
329- , " key-hash"
330- , " --verification-key-file"
331- , verificationKeyFile
332- ]
328+ H. diffVsGoldenFile result goldenFile
329+
330+ -- | Execute me with:
331+ -- @cabal test cardano-cli-golden --test-options '-p "/golden governance extended cold committee key hash/"'@
332+ tasty_golden_governance_extended_cold_committee_key_hash :: UnitIO ()
333+ tasty_golden_governance_extended_cold_committee_key_hash = do
334+ extendedKeyFile <- noteInputFile $ inputDir </> " governance/committee/cc.extended.cold.vkey"
335+ verificationKeyFile <- noteInputFile extendedKeyFile
336+ goldenFile <- noteGoldenFile " cc.extended.cold.vkey.hash"
337+
338+ result <-
339+ execCardanoCLI
340+ [ " conway"
341+ , " governance"
342+ , " committee"
343+ , " key-hash"
344+ , " --verification-key-file"
345+ , verificationKeyFile
346+ ]
333347
334- result H. === expected
348+ H. diffVsGoldenFile result goldenFile
335349
336350-- Execute me with:
337351-- @cabal test cardano-cli-test --test-options '-p "/golden governance committee checks wrong hash fails/"'@
0 commit comments