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

Commit 7af6671

Browse files
Michael Hueschendisassembler
authored andcommitted
[CO-354] Add tests for mainnet/staging ProtocolMagic
We want to be sure that mainnet/staging both have `NMMustBeNothing` as the `requiresNetworkMagic` field of their `ProtocolMagic` value, which is read from config. We add a simple test which can be run on the `lib/configuration.yaml` file and check multiple YAML keys for valid `RequiresNetworkMagic`s. We also fix the JSON file, which caused the test to fail because it did not have an explicit `requiresNetworkMagic: NMMustBeNothing` in it. (cherry picked from commit 3166d5b)
1 parent 0c61eb8 commit 7af6671

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

lib/cardano-sl.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ test-suite cardano-test
279279

280280
-- Everything else
281281
Test.Pos.Cbor.CborSpec
282+
Test.Pos.ConfigurationSpec
282283
Test.Pos.ConstantsSpec
283284
Test.Pos.CryptoSpec
284285
Test.Pos.Diffusion.BlockSpec
@@ -331,6 +332,7 @@ test-suite cardano-test
331332
, generic-arbitrary
332333
, hspec
333334
, lens
335+
, log-warper
334336
, mtl
335337
, network-transport
336338
, network-transport-inmemory

lib/configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14777,7 +14777,7 @@ mainnet_full: &mainnet_full
1477714777
<<: *mainnet_base_genesis
1477814778
src:
1477914779
file: mainnet-genesis.json
14780-
hash: 5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb
14780+
hash: 204beb98e6589cdc5cbc98b99a62fdc877dd01c35c66f6d4f85a576c949cc018
1478114781
spec:
1478214782
<<: *mainnet_base_spec
1478314783
protocolConstants:

lib/mainnet-genesis.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14532,7 +14532,10 @@
1453214532
"ftsSeed": "76617361206f7061736120736b6f766f726f64612047677572646120626f726f64612070726f766f6461",
1453314533
"protocolConsts": {
1453414534
"k": 2160,
14535-
"protocolMagic": 764824073,
14535+
"protocolMagic": {
14536+
"pm": 764824073,
14537+
"requiresNetworkMagic": "NMMustBeNothing"
14538+
},
1453614539
"vssMaxTTL": 6,
1453714540
"vssMinTTL": 2
1453814541
},
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{-# OPTIONS_GHC -fno-warn-orphans #-}
2+
3+
-- | This module tests configuration.
4+
5+
module Test.Pos.ConfigurationSpec
6+
( spec
7+
) where
8+
9+
import Universum
10+
11+
import System.Wlog (HasLoggerName (..), LoggerName (..))
12+
13+
import Mockable.Production (Production (..))
14+
import Pos.Core.Slotting (getCurrentTimestamp)
15+
import Pos.Crypto (ProtocolMagic (..), RequiresNetworkMagic (..))
16+
import Pos.Infra.Ntp.Configuration (NtpConfiguration)
17+
import Pos.Launcher.Configuration (ConfigurationOptions (..), withConfigurations)
18+
19+
import Test.Hspec (Spec, describe, it, runIO, shouldBe)
20+
21+
instance HasLoggerName IO where
22+
askLoggerName = pure $ LoggerName "ConfigurationSpec"
23+
modifyLoggerName _ x = x
24+
25+
configFilePath :: FilePath
26+
configFilePath = "configuration.yaml"
27+
28+
checkYamlSection :: Text -> Spec
29+
checkYamlSection key = describe ("key: " ++ show key) $ do
30+
startTime <- runIO (runProduction getCurrentTimestamp)
31+
let opts = ConfigurationOptions configFilePath key (Just startTime) Nothing
32+
rnm <- runIO (withConfigurations Nothing opts getRNM)
33+
it "should be NMMustBeNothing" $
34+
rnm `shouldBe` NMMustBeNothing
35+
36+
getRNM :: NtpConfiguration -> ProtocolMagic -> IO RequiresNetworkMagic
37+
getRNM _ pm = pure (getRequiresNetworkMagic pm)
38+
39+
spec :: Spec
40+
spec = mapM_ checkYamlSection [
41+
"mainnet_full" -- mainnet core/relay nodes and exchange wallets
42+
"mainnet_dryrun_full" -- staging core/relay nodes and exchange wallets
43+
"mainnet_wallet_win64" -- mainnet wallets (daedalus)
44+
"mainnet_wallet_mac64"
45+
"mainnet_wallet_linux64"
46+
"mainnet_dryrun_wallet_win64" -- staging wallets (daedalus)
47+
"mainnet_dryrun_wallet_mac64"
48+
"mainnet_dryrun_wallet_linux64"
49+
]

pkgs/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14850,6 +14850,7 @@ formatting
1485014850
generic-arbitrary
1485114851
hspec
1485214852
lens
14853+
log-warper
1485314854
mtl
1485414855
network-transport
1485514856
network-transport-inmemory

0 commit comments

Comments
 (0)