/
Main.hs
90 lines (73 loc) · 2.76 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
module Main (main) where
import Test.Tasty
import Test.Tasty.HUnit
import qualified Cardano.Tools.DBSynthesizer.Run as DBSynthesizer
import Cardano.Tools.DBSynthesizer.Types
import qualified Cardano.Tools.DBAnalyser.Block.Cardano as Cardano
import qualified Cardano.Tools.DBAnalyser.Run as DBAnalyser
import Cardano.Tools.DBAnalyser.Types
nodeConfig, chainDB :: FilePath
nodeConfig = "test/disk/config/config.json"
chainDB = "test/disk/chaindb"
testSynthOptions :: DBSynthesizerOptions
testSynthOptions =
DBSynthesizerOptions {
synthLimit = ForgeLimitEpoch 1
, synthForceDBRemoval = True
}
testNodeFilePaths :: NodeFilePaths
testNodeFilePaths =
NodeFilePaths {
nfpConfig = nodeConfig
, nfpChainDB = chainDB
}
testNodeCredentials :: NodeCredentials
testNodeCredentials =
NodeCredentials {
credCertFile = Nothing
, credVRFFile = Nothing
, credKESFile = Nothing
, credBulkFile = Just "test/disk/config/bulk-creds-k2.json"
}
testAnalyserConfig :: DBAnalyserConfig
testAnalyserConfig =
DBAnalyserConfig {
dbDir = chainDB
, verbose = False
, selectDB = SelectChainDB
, validation = Just ValidateAllBlocks
, blockType = CardanoBlock (Cardano.CardanoBlockArgs nodeConfig Nothing)
, analysis = CountBlocks
, confLimit = Unlimited
}
-- | A multi-step test including synthesis and analaysis 'SomeConsensusProtocol' using the Cardano instance.
--
-- 1. step: synthesize a ChainDB and counts the amount of blocks forged in the proces.
-- 2. step: analyze the ChainDB from previous step and confirm the block count.
--
blockCountTest :: (String -> IO ()) -> Assertion
blockCountTest logStep = do
logStep "intializing synthesis"
(protocol, options) <- either assertFailure pure
=<< DBSynthesizer.initialize
testNodeFilePaths
testNodeCredentials
testSynthOptions
logStep "running synthesis"
resultSynth <- DBSynthesizer.synthesize protocol options
let blockCount = resultForged resultSynth
blockCount > 0 @? "no blocks have been forged"
logStep "running analysis"
resultAnalysis <- case blockType testAnalyserConfig of
CardanoBlock b -> DBAnalyser.analyse testAnalyserConfig b
_ -> assertFailure "expexcting test case for Cardano block type"
resultAnalysis == Just (ResultCountBlock blockCount) @?
"wrong number of blocks encountered during analysis \
\ (counted: " ++ show resultAnalysis ++ "; expected: " ++ show blockCount ++ ")"
tests :: TestTree
tests =
testGroup "cardano-tools"
[ testCaseSteps "synthesize and analyse: blockCount" blockCountTest
]
main :: IO ()
main = defaultMain tests