Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 8b5321c

Browse files
author
Michael Hueschen
committed
[CBR-503] Refactor script-runner testcases; fix testHFM
I had repeated myself in `testHardForkMechanism`, by copying the body of `test4`. Due to (what seems like) a botched rebase, my CBR-503 PR was broken, and because of the duplication, I didn't catch it in review. This commit factors out the shared logic, and does checking (`confSetBvAndSv`) to make sure proposals are sane. I also fix `testHFM` by making the BlockVersions and SoftwareVersions agree.
1 parent cc02eed commit 8b5321c

File tree

2 files changed

+73
-87
lines changed

2 files changed

+73
-87
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
### Features
1313

1414
- Support for (unused) addresses batch import ([CO-448](https://iohk.myjetbrains.com/youtrack/issue/CO-448) [#4040](https://github.com/input-output-hk/cardano-sl/pull/4040))
15-
16-
- Add `script-runner` tool to automate cluster-level testing ([DEVOPS-1131](https://iohk.myjetbrains.com/youtrack/v2/issue/devops-1131): [#3916](https://github.com/input-output-hk/cardano-sl/pull/3916) [#4057](https://github.com/input-output-hk/cardano-sl/pull/4057))
15+
- Add `script-runner` tool to automate cluster-level testing ([DEVOPS-1131](https://iohk.myjetbrains.com/youtrack/v2/issue/devops-1131): [#3916](https://github.com/input-output-hk/cardano-sl/pull/3916) [#4057](https://github.com/input-output-hk/cardano-sl/pull/4057)) ([CBR-503](https://iohk.myjetbrains.com/youtrack/issue/CBR-503): [#4061](https://github.com/input-output-hk/cardano-sl/pull/4061) [#4073](https://github.com/input-output-hk/cardano-sl/pull/4073))
1716

1817
- Node Monitoring API: nodes now serve their own settings and info via a web server via a `/api/v1/node-settings` and `/api/v1/node-info` (still proxied by the wallet backend) ([#110](https://github.com/input-output-hk/cardano-wallet/issues/110))
1918
- Set up scaffolding for node API [#3788](https://github.com/input-output-hk/cardano-sl/pull/3788)

script-runner/TestCases.hs

+72-85
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import Pos.Chain.Update (ApplicationName (ApplicationName),
2020
BlockVersion (BlockVersion),
2121
BlockVersionData (bvdMaxBlockSize, bvdUnlockStakeEpoch),
2222
BlockVersionModifier (bvmMaxBlockSize, bvmUnlockStakeEpoch),
23-
SoftwareVersion (SoftwareVersion), UpdateConfiguration,
24-
ccApplicationVersion_L, ccLastKnownBlockVersion_L,
25-
obftEraFlagValue)
23+
SoftwareVersion (..), UpdateConfiguration,
24+
ccApplicationName_L, ccApplicationVersion_L,
25+
ccLastKnownBlockVersion_L, obftEraFlagValue)
2626
import qualified Pos.Client.CLI as CLI
2727
import Pos.Core.Slotting (EpochIndex)
2828
import Pos.DB.Class (gsAdoptedBVData)
@@ -42,15 +42,18 @@ import Types (NodeType (..))
4242

4343
import Serokell.Data.Memory.Units (Byte)
4444

45-
mutateConfiguration :: Configuration -> Configuration
46-
mutateConfiguration cfg = (cfg & ccUpdate_L . ccLastKnownBlockVersion_L .~ BlockVersion 0 1 0) & ccUpdate_L . ccApplicationVersion_L .~ 1
45+
-- | Helper to make sure BV and SV are set in accordance with the arguments passed in
46+
confSetBvAndSv :: BlockVersion -> SoftwareVersion -> Configuration -> Configuration
47+
confSetBvAndSv bv sv cfg = ((cfg & ccUpdate_L . ccLastKnownBlockVersion_L .~ bv)
48+
& ccUpdate_L . ccApplicationVersion_L .~ (svNumber sv))
49+
& ccUpdate_L . ccApplicationName_L .~ (svAppName sv)
4750

4851
mutateConfigurationForObft :: Configuration -> Configuration
49-
mutateConfigurationForObft cfg = (cfg & ccUpdate_L . ccLastKnownBlockVersion_L .~ BlockVersion 1 0 0) & over ccGenesis_L (updateUnlockStakeEpoch obftEraFlagValue)
50-
51-
updateUnlockStakeEpoch :: EpochIndex -> StaticConfig -> StaticConfig
52-
updateUnlockStakeEpoch ei (GCSrc _ _) = error "updateUnlockStakeEpoch: got GCSrc"
53-
updateUnlockStakeEpoch ei (GCSpec gs) = GCSpec (gs { gsBlockVersionData = ((gsBlockVersionData gs) { bvdUnlockStakeEpoch = ei })})
52+
mutateConfigurationForObft = over ccGenesis_L (updateUnlockStakeEpoch obftEraFlagValue)
53+
where
54+
updateUnlockStakeEpoch :: EpochIndex -> StaticConfig -> StaticConfig
55+
updateUnlockStakeEpoch _ (GCSrc _ _) = error "updateUnlockStakeEpoch: got GCSrc"
56+
updateUnlockStakeEpoch ei (GCSpec gs) = GCSpec (gs { gsBlockVersionData = ((gsBlockVersionData gs) { bvdUnlockStakeEpoch = ei })})
5457

5558
data ExpectedResult = SuccessFullUpdate | FailedProposalUpdate deriving (Show, Eq)
5659

@@ -60,81 +63,23 @@ data ExpectedResult = SuccessFullUpdate | FailedProposalUpdate deriving (Show, E
6063
logMsg :: String -> PocMode ()
6164
logMsg = liftIO . hPutStrLn stderr
6265

63-
{-# ANN testHardForkMechanism ("HLint: ignore Reduce duplication" :: Text) #-}
64-
testHardForkMechanism :: Script ()
65-
testHardForkMechanism = do
66-
genesisConfig <- getGenesisConfig
67-
let
68-
proposal :: Dict HasConfigurations -> Diffusion PocMode -> PocMode ()
69-
proposal Dict diffusion = do
70-
let
71-
keyIndex :: Int
72-
keyIndex = 0
73-
blockVersion = BlockVersion 0 1 0
74-
softwareVersion = SoftwareVersion (ApplicationName "cardano-sl") 1
75-
blockVersionModifier :: BlockVersionModifier
76-
blockVersionModifier = def { bvmUnlockStakeEpoch = Just obftEraFlagValue }
77-
doUpdate diffusion genesisConfig keyIndex blockVersion softwareVersion blockVersionModifier
78-
expectedResult = SuccessFullUpdate
79-
onStartup $ \Dict _diffusion -> do
80-
stateDir <- view acStatePath
81-
loadNKeys stateDir 4
82-
on (1,2) proposal
83-
on (2,6) $ \Dict _diffusion -> do
84-
uc <- view (lensOf @UpdateConfiguration)
85-
proposals <- GS.getConfirmedProposals uc Nothing
86-
case (proposals, expectedResult) of
87-
([], FailedProposalUpdate) -> do
88-
logMsg "expected failed proposal, passing test"
89-
endScript ExitSuccess
90-
(_, FailedProposalUpdate) -> do
91-
logMsg "expected failure, but proposal was accepted!"
92-
endScript $ ExitFailure 1
93-
([], _) -> do
94-
logMsg "expected proposal to pass, but it didnt"
95-
endScript $ ExitFailure 2
96-
([_one], SuccessFullUpdate) -> do
97-
stateDir <- view acStatePath
98-
opts <- view acScriptOptions
99-
let
100-
-- the config for the script-runner is mirrored to the nodes it starts
101-
cfg = opts ^. srCommonNodeArgs . CLI.commonArgs_L
102-
newConfiguration <- liftIO $ mutateConfigurationYaml (cfg ^. CLI.configurationOptions_L . cfoFilePath_L) (cfg ^. CLI.configurationOptions_L . cfoKey_L) mutateConfigurationForObft
103-
liftIO $ BS.writeFile (T.unpack $ stateDir <> "/configuration2.yaml") newConfiguration
104-
let
105-
cfg2 = cfg & CLI.configurationOptions_L . cfoFilePath_L .~ (T.unpack $ stateDir <> "/configuration2.yaml")
106-
forAllNodes_ $ \node -> do
107-
stopNodeByName (Core, node)
108-
startNode $ NodeInfo node Core stateDir (stateDir <> "/topology.yaml") cfg2
109-
(_toomany, SuccessFullUpdate) -> do
110-
logMsg "expected 1 proposal to pass, but >1 have passed"
111-
endScript $ ExitFailure 3
112-
on (3,10) $ \Dict _diffusion -> do
113-
bvd <- gsAdoptedBVData
114-
case (bvdUnlockStakeEpoch bvd == obftEraFlagValue) of
115-
True -> do
116-
liftIO $ hPutStrLn stderr "test passed"
117-
endScript ExitSuccess
118-
_ -> do
119-
liftIO $ hPutStrLn stderr "bvdUnlockStakeEpoch was not what was we expected"
120-
endScript $ ExitFailure 4
121-
forM_ (range (0,20)) $ \epoch -> do
122-
on(epoch, 0) $ printbvd epoch 0
123-
on(epoch, 1) $ printbvd epoch 1
124-
125-
test4 :: Byte -> ExpectedResult -> Script ()
126-
test4 targetblocksize expectedResult = do
66+
sharedUpdateTester :: (Configuration -> Configuration)
67+
-> ExpectedResult
68+
-> BlockVersion
69+
-> SoftwareVersion
70+
-> BlockVersionModifier
71+
-> (BlockVersionData -> Bool)
72+
-> String
73+
-> Script ()
74+
sharedUpdateTester mutateConf expectedResult blockVersion softwareVersion
75+
blockVersionModifier checkBvd errMsg = do
12776
genesisConfig <- getGenesisConfig
12877
let
12978
proposal :: Dict HasConfigurations -> Diffusion PocMode -> PocMode ()
13079
proposal Dict diffusion = do
13180
let
13281
keyIndex :: Int
13382
keyIndex = 0
134-
blockVersion = BlockVersion 0 1 0
135-
softwareVersion = SoftwareVersion (ApplicationName "cardano-sl") 1
136-
blockVersionModifier :: BlockVersionModifier
137-
blockVersionModifier = def { bvmMaxBlockSize = Just targetblocksize }
13883
doUpdate diffusion genesisConfig keyIndex blockVersion softwareVersion blockVersionModifier
13984
onStartup $ \Dict _diffusion -> do
14085
stateDir <- view acStatePath
@@ -145,43 +90,85 @@ test4 targetblocksize expectedResult = do
14590
proposals <- GS.getConfirmedProposals uc Nothing
14691
case (proposals, expectedResult) of
14792
([], FailedProposalUpdate) -> do
148-
logMsg "expected failed proposal, passing test"
93+
logMsg "test passed: proposal failed, as expected"
14994
endScript ExitSuccess
15095
(_, FailedProposalUpdate) -> do
151-
logMsg "expected failure, but proposal was accepted!"
96+
logMsg "test failed: proposal was accepted, but we expected failure"
15297
endScript $ ExitFailure 1
15398
([], _) -> do
154-
logMsg "expected proposal to pass, but it didnt"
99+
logMsg "test failed: proposal failed, but we expected success"
155100
endScript $ ExitFailure 2
156101
([_one], SuccessFullUpdate) -> do
157102
stateDir <- view acStatePath
158103
opts <- view acScriptOptions
159104
let
160105
-- the config for the script-runner is mirrored to the nodes it starts
161106
cfg = opts ^. srCommonNodeArgs . CLI.commonArgs_L
162-
newConfiguration <- liftIO $ mutateConfigurationYaml (cfg ^. CLI.configurationOptions_L . cfoFilePath_L) (cfg ^. CLI.configurationOptions_L . cfoKey_L) mutateConfiguration
107+
fullConfMutator = mutateConf . confSetBvAndSv blockVersion softwareVersion
108+
--
109+
newConfiguration <- liftIO $ mutateConfigurationYaml (cfg ^. CLI.configurationOptions_L . cfoFilePath_L)
110+
(cfg ^. CLI.configurationOptions_L . cfoKey_L)
111+
fullConfMutator
163112
liftIO $ BS.writeFile (T.unpack $ stateDir <> "/configuration2.yaml") newConfiguration
164113
let
165114
cfg2 = cfg & CLI.configurationOptions_L . cfoFilePath_L .~ (T.unpack $ stateDir <> "/configuration2.yaml")
166115
forAllNodes_ $ \node -> do
167116
stopNodeByName (Core, node)
168117
startNode $ NodeInfo node Core stateDir (stateDir <> "/topology.yaml") cfg2
169118
(_toomany, SuccessFullUpdate) -> do
170-
logMsg "expected 1 proposal to pass, but >1 have passed"
119+
logMsg "test failed: expected 1 proposal to pass, but >1 have passed"
171120
endScript $ ExitFailure 3
172121
on (3,10) $ \Dict _diffusion -> do
173122
bvd <- gsAdoptedBVData
174-
if bvdMaxBlockSize bvd == targetblocksize
123+
if checkBvd bvd
175124
then do
176125
liftIO $ hPutStrLn stderr "test passed"
177126
endScript ExitSuccess
178127
else do
179-
liftIO $ hPutStrLn stderr "max block size not what was expected"
128+
liftIO $ hPutStrLn stderr errMsg
180129
endScript $ ExitFailure 4
181130
forM_ (range (0,20)) $ \epoch -> do
182131
on(epoch, 0) $ printbvd epoch 0
183132
on(epoch, 1) $ printbvd epoch 1
184133

134+
testHardForkMechanism :: Script ()
135+
testHardForkMechanism =
136+
sharedUpdateTester mutateConf expectedResult blockVersion softwareVersion
137+
blockVersionModifier checkBvd errMsg
138+
where
139+
mutateConf :: Configuration -> Configuration
140+
mutateConf = mutateConfigurationForObft
141+
expectedResult :: ExpectedResult
142+
expectedResult = SuccessFullUpdate
143+
blockVersion :: BlockVersion
144+
blockVersion = BlockVersion 1 0 0
145+
softwareVersion :: SoftwareVersion
146+
softwareVersion = SoftwareVersion (ApplicationName "cardano-sl") 0
147+
blockVersionModifier :: BlockVersionModifier
148+
blockVersionModifier = def { bvmUnlockStakeEpoch = Just obftEraFlagValue }
149+
checkBvd :: BlockVersionData -> Bool
150+
checkBvd bvd = bvdUnlockStakeEpoch bvd == obftEraFlagValue
151+
errMsg :: String
152+
errMsg = "bvdUnlockStakeEpoch was not what was we expected"
153+
154+
test4 :: Byte -> ExpectedResult -> Script ()
155+
test4 targetblocksize expectedResult =
156+
sharedUpdateTester mutateConf expectedResult blockVersion softwareVersion
157+
blockVersionModifier checkBvd errMsg
158+
where
159+
mutateConf :: Configuration -> Configuration
160+
mutateConf = identity
161+
blockVersion :: BlockVersion
162+
blockVersion = BlockVersion 0 1 0
163+
softwareVersion :: SoftwareVersion
164+
softwareVersion = SoftwareVersion (ApplicationName "cardano-sl") 1
165+
blockVersionModifier :: BlockVersionModifier
166+
blockVersionModifier = def { bvmMaxBlockSize = Just targetblocksize }
167+
checkBvd :: BlockVersionData -> Bool
168+
checkBvd bvd = bvdMaxBlockSize bvd == targetblocksize
169+
errMsg :: String
170+
errMsg = "max block size not what was expected"
171+
185172
emptyScript :: Script ()
186173
emptyScript = do
187174
pure ()

0 commit comments

Comments
 (0)