Skip to content

Commit 60fc9c4

Browse files
committed
Fix security param for tests
1 parent f84edc0 commit 60fc9c4

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE NamedFieldPuns #-}
34
{-# LANGUAGE OverloadedStrings #-}
45
{-# LANGUAGE RankNTypes #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
@@ -47,14 +48,17 @@ import qualified Data.Aeson.KeyMap as KeyMapAeson
4748
import Data.Bifunctor
4849
import qualified Data.Default.Class as DefaultClass
4950
import qualified Data.Map.Strict as Map
51+
import Data.Maybe
5052
import Data.Proxy
5153
import Data.Ratio
5254
import Data.Scientific
5355
import Data.Text (Text)
5456
import qualified Data.Text as Text
5557
import Data.Time (UTCTime)
58+
import Data.Typeable
5659
import qualified Data.Vector as Vector
5760
import Data.Word
61+
import GHC.Stack
5862
import Lens.Micro
5963
import Numeric.Natural
6064

@@ -440,21 +444,31 @@ defaultShelleyGenesis
440444
:: UTCTime
441445
-> CardanoTestnetOptions
442446
-> Api.ShelleyGenesis StandardCrypto
443-
defaultShelleyGenesis startTime testnetOptions =
444-
let testnetMagic = cardanoTestnetMagic testnetOptions
445-
slotLength = cardanoSlotLength testnetOptions
446-
epochLength = cardanoEpochLength testnetOptions
447-
maxLovelaceLovelaceSupply = cardanoMaxSupply testnetOptions
448-
pVer = eraToProtocolVersion $ cardanoNodeEra testnetOptions
447+
defaultShelleyGenesis startTime testnetOptions = do
448+
let CardanoTestnetOptions
449+
{ cardanoTestnetMagic = testnetMagic
450+
, cardanoSlotLength = slotLength
451+
, cardanoEpochLength = epochLength
452+
, cardanoMaxSupply = maxLovelaceLovelaceSupply
453+
, cardanoActiveSlotsCoeff
454+
, cardanoNodeEra
455+
} = testnetOptions
456+
-- f
457+
activeSlotsCoeff = round (cardanoActiveSlotsCoeff * 100) % 100
458+
-- make security param k satisfy: epochLength = 10 * k / f
459+
securityParam = fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
460+
pVer = eraToProtocolVersion cardanoNodeEra
449461
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults
450462
protocolParamsWithPVer = protocolParams & ppProtocolVersionL' .~ pVer
451-
in Api.shelleyGenesisDefaults
452-
{ Api.sgNetworkMagic = fromIntegral testnetMagic
453-
, Api.sgSlotLength = secondsToNominalDiffTimeMicro $ realToFrac slotLength
463+
Api.shelleyGenesisDefaults
464+
{ Api.sgActiveSlotsCoeff = unsafeBoundedRational activeSlotsCoeff
454465
, Api.sgEpochLength = EpochSize $ fromIntegral epochLength
455466
, Api.sgMaxLovelaceSupply = maxLovelaceLovelaceSupply
456-
, Api.sgSystemStart = startTime
467+
, Api.sgNetworkMagic = fromIntegral testnetMagic
457468
, Api.sgProtocolParams = protocolParamsWithPVer
469+
, Api.sgSecurityParam = round securityParam
470+
, Api.sgSlotLength = secondsToNominalDiffTimeMicro $ realToFrac slotLength
471+
, Api.sgSystemStart = startTime
458472
}
459473

460474

@@ -522,3 +536,11 @@ plutusV3SpendingScript =
522536
, ",\"cborHex\": \"484701010022280001\""
523537
, "}"
524538
]
539+
540+
-- FIXME: move to cardano-api
541+
unsafeBoundedRational :: forall r. (HasCallStack, Typeable r, BoundedRational r)
542+
=> Rational
543+
-> r
544+
unsafeBoundedRational x = fromMaybe (error errMessage) $ boundRational x
545+
where
546+
errMessage = show (typeRep (Proxy @r)) <> " is out of bounds: " <> show x

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/LedgerEvents/Gov/InfoAction.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,14 @@ hprop_ledger_events_info_action = H.integrationRetryWorkspace 0 "info-hash" $ \t
274274

275275
-- We check that info action was succcessfully ratified
276276
!meInfoRatified
277-
<- H.timeout 720_000_000 $ runExceptT $ foldBlocks
277+
<- H.timeout 120_000_000 $ runExceptT $ foldBlocks
278278
(File configurationFile)
279279
(File socketPath)
280280
FullValidation
281281
(InfoActionState False False) -- Initial accumulator state
282282
(foldBlocksCheckInfoAction (tempAbsPath' </> "events.log") governanceActionIndex )
283283

284-
eInfoRatified <- H.nothingFail meInfoRatified
285-
case eInfoRatified of
284+
H.nothingFail meInfoRatified >>= \case
286285
Left e ->
287286
H.failMessage callStack
288287
$ "foldBlocksCheckInfoAction failed with: " <> displayError e

0 commit comments

Comments
 (0)