1
- {-# LANGUAGE ApplicativeDo #-}
2
- {-# LANGUAGE ConstraintKinds #-}
3
- {-# LANGUAGE DeriveGeneric #-}
4
- {-# LANGUAGE FlexibleContexts #-}
5
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
6
- {-# LANGUAGE OverloadedStrings #-}
7
- {-# LANGUAGE RankNTypes #-}
8
- {-# LANGUAGE TypeApplications #-}
9
- {-# LANGUAGE NamedFieldPuns #-}
1
+ {-# LANGUAGE ApplicativeDo #-}
2
+ {-# LANGUAGE ConstraintKinds #-}
3
+ {-# LANGUAGE DeriveGeneric #-}
4
+ {-# LANGUAGE FlexibleContexts #-}
5
+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
6
+ {-# LANGUAGE NamedFieldPuns #-}
7
+ {-# LANGUAGE OverloadedStrings #-}
8
+ {-# LANGUAGE RankNTypes #-}
9
+ {-# LANGUAGE TypeApplications #-}
10
10
11
11
module AutomatedTestRunner (Example , getGenesisConfig , loadNKeys , doUpdate , onStartup , on , getScript , runScript , NodeType (.. ), startNode ) where
12
12
@@ -19,49 +19,61 @@ import Control.Concurrent.Async.Lifted.Safe
19
19
import Control.Exception (throw )
20
20
import Control.Lens (to )
21
21
import Control.Monad.STM (orElse )
22
- import Data.Constraint (Dict (Dict ))
23
- import Data.Default (Default (def ))
22
+ import Data.Constraint (Dict (Dict ))
23
+ import Data.Default (Default (def ))
24
+ import qualified Data.HashMap.Strict as HM
24
25
import Data.Ix (range )
25
26
import Data.List ((!!) )
26
- import Data.Reflection (Given , given , give )
27
+ import qualified Data.Map as Map
28
+ import Data.Reflection (Given , give , given )
29
+ import qualified Data.Text as T
27
30
import Data.Version (showVersion )
28
- import Options.Applicative (Parser , execParser , footerDoc , fullDesc , header , help , helper , info , infoOption , long , progDesc )
29
- import Paths_cardano_sl (version )
30
- import Pos.Client.KeyStorage (getSecretKeysPlain , addSecretKey )
31
- import Pos.Crypto (emptyPassphrase , hash , hashHexF , withSafeSigners , noPassEncrypt )
32
- import Pos.DB.BlockIndex (getTipHeader )
33
- import Pos.Util.CompileInfo (CompileTimeInfo (ctiGitRevision ), HasCompileInfo , compileInfo , withCompileInfo )
34
- import Prelude (show )
35
- import Text.PrettyPrint.ANSI.Leijen (Doc )
36
- import Universum hiding (when , show , on , state )
37
- import qualified Pos.Client.CLI as CLI
38
- import Pos.Launcher (HasConfigurations , NodeParams (npBehaviorConfig , npUserSecret , npNetworkConfig ),
39
- NodeResources , WalletConfiguration ,
40
- bracketNodeResources , loggerBracket ,
41
- runNode , runRealMode , withConfigurations , InitModeContext )
42
- import Formatting (int , sformat , (%) , Format )
43
- import Graphics.Vty (mkVty , defaultConfig , defAttr )
31
+ import Formatting (Format , int , sformat , (%) )
32
+ import Graphics.Vty (defAttr , defaultConfig , mkVty )
44
33
import Ntp.Client (NtpConfiguration )
45
- import PocMode (AuxxContext (AuxxContext , acRealModeContext ), AuxxMode , realModeToAuxx )
34
+ import Options.Applicative (Parser , execParser , footerDoc , fullDesc ,
35
+ header , help , helper , info , infoOption , long , progDesc )
36
+ import Paths_cardano_sl (version )
37
+ import PocMode (AuxxContext (AuxxContext , acRealModeContext ),
38
+ AuxxMode , realModeToAuxx )
46
39
import Pos.Chain.Block (LastKnownHeaderTag )
47
- import Pos.Chain.Genesis as Genesis (Config (configGeneratedSecrets , configProtocolMagic ), configEpochSlots )
40
+ import Pos.Chain.Genesis as Genesis
41
+ (Config (configGeneratedSecrets , configProtocolMagic ),
42
+ configEpochSlots )
48
43
import Pos.Chain.Txp (TxpConfiguration )
49
- import Pos.Chain.Update (UpdateData , SystemTag , mkUpdateProposalWSign , BlockVersion , SoftwareVersion , BlockVersionModifier , updateConfiguration )
44
+ import Pos.Chain.Update (BlockVersion , BlockVersionModifier ,
45
+ SoftwareVersion , SystemTag , UpdateData ,
46
+ mkUpdateProposalWSign , updateConfiguration )
47
+ import qualified Pos.Client.CLI as CLI
48
+ import Pos.Client.KeyStorage (addSecretKey , getSecretKeysPlain )
50
49
import Pos.Client.Update.Network (submitUpdateProposal )
51
- import Pos.Core (LocalSlotIndex , SlotId (SlotId , siEpoch , siSlot ), mkLocalSlotIndex , EpochIndex (EpochIndex ), SlotCount , getEpochIndex , getSlotIndex , difficultyL , getChainDifficulty , getBlockCount , getEpochOrSlot )
50
+ import Pos.Core (EpochIndex (EpochIndex ), LocalSlotIndex , SlotCount ,
51
+ SlotId (SlotId , siEpoch , siSlot ), difficultyL ,
52
+ getBlockCount , getChainDifficulty , getEpochIndex ,
53
+ getEpochOrSlot , getSlotIndex , mkLocalSlotIndex )
54
+ import Pos.Crypto (emptyPassphrase , hash , hashHexF , noPassEncrypt ,
55
+ withSafeSigners )
56
+ import Pos.DB.BlockIndex (getTipHeader )
52
57
import Pos.DB.DB (initNodeDBs )
53
58
import Pos.DB.Txp (txpGlobalSettings )
54
59
import Pos.Infra.Diffusion.Types (Diffusion , hoistDiffusion )
55
- import Pos.Infra.Network.Types (NetworkConfig (ncTopology , ncEnqueuePolicy , ncDequeuePolicy , ncFailurePolicy ), Topology (TopologyAuxx ), topologyDequeuePolicy , topologyEnqueuePolicy , topologyFailurePolicy , NodeId )
60
+ import Pos.Infra.Network.Types (NetworkConfig (ncDequeuePolicy , ncEnqueuePolicy , ncFailurePolicy , ncTopology ),
61
+ NodeId , Topology (TopologyAuxx ), topologyDequeuePolicy ,
62
+ topologyEnqueuePolicy , topologyFailurePolicy )
56
63
import Pos.Infra.Shutdown (triggerShutdown )
57
- import Pos.Infra.Slotting.Util (onNewSlot , defaultOnNewSlotParams )
58
- import Pos.Util (logException , lensOf )
59
- import Pos.Util.UserSecret (usVss , readUserSecret , usPrimKey , usKeys )
64
+ import Pos.Infra.Slotting.Util (defaultOnNewSlotParams , onNewSlot )
65
+ import Pos.Launcher (HasConfigurations , InitModeContext , NodeParams (npBehaviorConfig , npNetworkConfig , npUserSecret ),
66
+ NodeResources , WalletConfiguration , bracketNodeResources ,
67
+ loggerBracket , runNode , runRealMode , withConfigurations )
68
+ import Pos.Util (lensOf , logException )
69
+ import Pos.Util.CompileInfo (CompileTimeInfo (ctiGitRevision ),
70
+ HasCompileInfo , compileInfo , withCompileInfo )
71
+ import Pos.Util.UserSecret (readUserSecret , usKeys , usPrimKey , usVss )
60
72
import Pos.Util.Wlog (LoggerName )
61
- import Pos.WorkMode (RealMode , EmptyMempoolExt )
62
- import qualified Data.HashMap.Strict as HM
63
- import qualified Data.Map as Map
64
- import qualified Data.Text as T
73
+ import Pos.WorkMode (EmptyMempoolExt , RealMode )
74
+ import Prelude ( show )
75
+ import Text.PrettyPrint.ANSI.Leijen ( Doc )
76
+ import Universum hiding ( on , show , state , when )
65
77
66
78
class TestScript a where
67
79
getScript :: a -> Script
@@ -72,16 +84,16 @@ data ScriptRunnerOptions = ScriptRunnerOptions
72
84
} deriving Show
73
85
74
86
data ScriptBuilder = ScriptBuilder
75
- { sbScript :: Script
76
- , sbEpochSlots :: SlotCount
87
+ { sbScript :: Script
88
+ , sbEpochSlots :: SlotCount
77
89
, sbGenesisConfig :: Config
78
90
}
79
91
data NodeType = Core { ntIdex :: Integer }
80
92
81
93
instance Default Script where def = Script def def
82
94
83
95
data Script = Script
84
- { slotTriggers :: Map. Map SlotId SlotTrigger
96
+ { slotTriggers :: Map. Map SlotId SlotTrigger
85
97
, startupActions :: [ SlotTrigger ]
86
98
} deriving (Show , Generic )
87
99
@@ -220,7 +232,7 @@ worker2 eventChan diffusion = do
220
232
globalHeight = view (difficultyL . to getChainDifficulty) <$> mbHeader
221
233
localHeight = view (difficultyL . to getChainDifficulty) localTip
222
234
f (Just v) = Just $ getBlockCount v
223
- f Nothing = Nothing
235
+ f Nothing = Nothing
224
236
liftIO $ do
225
237
writeBChan eventChan $ CENodeInfo $ NodeInfo (getBlockCount localHeight) (getEpochOrSlot localTip) (f globalHeight)
226
238
threadDelay 100000
@@ -234,7 +246,7 @@ worker1 genesisConfig script eventChan diffusion = do
234
246
liftIO $ writeBChan eventChan $ CESlotStart $ SlotStart (getEpochIndex $ siEpoch slotid) (getSlotIndex $ siSlot slotid)
235
247
case Map. lookup slotid (slotTriggers realScript) of
236
248
Just (SlotTrigger act) -> runAction act
237
- Nothing -> pure ()
249
+ Nothing -> pure ()
238
250
pure ()
239
251
realScript = getScript script
240
252
errhandler :: Show e => e -> AuxxMode ()
@@ -249,14 +261,14 @@ worker1 genesisConfig script eventChan diffusion = do
249
261
realWorker `catch` errhandler @ SomeException
250
262
251
263
data TestScript a => InputParams a = InputParams
252
- { ipEventChan :: BChan CustomEvent
253
- , ipReplyChan :: BChan Reply
264
+ { ipEventChan :: BChan CustomEvent
265
+ , ipReplyChan :: BChan Reply
254
266
, ipScriptGetter :: HasEpochSlots => IO a
255
267
}
256
268
data TestScript a => InputParams2 a = InputParams2
257
269
{ ip2EventChan :: BChan CustomEvent
258
270
, ip2ReplyChan :: BChan Reply
259
- , ip2Script :: a
271
+ , ip2Script :: a
260
272
}
261
273
262
274
runScript :: TestScript a => (HasEpochSlots => IO a ) -> IO ()
@@ -297,9 +309,7 @@ runUI = do
297
309
pure (eventChan, replyChan, brick)
298
310
299
311
getGenesisConfig :: Example Config
300
- getGenesisConfig = do
301
- oldsb <- get
302
- pure $ sbGenesisConfig oldsb
312
+ getGenesisConfig = sbGenesisConfig <$> get
303
313
304
314
data SlotCreationFailure = SlotCreationFailure { msg :: Text , slotsInEpoch :: SlotCount } deriving Show
305
315
instance Exception SlotCreationFailure where
@@ -338,7 +348,6 @@ on (epoch, slot) action = do
338
348
sbScript = script
339
349
}
340
350
put newsb
341
- pure ()
342
351
343
352
doUpdate :: HasConfigurations => Diffusion AuxxMode -> Config -> Int -> BlockVersion -> SoftwareVersion -> BlockVersionModifier -> AuxxMode ()
344
353
doUpdate diffusion genesisConfig keyIndex blockVersion softwareVersion blockVersionModifier = do
0 commit comments