Skip to content

Commit e381346

Browse files
committed
Some cleanup from code-review
1 parent 9701802 commit e381346

File tree

1 file changed

+15
-4
lines changed
  • ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano

1 file changed

+15
-4
lines changed

ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/GenCDDLs.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,32 @@ import Test.Tasty
2828

2929
newtype CDDLSpec = CDDLSpec {cddlSpec :: BS.ByteString} deriving Show
3030

31+
-- | This function will run the provided test-tree after generating the node to
32+
-- node cddls for Blocks and Headers. As more CDDLs are stabilized they will
33+
-- have to be added here. Eventually we can have a datatype with one field for
34+
-- each CDDL so that we know always what is available.
3135
withCDDLs :: TestTree -> TestTree
3236
withCDDLs f =
3337
withResource
3438
( do
3539
probeTools
3640
setupCDDLCEnv
37-
BS.writeFile "ntnblock.cddl" . cddlSpec
38-
=<< (cddlc "cddl/node-to-node/blockfetch/block.cddl" >>= fixupBlockCDDL)
39-
BS.writeFile "ntnheader.cddl" . cddlSpec
40-
=<< cddlc "cddl/node-to-node/chainsync/header.cddl"
41+
42+
ntnBlock <- cddlc "cddl/node-to-node/blockfetch/block.cddl"
43+
ntnBlock' <- fixupBlockCDDL ntnBlock
44+
BS.writeFile "ntnblock.cddl" . cddlSpec $ ntnBlock
45+
46+
ntnHeader <- cddlc "cddl/node-to-node/chainsync/header.cddl"
47+
BS.writeFile "ntnheader.cddl" . cddlSpec $ ntnHeader
4148
)
4249
( \() -> do
4350
D.removeFile "ntnblock.cddl"
4451
D.removeFile "ntnheader.cddl"
4552
)
4653
(\_ -> f)
4754

55+
-- | The Ledger CDDL specs are not _exactly_ correct. Here we do some dirty
56+
-- sed-replace to make them able to validate blocks. See cardano-ledger#5054.
4857
fixupBlockCDDL :: CDDLSpec -> IO CDDLSpec
4958
fixupBlockCDDL spec =
5059
withTempFile "." "block-temp.cddl" $ \fp h -> do
@@ -64,6 +73,7 @@ fixupBlockCDDL spec =
6473
]
6574
CDDLSpec <$> BS.readFile fp
6675

76+
-- | This sets the environment variables needed for `cddlc` to run properly.
6777
setupCDDLCEnv :: IO ()
6878
setupCDDLCEnv = do
6979
byron <- map takePath <$> Byron.readByronCddlFileNames
@@ -95,6 +105,7 @@ setupCDDLCEnv = do
95105

96106
E.setEnv "CDDL_INCLUDE_PATH" (include_path <> ":")
97107

108+
-- | Call @sed@ on the given file with the given args
98109
sed :: FilePath -> [String] -> IO ()
99110
sed fp args =
100111
Monad.void $ P.readProcessWithExitCode "sed" (args ++ [fp]) mempty

0 commit comments

Comments
 (0)