@@ -28,23 +28,32 @@ import Test.Tasty
28
28
29
29
newtype CDDLSpec = CDDLSpec { cddlSpec :: BS. ByteString} deriving Show
30
30
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.
31
35
withCDDLs :: TestTree -> TestTree
32
36
withCDDLs f =
33
37
withResource
34
38
( do
35
39
probeTools
36
40
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
41
48
)
42
49
( \ () -> do
43
50
D. removeFile " ntnblock.cddl"
44
51
D. removeFile " ntnheader.cddl"
45
52
)
46
53
(\ _ -> f)
47
54
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.
48
57
fixupBlockCDDL :: CDDLSpec -> IO CDDLSpec
49
58
fixupBlockCDDL spec =
50
59
withTempFile " ." " block-temp.cddl" $ \ fp h -> do
@@ -64,6 +73,7 @@ fixupBlockCDDL spec =
64
73
]
65
74
CDDLSpec <$> BS. readFile fp
66
75
76
+ -- | This sets the environment variables needed for `cddlc` to run properly.
67
77
setupCDDLCEnv :: IO ()
68
78
setupCDDLCEnv = do
69
79
byron <- map takePath <$> Byron. readByronCddlFileNames
@@ -95,6 +105,7 @@ setupCDDLCEnv = do
95
105
96
106
E. setEnv " CDDL_INCLUDE_PATH" (include_path <> " :" )
97
107
108
+ -- | Call @sed@ on the given file with the given args
98
109
sed :: FilePath -> [String ] -> IO ()
99
110
sed fp args =
100
111
Monad. void $ P. readProcessWithExitCode " sed" (args ++ [fp]) mempty
0 commit comments