Skip to content

Commit 24bafb6

Browse files
iohk-bors[bot]intricatenewhoggyJames Browning
authored
4915: Tip hash metrics r=newhoggy a=newhoggy Salvaging this PR #2006 Related to #801 4918: Fix key non extended key for StakeExtendedVerificationKeyShelley_ed25519_bip32 envelope r=newhoggy a=newhoggy * Fix key non extended key for `StakeExtendedVerificationKeyShelley_ed25519_bip32` envelope * Add ability to generate golden files from test using `CREATE_GOLDEN_FILES=1` * New `diffFileVsGoldenFile` function Resolves #4914 4922: Deploy Haddock for merge to master only r=newhoggy a=newhoggy To merge changes from this PR #3012 Co-authored-by: Luke Nadur <[email protected]> Co-authored-by: John Ky <[email protected]> Co-authored-by: James Browning <[email protected]>
4 parents 3b21b2d + 57612b7 + 4c180c8 + 6ce865c commit 24bafb6

File tree

12 files changed

+304
-60
lines changed

12 files changed

+304
-60
lines changed

.github/workflows/github-page.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: "Haddock documentation"
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
47

58
jobs:
69
build:

cardano-api/src/Cardano/Api/DeserialiseAnyOf.hs

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ deserialiseAnyVerificationKeyTextEnvelope bs =
310310
[ FromSomeType (AsVerificationKey AsByronKey) AByronVerificationKey
311311
, FromSomeType (AsVerificationKey AsPaymentKey) APaymentVerificationKey
312312
, FromSomeType (AsVerificationKey AsPaymentExtendedKey) APaymentExtendedVerificationKey
313+
, FromSomeType (AsVerificationKey AsStakeExtendedKey) AStakeExtendedVerificationKey
313314
, FromSomeType (AsVerificationKey AsGenesisUTxOKey) AGenesisUTxOVerificationKey
314315
, FromSomeType (AsVerificationKey AsGenesisExtendedKey) AGenesisExtendedVerificationKey
315316
]

cardano-cli/test/Test/Golden/Key.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@ keyTests :: IO Bool
1212
keyTests =
1313
H.checkSequential
1414
$ H.Group "Key command group"
15-
[ ("golden_KeyNonExtendedKey", Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey)
15+
[ ( "golden_KeyNonExtendedKey_GenesisExtendedVerificationKey"
16+
, Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey_GenesisExtendedVerificationKey
17+
)
18+
, ( "golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley"
19+
, Test.Golden.Key.NonExtendedKey.golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley
20+
)
1621
]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

33
module Test.Golden.Key.NonExtendedKey
4-
( golden_KeyNonExtendedKey
4+
( golden_KeyNonExtendedKey_GenesisExtendedVerificationKey
5+
, golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley
56
) where
67

78
import Control.Monad (void)
@@ -10,30 +11,52 @@ import qualified Hedgehog.Extras.Test.Base as H
1011
import qualified Hedgehog.Extras.Test.File as H
1112
import System.FilePath ((</>))
1213
import Test.OptParse (execCardanoCLI, propertyOnce)
13-
import Test.Utilities (diffVsGoldenFile)
14+
import Test.Utilities (diffFileVsGoldenFile)
1415

1516
{- HLINT ignore "Use camelCase" -}
1617

1718
-- | Test that converting a @cardano-address@ Byron signing key yields the
1819
-- expected result.
19-
golden_KeyNonExtendedKey :: Property
20-
golden_KeyNonExtendedKey =
20+
golden_KeyNonExtendedKey_GenesisExtendedVerificationKey :: Property
21+
golden_KeyNonExtendedKey_GenesisExtendedVerificationKey =
2122
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
2223
genesisVKeyFp <- H.note "test/data/golden/key/non-extended-keys/shelley.000.vkey"
23-
nonExtendedGenesisVKeyFp <- H.note $ tempDir </> "non-extended-shelley.000.vkey"
24+
nonExtendedFp <- H.note "test/data/golden/key/non-extended-keys/non-extended-shelley.000.vkey"
25+
outFp <- H.note $ tempDir </> "non-extended-shelley.000.vkey"
2426

2527
H.assertFilesExist [genesisVKeyFp]
2628

2729
-- Convert the `cardano-address` signing key
2830
void $ execCardanoCLI
2931
[ "key", "non-extended-key"
3032
, "--extended-verification-key-file", genesisVKeyFp
31-
, "--verification-key-file", nonExtendedGenesisVKeyFp
33+
, "--verification-key-file", outFp
3234
]
3335

3436
-- Check for existence of the converted signing key file
35-
H.assertFilesExist [nonExtendedGenesisVKeyFp]
37+
H.assertFilesExist [outFp]
3638

37-
contents <- H.readFile nonExtendedGenesisVKeyFp
39+
diffFileVsGoldenFile outFp nonExtendedFp
3840

39-
diffVsGoldenFile contents nonExtendedGenesisVKeyFp
41+
-- | Test that converting a @cardano-address@ Byron signing key yields the
42+
-- expected result.
43+
golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley :: Property
44+
golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley =
45+
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
46+
genesisVKeyFp <- H.note "test/data/golden/key/non-extended-keys/stake.000.vkey"
47+
nonExtendedFp <- H.note "test/data/golden/key/non-extended-keys/non-extended-stake.000.vkey"
48+
outFp <- H.note $ tempDir </> "non-extended-stake.000.vkey"
49+
50+
H.assertFilesExist [genesisVKeyFp]
51+
52+
-- Convert the `cardano-address` signing key
53+
void $ execCardanoCLI
54+
[ "key", "non-extended-key"
55+
, "--extended-verification-key-file", genesisVKeyFp
56+
, "--verification-key-file", outFp
57+
]
58+
59+
-- Check for existence of the converted signing key file
60+
H.assertFilesExist [outFp]
61+
62+
diffFileVsGoldenFile outFp nonExtendedFp

cardano-cli/test/Test/Utilities.hs

+72-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,87 @@
1-
module Test.Utilities (diffVsGoldenFile) where
1+
module Test.Utilities
2+
( diffVsGoldenFile,
3+
diffFileVsGoldenFile,
4+
) where
25

3-
import Cardano.Prelude (ConvertText (..))
6+
import Cardano.Prelude (ConvertText (..), HasCallStack)
47

58
import Control.Monad.IO.Class (MonadIO (liftIO))
69
import Data.Algorithm.Diff (PolyDiff (Both), getGroupedDiff)
710
import Data.Algorithm.DiffOutput (ppDiff)
811
import GHC.Stack (callStack)
12+
import qualified GHC.Stack as GHC
913
import Hedgehog (MonadTest)
14+
import qualified Hedgehog.Extras.Test as H
1015
import Hedgehog.Extras.Test.Base (failMessage)
16+
import qualified Hedgehog.Internal.Property as H
17+
import qualified System.Directory as IO
18+
import qualified System.Environment as IO
19+
import qualified System.IO.Unsafe as IO
1120

21+
-- | Whether the test should create the golden files if the file does ont exist.
22+
createFiles :: Bool
23+
createFiles = IO.unsafePerformIO $ do
24+
value <- IO.lookupEnv "CREATE_GOLDEN_FILES"
25+
return $ value == Just "1"
26+
27+
-- | Diff contents against the golden file. If CREATE_GOLDEN_FILES environment is
28+
-- set to "1", then should the gold file not exist it would be created.
29+
--
30+
-- Set the environment variable when you intend to generate or re-generate the golden
31+
-- file for example when running the test for the first time or if the golden file
32+
-- genuinely needs to change.
33+
--
34+
-- To re-generate a golden file you must also delete the golden file because golden
35+
-- files are never overwritten.
36+
--
1237
-- TODO: Improve the help output by saying the difference of
1338
-- each input.
1439
diffVsGoldenFile
15-
:: (MonadIO m, MonadTest m)
16-
=> String -- ^ actual content
17-
-> FilePath -- ^ reference file
40+
:: HasCallStack
41+
=> (MonadIO m, MonadTest m)
42+
=> String -- ^ Actual content
43+
-> FilePath -- ^ Reference file
1844
-> m ()
19-
diffVsGoldenFile actualContent referenceFile =
20-
do
21-
referenceLines <- map toS . lines <$> liftIO (readFile referenceFile)
22-
let difference = getGroupedDiff actualLines referenceLines
23-
case difference of
24-
[Both{}] -> pure ()
25-
_ -> failMessage callStack $ ppDiff difference
45+
diffVsGoldenFile actualContent referenceFile = GHC.withFrozenCallStack $ do
46+
fileExists <- liftIO $ IO.doesFileExist referenceFile
47+
48+
if fileExists
49+
then do
50+
referenceLines <- map toS . lines <$> H.readFile referenceFile
51+
let difference = getGroupedDiff actualLines referenceLines
52+
case difference of
53+
[Both{}] -> pure ()
54+
_ -> failMessage callStack $ ppDiff difference
55+
else if createFiles
56+
then do
57+
-- CREATE_GOLDEN_FILES is set, so we create any golden files that don't
58+
-- already exist.
59+
H.note_ $ "Creating golden file " <> referenceFile
60+
H.writeFile referenceFile actualContent
61+
else do
62+
H.note_ $ mconcat
63+
[ "Golden file " <> referenceFile
64+
, " does not exist. To create, run with CREATE_GOLDEN_FILES=1"
65+
]
66+
H.failure
2667
where
2768
actualLines = Prelude.lines actualContent
69+
70+
-- | Diff file against the golden file. If CREATE_GOLDEN_FILES environment is
71+
-- set to "1", then should the gold file not exist it would be created.
72+
--
73+
-- Set the environment variable when you intend to generate or re-generate the golden
74+
-- file for example when running the test for the first time or if the golden file
75+
-- genuinely needs to change.
76+
--
77+
-- To re-generate a golden file you must also delete the golden file because golden
78+
-- files are never overwritten.
79+
diffFileVsGoldenFile
80+
:: HasCallStack
81+
=> (MonadIO m, MonadTest m)
82+
=> FilePath -- ^ Actual file
83+
-> FilePath -- ^ Reference file
84+
-> m ()
85+
diffFileVsGoldenFile actualFile referenceFile = GHC.withFrozenCallStack $ do
86+
contents <- H.readFile actualFile
87+
diffVsGoldenFile contents referenceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "GenesisVerificationKey_ed25519",
3+
"description": "",
4+
"cborHex": "58200834b58f4bdda9522bb202af1f546db4cbbd94b068ae72c9fd96d9b55279edf0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "StakeVerificationKeyShelley_ed25519",
3+
"description": "",
4+
"cborHex": "58200f205175c0a47cba409c328f066e31ea4e81ef211f539c12b64b4b14e1d87188"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "StakeExtendedVerificationKeyShelley_ed25519_bip32",
3+
"description": "",
4+
"cborHex": "58400f205175c0a47cba409c328f066e31ea4e81ef211f539c12b64b4b14e1d87188a54f03c3edad073428f37dbdad714b7c07371ca19fe66c72d41fda23a81d8309"
5+
}

cardano-node/cardano-node.cabal

+24-22
Original file line numberDiff line numberDiff line change
@@ -70,61 +70,62 @@ library
7070
Cardano.Node.Handlers.Shutdown
7171
Cardano.Node.Handlers.TopLevel
7272
Cardano.Node.Orphans
73+
Cardano.Node.Parsers
7374
Cardano.Node.Protocol
7475
Cardano.Node.Protocol.Alonzo
7576
Cardano.Node.Protocol.Byron
7677
Cardano.Node.Protocol.Cardano
7778
Cardano.Node.Protocol.Shelley
7879
Cardano.Node.Protocol.Types
79-
Cardano.Node.Parsers
8080
Cardano.Node.Queries
8181
Cardano.Node.Run
82-
Cardano.Node.STM
8382
Cardano.Node.Startup
83+
Cardano.Node.STM
8484
Cardano.Node.TraceConstraints
8585
Cardano.Node.Tracing
86-
Cardano.Node.Types
8786
Cardano.Node.Tracing.API
8887
Cardano.Node.Tracing.Compat
8988
Cardano.Node.Tracing.DefaultTraceConfig
9089
Cardano.Node.Tracing.Documentation
9190
Cardano.Node.Tracing.Era.Byron
9291
Cardano.Node.Tracing.Era.HardFork
9392
Cardano.Node.Tracing.Era.Shelley
93+
Cardano.Node.Tracing.Formatting
9494
Cardano.Node.Tracing.Peers
95+
Cardano.Node.Tracing.Render
9596
Cardano.Node.Tracing.StateRep
9697
Cardano.Node.Tracing.Tracers
9798
Cardano.Node.Tracing.Tracers.BlockReplayProgress
9899
Cardano.Node.Tracing.Tracers.ChainDB
99100
Cardano.Node.Tracing.Tracers.Consensus
100101
Cardano.Node.Tracing.Tracers.ConsensusStartupException
101102
Cardano.Node.Tracing.Tracers.Diffusion
102-
Cardano.Node.Tracing.Tracers.KESInfo
103-
Cardano.Node.Tracing.Tracers.StartLeadershipCheck
104103
Cardano.Node.Tracing.Tracers.ForgingThreadStats
105-
Cardano.Node.Tracing.Tracers.Resources
106-
Cardano.Node.Tracing.Tracers.Peer
107-
Cardano.Node.Tracing.Tracers.Startup
108-
Cardano.Node.Tracing.Tracers.Shutdown
109-
Cardano.Node.Tracing.Tracers.P2P
110-
Cardano.Node.Tracing.Tracers.NonP2P
104+
Cardano.Node.Tracing.Tracers.KESInfo
111105
Cardano.Node.Tracing.Tracers.NodeToClient
112106
Cardano.Node.Tracing.Tracers.NodeToNode
113-
Cardano.Node.Tracing.Formatting
114-
Cardano.Node.Tracing.Render
107+
Cardano.Node.Tracing.Tracers.NonP2P
108+
Cardano.Node.Tracing.Tracers.P2P
109+
Cardano.Node.Tracing.Tracers.Peer
110+
Cardano.Node.Tracing.Tracers.Resources
111+
Cardano.Node.Tracing.Tracers.Shutdown
112+
Cardano.Node.Tracing.Tracers.StartLeadershipCheck
113+
Cardano.Node.Tracing.Tracers.Startup
114+
Cardano.Node.Types
115115
Cardano.Tracing.Config
116+
Cardano.Tracing.HasIssuer
116117
Cardano.Tracing.Metrics
117-
Cardano.Tracing.Peer
118-
Cardano.Tracing.Render
119-
Cardano.Tracing.Startup
120-
Cardano.Tracing.Shutdown
121-
Cardano.Tracing.Tracers
122118
Cardano.Tracing.OrphanInstances.Byron
123119
Cardano.Tracing.OrphanInstances.Common
124120
Cardano.Tracing.OrphanInstances.Consensus
125121
Cardano.Tracing.OrphanInstances.HardFork
126122
Cardano.Tracing.OrphanInstances.Network
127123
Cardano.Tracing.OrphanInstances.Shelley
124+
Cardano.Tracing.Peer
125+
Cardano.Tracing.Render
126+
Cardano.Tracing.Shutdown
127+
Cardano.Tracing.Startup
128+
Cardano.Tracing.Tracers
128129

129130
other-modules: Paths_cardano_node
130131
autogen-modules: Paths_cardano_node
@@ -139,18 +140,19 @@ library
139140
, cardano-git-rev
140141
, cardano-crypto-class
141142
, cardano-crypto-wrapper
142-
, cardano-ledger-core
143+
, cardano-ledger-alonzo
144+
, cardano-ledger-babbage
143145
, cardano-ledger-byron
146+
, cardano-ledger-core
144147
, cardano-ledger-shelley
145148
, cardano-ledger-shelley-ma
146-
, cardano-ledger-alonzo
147-
, cardano-ledger-babbage
148149
, cardano-prelude
149150
, cardano-protocol-tpraos ^>= 0.1
150151
, cardano-slotting ^>= 0.1
151152
, cborg ^>= 0.2.4
152153
, contra-tracer
153154
, containers
155+
, contra-tracer
154156
, deepseq
155157
, directory
156158
, dns
@@ -159,9 +161,9 @@ library
159161
, filepath
160162
, generic-data
161163
, hostname
162-
, iproute
163164
, io-classes ^>= 0.3
164165
, iohk-monitoring
166+
, iproute
165167
, lobemo-backend-aggregation
166168
, lobemo-backend-ekg
167169
, lobemo-backend-monitoring

cardano-node/src/Cardano/Node/TraceConstraints.hs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE ConstraintKinds #-}
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE FlexibleContexts #-}
4+
45
module Cardano.Node.TraceConstraints (TraceConstraints) where
56

67

@@ -10,6 +11,7 @@ import Cardano.BM.Tracing (ToObject)
1011
import Cardano.Logging (LogFormatting)
1112
import Cardano.Node.Queries (ConvertTxId, GetKESInfo (..), HasKESInfo (..),
1213
HasKESMetricsData (..), LedgerQueries)
14+
import Cardano.Tracing.HasIssuer (HasIssuer)
1315

1416
import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateUpdateError,
1517
Header)
@@ -25,6 +27,8 @@ import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId)
2527
-- | Tracing-related constraints for monitoring purposes.
2628
type TraceConstraints blk =
2729
( ConvertTxId blk
30+
, HasIssuer blk
31+
, HasKESMetricsData blk
2832
, HasTxs blk
2933
, HasTxId (GenTx blk)
3034
, LedgerQueries blk

0 commit comments

Comments
 (0)