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

Commit 66e820c

Browse files
committed
[CO-410] Add golden decode only test for Configuration
1 parent fc4b583 commit 66e820c

File tree

13 files changed

+408
-11
lines changed

13 files changed

+408
-11
lines changed

chain/src/Pos/Chain/Block/Configuration.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ data BlockConfiguration = BlockConfiguration
7474
-- | Chain quality will be also calculated for this amount of seconds.
7575
, ccFixedTimeCQ :: !Second
7676

77-
} deriving (Show, Generic)
77+
} deriving (Eq, Generic, Show)
7878

7979
instance ToJSON BlockConfiguration where
8080
toJSON = genericToJSON defaultOptions

chain/src/Pos/Chain/Genesis/Config.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ instance FromJSON StaticConfig where
148148
avvmBalanceFactor
149149
useHeavyDlg
150150
seed)
151-
| otherwise = fail "Incorrect JSON encoding for GenesisConfiguration"
151+
| otherwise = fail "Incorrect JSON encoding for StaticConfig"
152152

153-
parseJSON invalid = typeMismatch "GenesisConfiguration" invalid
153+
parseJSON invalid = typeMismatch "StaticConfig" invalid
154154

155155
--------------------------------------------------------------------------------
156156
-- Config

chain/src/Pos/Chain/Ssc/Configuration.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data SscConfiguration = SscConfiguration
3737
-- | Don't print “SSC couldn't compute seed” for the first epoch.
3838
, ccNoReportNoSecretsForEpoch1 :: !Bool
3939
}
40-
deriving (Show, Generic)
40+
deriving (Eq, Generic, Show)
4141

4242
instance FromJSON SscConfiguration where
4343
parseJSON = genericParseJSON defaultOptions

chain/src/Pos/Chain/Update/Configuration.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ data UpdateConfiguration = UpdateConfiguration
5555
-- | System tag.
5656
, ccSystemTag :: !SystemTag
5757
}
58-
deriving (Show, Generic)
58+
deriving (Eq, Generic, Show)
5959

6060
instance ToJSON UpdateConfiguration where
6161
toJSON = genericToJSON defaultOptions

lib/cardano-sl.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ test-suite cardano-test
283283
Test.Pos.Diffusion.BlockSpec
284284
Test.Pos.Genesis.CanonicalSpec
285285
Test.Pos.Launcher.ConfigurationSpec
286+
Test.Pos.Launcher.Json
286287
Test.Pos.MerkleSpec
287288
Test.Pos.Infra.Slotting.TypesSpec
288289
Test.Pos.Types.Identity.SafeCopySpec
@@ -322,6 +323,7 @@ test-suite cardano-test
322323
, filelock
323324
, formatting
324325
, generic-arbitrary
326+
, hedgehog
325327
, hspec
326328
, lens
327329
, network-transport

lib/src/Pos/Configuration.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data NodeConfiguration = NodeConfiguration
5858
, ccExplorerExtendedApi :: !Bool
5959
-- ^ Enable explorer extended API for fetching more
6060
-- info about addresses (like utxos) and bulk endpoints
61-
} deriving (Show, Generic)
61+
} deriving (Eq, Generic, Show)
6262

6363
instance ToJSON NodeConfiguration where
6464
toJSON = genericToJSON defaultOptions

lib/src/Pos/Launcher/Configuration.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ data Configuration = Configuration
7474
, ccNode :: !NodeConfiguration
7575
, ccWallet :: !WalletConfiguration
7676
, ccReqNetMagic :: !RequiresNetworkMagic
77-
} deriving (Show, Generic)
77+
} deriving (Eq, Generic , Show)
7878

7979
instance FromJSON Configuration where
8080
parseJSON = withObject "Configuration" $ \o -> do
@@ -114,7 +114,7 @@ instance ToJSON Configuration where
114114

115115
data WalletConfiguration = WalletConfiguration
116116
{ ccThrottle :: !(Maybe ThrottleSettings)
117-
} deriving (Show, Generic)
117+
} deriving (Eq, Generic, Show)
118118

119119
defaultWalletConfiguration :: WalletConfiguration
120120
defaultWalletConfiguration = WalletConfiguration
@@ -131,7 +131,7 @@ data ThrottleSettings = ThrottleSettings
131131
{ tsRate :: !Word64
132132
, tsPeriod :: !Word64
133133
, tsBurst :: !Word64
134-
} deriving (Show, Generic)
134+
} deriving (Eq, Generic, Show)
135135

136136
defaultThrottleSettings :: ThrottleSettings
137137
defaultThrottleSettings = ThrottleSettings

lib/test/Test.hs

+3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import Test.Hspec (hspec)
55
import Spec (spec)
66

77
import Test.Pos.Configuration (defaultTestConf)
8+
import qualified Test.Pos.Launcher.Json
9+
import Test.Pos.Util.Tripping (runTests)
810

911
main :: IO ()
1012
main = do
1113
putText $ "default configuration: " <> show defaultTestConf
1214
hspec spec
15+
runTests [ Test.Pos.Launcher.Json.tests ]

lib/test/Test/Pos/Launcher/Json.hs

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module Test.Pos.Launcher.Json
4+
( tests
5+
) where
6+
7+
import Universum
8+
9+
import qualified Data.HashMap.Strict as HM
10+
import qualified Data.Set as S
11+
import Hedgehog (Property)
12+
import qualified Hedgehog as H
13+
14+
import Ntp.Client (NtpConfiguration (..))
15+
import Pos.Chain.Block (BlockConfiguration (..))
16+
import Pos.Chain.Delegation (DlgConfiguration (..))
17+
import Pos.Chain.Genesis (FakeAvvmOptions (..),
18+
GenesisAvvmBalances (..), GenesisDelegation (..),
19+
GenesisInitializer (..), GenesisProtocolConstants (..),
20+
GenesisSpec (..), StaticConfig (..),
21+
TestnetBalanceOptions (..))
22+
import Pos.Chain.Ssc (SscConfiguration (..))
23+
import Pos.Chain.Txp (TxpConfiguration (..))
24+
import Pos.Chain.Update
25+
import Pos.Configuration (NodeConfiguration (..))
26+
import Pos.Core.Common (Coeff (..), CoinPortion (..), SharedSeed (..),
27+
TxFeePolicy (..), TxSizeLinear (..))
28+
import Pos.Core.ProtocolConstants (VssMaxTTL (..), VssMinTTL (..))
29+
import Pos.Core.Slotting (EpochIndex (..))
30+
import Pos.Crypto.Configuration (ProtocolMagic (..),
31+
ProtocolMagicId (..), RequiresNetworkMagic (..))
32+
import Pos.Launcher.Configuration (Configuration (..),
33+
WalletConfiguration (..))
34+
35+
import Test.Pos.Util.Golden (discoverGolden, goldenTestJSONDec)
36+
--------------------------------------------------------------------------------
37+
-- Configuration
38+
--------------------------------------------------------------------------------
39+
40+
-- Decode-only golden tests for ensuring that, when decoding the legacy
41+
-- `Configuration` JSON format, the `RequiresNetworkMagic` field defaults to
42+
-- the correct `RequiresNetworkMagic`.
43+
44+
golden_Configuration_Legacy_NoNetworkMagicField :: Property
45+
golden_Configuration_Legacy_NoNetworkMagicField =
46+
goldenTestJSONDec
47+
testGoldenConf_NoNetworkMagicField
48+
"test/golden/json/Configuration_Legacy_NoNetworkMagicField"
49+
50+
testGoldenConf_NoNetworkMagicField :: Configuration
51+
testGoldenConf_NoNetworkMagicField = Configuration
52+
{ ccGenesis = GCSpec
53+
( UnsafeGenesisSpec
54+
{ gsAvvmDistr = GenesisAvvmBalances (HM.fromList [])
55+
, gsFtsSeed = SharedSeed "skovoroda Ggurda boroda provoda "
56+
, gsHeavyDelegation = UnsafeGenesisDelegation (HM.fromList [])
57+
, gsBlockVersionData = BlockVersionData
58+
{ bvdScriptVersion = 0
59+
, bvdSlotDuration = 7000
60+
, bvdMaxBlockSize = 2000000
61+
, bvdMaxHeaderSize = 2000000
62+
, bvdMaxTxSize = 4096
63+
, bvdMaxProposalSize = 700
64+
, bvdMpcThd = CoinPortion 100000000000000
65+
, bvdHeavyDelThd = CoinPortion 100000000000000
66+
, bvdUpdateVoteThd = CoinPortion 100000000000000
67+
, bvdUpdateProposalThd = CoinPortion 100000000000000
68+
, bvdUpdateImplicit = 10
69+
, bvdSoftforkRule = SoftforkRule
70+
{ srInitThd = CoinPortion 100000000000000
71+
, srMinThd = CoinPortion 100000000000000
72+
, srThdDecrement = CoinPortion 100000000000000
73+
}
74+
, bvdTxFeePolicy =
75+
TxFeePolicyTxSizeLinear
76+
(TxSizeLinear
77+
(Coeff 155381.000000000) (Coeff 43.946000000))
78+
, bvdUnlockStakeEpoch = EpochIndex 1844
79+
}
80+
, gsProtocolConstants = GenesisProtocolConstants
81+
{ gpcK = 2
82+
, gpcProtocolMagic = ProtocolMagic
83+
(ProtocolMagicId 55550001) RequiresMagic
84+
, gpcVssMaxTTL = VssMaxTTL 6
85+
, gpcVssMinTTL = VssMinTTL 2
86+
}
87+
, gsInitializer = GenesisInitializer
88+
{ giTestBalance = TestnetBalanceOptions
89+
{ tboPoors = 12
90+
, tboRichmen = 4
91+
, tboTotalBalance = 600000000000000000
92+
, tboRichmenShare = 0.99
93+
, tboUseHDAddresses = True
94+
}
95+
, giFakeAvvmBalance = FakeAvvmOptions
96+
{ faoCount = 10
97+
, faoOneBalance = 100000
98+
}
99+
, giAvvmBalanceFactor = CoinPortion 100000000000000
100+
, giUseHeavyDlg = True
101+
, giSeed = 0
102+
}
103+
}
104+
)
105+
, ccNtp = NtpConfiguration
106+
{ ntpcServers =
107+
[ "0.pool.ntp.org"
108+
, "2.pool.ntp.org"
109+
, "3.pool.ntp.org"
110+
]
111+
, ntpcResponseTimeout = 30000000
112+
, ntpcPollDelay = 1800000000
113+
}
114+
, ccUpdate = UpdateConfiguration
115+
{ ccApplicationName = ApplicationName "cardano-sl"
116+
, ccLastKnownBlockVersion = BlockVersion 0 0 0
117+
, ccApplicationVersion = 0
118+
, ccSystemTag = SystemTag "linux64"
119+
}
120+
, ccSsc = SscConfiguration
121+
{ ccMpcSendInterval = 10
122+
, ccMdNoCommitmentsEpochThreshold = 3
123+
, ccNoReportNoSecretsForEpoch1 = False
124+
}
125+
, ccDlg = DlgConfiguration
126+
{ ccDlgCacheParam = 500
127+
, ccMessageCacheTimeout = 30
128+
}
129+
, ccTxp = TxpConfiguration
130+
{ ccMemPoolLimitTx = 200
131+
, tcAssetLockedSrcAddrs = S.fromList []
132+
}
133+
, ccBlock = BlockConfiguration
134+
{ ccNetworkDiameter = 3
135+
, ccRecoveryHeadersMessage = 20
136+
, ccStreamWindow = 2048
137+
, ccNonCriticalCQBootstrap = 0.95
138+
, ccCriticalCQBootstrap = 0.8888
139+
, ccNonCriticalCQ = 0.8
140+
, ccCriticalCQ = 0.654321
141+
, ccCriticalForkThreshold = 2
142+
, ccFixedTimeCQ = 10
143+
}
144+
, ccNode = NodeConfiguration
145+
{ ccNetworkConnectionTimeout = 15000
146+
, ccConversationEstablishTimeout = 30000
147+
, ccBlockRetrievalQueueSize = 100
148+
, ccPendingTxResubmissionPeriod = 7
149+
, ccWalletProductionApi = False
150+
, ccWalletTxCreationDisabled = False
151+
, ccExplorerExtendedApi = False
152+
}
153+
, ccWallet = WalletConfiguration { ccThrottle = Nothing }
154+
, ccReqNetMagic = RequiresNoMagic
155+
}
156+
157+
tests :: IO Bool
158+
tests = H.checkSequential $$discoverGolden
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"core":{"genesis":{"spec":{"initializer":{"testBalance":{"poors":12,"richmen":4,"richmenShare":0.99,"useHDAddresses":true,"totalBalance":600000000000000000},"fakeAvvmBalance":{"count":10,"oneBalance":100000},"avvmBalanceFactor":0.1,"useHeavyDlg":true,"seed":0},"blockVersionData":{"scriptVersion":0,"slotDuration":7000,"maxBlockSize":2000000,"maxHeaderSize":2000000,"maxTxSize":4096,"maxProposalSize":700,"mpcThd":0.1,"heavyDelThd":0.1,"updateVoteThd":0.1,"updateProposalThd":0.1,"updateImplicit":10,"softforkRule":{"initThd":0.1,"minThd":0.1,"thdDecrement":0.1},"txFeePolicy":{"txSizeLinear":{"a":155381,"b":43.946}},"unlockStakeEpoch":1844},"protocolConstants":{"k":2,"protocolMagic":55550001,"vssMinTTL":2,"vssMaxTTL":6},"ftsSeed":"c2tvdm9yb2RhIEdndXJkYSBib3JvZGEgcHJvdm9kYSA=","heavyDelegation":{},"avvmDistr":{}}},"requiresNetworkMagic":"RequiresNoMagic","dbSerializeVersion":0},"ntp":{"responseTimeout":30000000,"pollDelay":1800000000,"servers":["0.pool.ntp.org","2.pool.ntp.org","3.pool.ntp.org"]},"update":{"applicationName":"cardano-sl","applicationVersion":0,"lastKnownBlockVersion":{"bvMajor":0,"bvMinor":0,"bvAlt":0}},"ssc":{"mpcSendInterval":10,"mdNoCommitmentsEpochThreshold":3,"noReportNoSecretsForEpoch1":false},"txp":{"memPoolLimitTx":200,"assetLockedSrcAddrs":[]},"dlg":{"dlgCacheParam":500,"messageCacheTimeout":30},"block":{"networkDiameter":3,"recoveryHeadersMessage":20,"streamWindow":2048,"nonCriticalCQBootstrap":0.95,"criticalCQBootstrap":0.8888,"nonCriticalCQ":0.8,"criticalCQ":0.654321,"criticalForkThreshold":2,"fixedTimeCQ":10},"node":{"networkConnectionTimeout":15000,"conversationEstablishTimeout":30000,"blockRetrievalQueueSize":100,"pendingTxResubmissionPeriod":7,"walletProductionApi":false,"walletTxCreationDisabled":false,"explorerExtendedApi":false},"wallet":{"throttle":null}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
This is the prettified version of `testGoldenConf_NoNetworkMagicField` for reference purposes.
2+
3+
Configuration
4+
{ ccGenesis = GCSpec
5+
( UnsafeGenesisSpec
6+
{ gsAvvmDistr = GenesisAvvmBalances { getGenesisAvvmBalances = fromList [] }
7+
, gsFtsSeed = SharedSeed { getSharedSeed = "skovoroda Ggurda boroda provoda " }
8+
, gsHeavyDelegation = UnsafeGenesisDelegation { unGenesisDelegation = fromList [] }
9+
, gsBlockVersionData = BlockVersionData
10+
{ bvdScriptVersion = 0
11+
, bvdSlotDuration = 7000ms
12+
, bvdMaxBlockSize = Byte 2000000
13+
, bvdMaxHeaderSize = Byte 2000000
14+
, bvdMaxTxSize = Byte 4096
15+
, bvdMaxProposalSize = Byte 700
16+
, bvdMpcThd = CoinPortion { getCoinPortion = 10000000000000 }
17+
, bvdHeavyDelThd = CoinPortion { getCoinPortion = 5000000000000 }
18+
, bvdUpdateVoteThd = CoinPortion { getCoinPortion = 1000000000000 }
19+
, bvdUpdateProposalThd = CoinPortion { getCoinPortion = 100000000000000 }
20+
, bvdUpdateImplicit = 10
21+
, bvdSoftforkRule = SoftforkRule
22+
{ srInitThd = CoinPortion { getCoinPortion = 900000000000000 }
23+
, srMinThd = CoinPortion { getCoinPortion = 600000000000000 }
24+
, srThdDecrement = CoinPortion { getCoinPortion = 50000000000000 }
25+
}
26+
, bvdTxFeePolicy = TxFeePolicyTxSizeLinear ( TxSizeLinear ( Coeff 155381.000000000 ) ( Coeff 43.946000000 ) )
27+
, bvdUnlockStakeEpoch = EpochIndex { getEpochIndex = 18446744073709551615 }
28+
}
29+
, gsProtocolConstants = GenesisProtocolConstants
30+
{ gpcK = 10
31+
, gpcProtocolMagic = ProtocolMagic
32+
{ getProtocolMagicId = ProtocolMagicId { unProtocolMagicId = 55550001 }
33+
, getRequiresNetworkMagic = RequiresMagic
34+
}
35+
, gpcVssMaxTTL = VssMaxTTL { getVssMaxTTL = 6 }
36+
, gpcVssMinTTL = VssMinTTL { getVssMinTTL = 2 }
37+
}
38+
, gsInitializer = GenesisInitializer
39+
{ giTestBalance = TestnetBalanceOptions
40+
{ tboPoors = 12
41+
, tboRichmen = 4
42+
, tboTotalBalance = 600000000000000000
43+
, tboRichmenShare = 0.99
44+
, tboUseHDAddresses = True
45+
}
46+
, giFakeAvvmBalance = FakeAvvmOptions
47+
{ faoCount = 10
48+
, faoOneBalance = 100000
49+
}
50+
, giAvvmBalanceFactor = CoinPortion { getCoinPortion = 1000000000000000 }
51+
, giUseHeavyDlg = True
52+
, giSeed = 0
53+
}
54+
}
55+
)
56+
, ccNtp = NtpConfiguration
57+
{ ntpcServers =
58+
[ "0.pool.ntp.org"
59+
, "2.pool.ntp.org"
60+
, "3.pool.ntp.org"
61+
]
62+
, ntpcResponseTimeout = 30000000
63+
, ntpcPollDelay = 1800000000
64+
}
65+
, ccUpdate = UpdateConfiguration
66+
{ ccApplicationName = ApplicationName { getApplicationName = "cardano-sl" }
67+
, ccLastKnownBlockVersion = 0.0.0
68+
, ccApplicationVersion = 0
69+
, ccSystemTag = SystemTag { getSystemTag = "linux64" }
70+
}
71+
, ccSsc = SscConfiguration
72+
{ ccMpcSendInterval = 10
73+
, ccMdNoCommitmentsEpochThreshold = 3
74+
, ccNoReportNoSecretsForEpoch1 = False
75+
}
76+
, ccDlg = DlgConfiguration
77+
{ ccDlgCacheParam = 500
78+
, ccMessageCacheTimeout = 30
79+
}
80+
, ccTxp = TxpConfiguration
81+
{ ccMemPoolLimitTx = 200
82+
, tcAssetLockedSrcAddrs = fromList []
83+
}
84+
, ccBlock = BlockConfiguration
85+
{ ccNetworkDiameter = 3
86+
, ccRecoveryHeadersMessage = 20
87+
, ccStreamWindow = 2048
88+
, ccNonCriticalCQBootstrap = 0.95
89+
, ccCriticalCQBootstrap = 0.8888
90+
, ccNonCriticalCQ = 0.8
91+
, ccCriticalCQ = 0.654321
92+
, ccCriticalForkThreshold = 2
93+
, ccFixedTimeCQ = 10s
94+
}
95+
, ccNode = NodeConfiguration
96+
{ ccNetworkConnectionTimeout = 15000
97+
, ccConversationEstablishTimeout = 30000
98+
, ccBlockRetrievalQueueSize = 100
99+
, ccPendingTxResubmissionPeriod = 7
100+
, ccWalletProductionApi = False
101+
, ccWalletTxCreationDisabled = False
102+
, ccExplorerExtendedApi = False
103+
}
104+
, ccWallet = WalletConfiguration { ccThrottle = Nothing }
105+
, ccReqNetMagic = RequiresNoMagic
106+
}

0 commit comments

Comments
 (0)