Skip to content

Commit f57f1f5

Browse files
committed
testtest
1 parent 93b8985 commit f57f1f5

File tree

10 files changed

+76
-111
lines changed

10 files changed

+76
-111
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ test-suite cardano-testnet-test
215215
, time
216216
, transformers
217217

218-
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T"
218+
ghc-options: -threaded -rtsopts "-with-rtsopts=-N4 -T"
219219

220220
build-tool-depends: cardano-node:cardano-node
221221
, cardano-cli:cardano-cli

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ defaultShelleyGenesis startTime testnetOptions = do
456456
-- f
457457
activeSlotsCoeff = round (cardanoActiveSlotsCoeff * 100) % 100
458458
-- make security param k satisfy: epochLength = 10 * k / f
459-
securityParam = fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
459+
-- securityParam = fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
460460
pVer = eraToProtocolVersion cardanoNodeEra
461461
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults
462462
protocolParamsWithPVer = protocolParams & ppProtocolVersionL' .~ pVer
@@ -466,7 +466,7 @@ defaultShelleyGenesis startTime testnetOptions = do
466466
, Api.sgMaxLovelaceSupply = maxLovelaceLovelaceSupply
467467
, Api.sgNetworkMagic = fromIntegral testnetMagic
468468
, Api.sgProtocolParams = protocolParamsWithPVer
469-
, Api.sgSecurityParam = round securityParam
469+
-- , Api.sgSecurityParam = round securityParam
470470
, Api.sgSlotLength = secondsToNominalDiffTimeMicro $ realToFrac slotLength
471471
, Api.sgSystemStart = startTime
472472
}

cardano-testnet/src/Testnet/Property/Assert.hs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fileJsonGrep fp f = do
6767
assertByDeadlineIOCustom
6868
:: (MonadTest m, MonadIO m, HasCallStack)
6969
=> String -> DTC.UTCTime -> IO Bool -> m ()
70-
assertByDeadlineIOCustom str deadline f = GHC.withFrozenCallStack $ do
70+
assertByDeadlineIOCustom str deadline f = withFrozenCallStack $ do
7171
success <- H.evalIO f
7272
unless success $ do
7373
currentTime <- H.evalIO DTC.getCurrentTime
@@ -86,33 +86,35 @@ assertExpectedSposInLedgerState
8686
-> CardanoTestnetOptions
8787
-> ExecConfig
8888
-> m ()
89-
assertExpectedSposInLedgerState output tNetOptions execConfig =
90-
GHC.withFrozenCallStack $ do
91-
let numExpectedPools = length $ cardanoNodes tNetOptions
89+
assertExpectedSposInLedgerState output tNetOptions execConfig = withFrozenCallStack $ do
90+
let numExpectedPools = length $ cardanoNodes tNetOptions
9291

93-
void $ execCli' execConfig
94-
[ "query", "stake-pools"
95-
, "--out-file", output
96-
]
92+
void $ execCli' execConfig
93+
[ "query", "stake-pools"
94+
, "--out-file", output
95+
]
9796

98-
poolSet <- H.evalEither =<< H.evalIO (Aeson.eitherDecodeFileStrict' @(Set PoolId) output)
97+
poolSet <- H.evalEither =<< H.evalIO (Aeson.eitherDecodeFileStrict' @(Set PoolId) output)
9998

100-
H.cat output
99+
H.cat output
101100

102-
let numPoolsInLedgerState = Set.size poolSet
103-
unless (numPoolsInLedgerState == numExpectedPools) $
104-
failMessage GHC.callStack
105-
$ unlines [ "Expected number of stake pools not found in ledger state"
106-
, "Expected: ", show numExpectedPools
107-
, "Actual: ", show numPoolsInLedgerState
108-
]
101+
let numPoolsInLedgerState = Set.size poolSet
102+
unless (numPoolsInLedgerState == numExpectedPools) $
103+
failMessage GHC.callStack
104+
$ unlines [ "Expected number of stake pools not found in ledger state"
105+
, "Expected: ", show numExpectedPools
106+
, "Actual: ", show numPoolsInLedgerState
107+
]
109108

110-
assertChainExtended :: (HasCallStack, H.MonadTest m, MonadIO m)
109+
assertChainExtended
110+
:: HasCallStack
111+
=> H.MonadTest m
112+
=> MonadIO m
111113
=> DTC.UTCTime
112114
-> NodeLoggingFormat
113115
-> FilePath
114116
-> m ()
115-
assertChainExtended deadline nodeLoggingFormat nodeStdoutFile =
117+
assertChainExtended deadline nodeLoggingFormat nodeStdoutFile = withFrozenCallStack $
116118
assertByDeadlineIOCustom "Chain not extended" deadline $ do
117119
case nodeLoggingFormat of
118120
NodeLoggingFormatAsText -> IO.fileContains "Chain extended, new tip" nodeStdoutFile

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 49 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ import Hedgehog.Extras (failMessage)
6565
import qualified Hedgehog.Extras.Stock.OS as OS
6666
import qualified Hedgehog.Extras.Test.Base as H
6767
import qualified Hedgehog.Extras.Test.File as H
68+
import Data.IORef
69+
import GHC.IO.Unsafe (unsafePerformIO)
70+
import Hedgehog (MonadTest)
71+
import GHC.Stack
72+
import Text.Printf (printf)
6873

6974
{- HLINT ignore "Redundant flip" -}
7075
{- HLINT ignore "Redundant id" -}
@@ -106,6 +111,31 @@ cardanoTestnetDefault opts conf = do
106111
opts conf startTime
107112
(Defaults.defaultShelleyGenesis startTime opts) alonzoGenesis Defaults.defaultConwayGenesis
108113

114+
115+
-- | Starting port number, from which testnet nodes will get new ports.
116+
defaultTestnetNodeStartingPortNumber :: Int
117+
defaultTestnetNodeStartingPortNumber = 13000
118+
119+
availablePortNumber :: IORef Int
120+
availablePortNumber = unsafePerformIO $ newIORef defaultTestnetNodeStartingPortNumber
121+
{-# NOINLINE availablePortNumber #-}
122+
123+
requestAvailablePortNumbers
124+
:: HasCallStack
125+
=> MonadIO m
126+
=> MonadTest m
127+
=> Int
128+
-> m [Int]
129+
requestAvailablePortNumbers numberOfPorts
130+
| numberOfPorts > maxPortsPerRequest = withFrozenCallStack $ do
131+
H.note_ $ "Tried to allocate " <> show numberOfPorts <> " port numbers in one request. "
132+
<> "It's allowed to allocate no more than " <> show maxPortsPerRequest <> " per request."
133+
H.failure
134+
| otherwise = liftIO $ atomicModifyIORef' availablePortNumber $ \n ->
135+
(n + maxPortsPerRequest, [n..n + numberOfPorts - 1])
136+
where
137+
maxPortsPerRequest = 100
138+
109139
-- | Setup a number of credentials and pools, like this:
110140
--
111141
-- > ├── byron
@@ -178,6 +208,8 @@ cardanoTestnet
178208
nbPools = numPools testnetOptions
179209
era = cardanoNodeEra testnetOptions
180210

211+
portNumbers <- requestAvailablePortNumbers numPoolNodes
212+
181213
-- Sanity checks
182214
testnetMinimumConfigurationRequirements testnetOptions
183215
when (shelleyStartTime /= startTime) $ do
@@ -284,87 +316,26 @@ cardanoTestnet
284316
H.evalIO $ LBS.writeFile configurationFile finalYamlConfig
285317

286318
-- Byron related
287-
288-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegate-keys.000.key") (tmpAbsPath </> poolKeyDir 1 </> "byron-delegate.key")
289-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegate-keys.001.key") (tmpAbsPath </> poolKeyDir 2 </> "byron-delegate.key")
290-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegate-keys.002.key") (tmpAbsPath </> poolKeyDir 3 </> "byron-delegate.key")
291-
292-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegation-cert.000.json") (tmpAbsPath </> poolKeyDir 1 </>"byron-delegation.cert")
293-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegation-cert.001.json") (tmpAbsPath </> poolKeyDir 2 </>"byron-delegation.cert")
294-
H.renameFile (tmpAbsPath </> "byron-gen-command/delegation-cert.002.json") (tmpAbsPath </> poolKeyDir 3 </>"byron-delegation.cert")
295-
296-
H.writeFile (tmpAbsPath </> poolKeyDir 1 </> "port") "3001"
297-
H.writeFile (tmpAbsPath </> poolKeyDir 2 </> "port") "3002"
298-
H.writeFile (tmpAbsPath </> poolKeyDir 3 </> "port") "3003"
319+
forM_ (zip [1..] portNumbers) $ \(i, portNumber) -> do
320+
let iStr = printf "%03d" (i - 1)
321+
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegate-keys." <> iStr <> ".key") (tmpAbsPath </> poolKeyDir i </> "byron-delegate.key")
322+
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegation-cert." <> iStr <> ".json") (tmpAbsPath </> poolKeyDir i </>"byron-delegation.cert")
323+
H.writeFile (tmpAbsPath </> poolKeyDir i </> "port") (show portNumber)
299324

300325

301326
-- Make topology files
302-
-- TODO generalise this over the N BFT nodes and pool nodes
303-
304-
H.lbsWriteFile (tmpAbsPath </> poolKeyDir 1 </> "topology.json") $ encode $
305-
object
306-
[ "Producers" .= toJSON
307-
[ object
308-
[ "addr" .= toJSON @String "127.0.0.1"
309-
, "port" .= toJSON @Int 3002
310-
, "valency" .= toJSON @Int 1
311-
]
312-
, object
313-
[ "addr" .= toJSON @String "127.0.0.1"
314-
, "port" .= toJSON @Int 3003
315-
, "valency" .= toJSON @Int 1
316-
]
317-
, object
318-
[ "addr" .= toJSON @String "127.0.0.1"
319-
, "port" .= toJSON @Int 3005
320-
, "valency" .= toJSON @Int 1
321-
]
322-
]
323-
]
324-
325-
H.lbsWriteFile (tmpAbsPath </> poolKeyDir 2 </> "topology.json") $ encode $
326-
object
327-
[ "Producers" .= toJSON
328-
[ object
329-
[ "addr" .= toJSON @String "127.0.0.1"
330-
, "port" .= toJSON @Int 3001
331-
, "valency" .= toJSON @Int 1
332-
]
333-
, object
334-
[ "addr" .= toJSON @String "127.0.0.1"
335-
, "port" .= toJSON @Int 3003
336-
, "valency" .= toJSON @Int 1
337-
]
338-
, object
339-
[ "addr" .= toJSON @String "127.0.0.1"
340-
, "port" .= toJSON @Int 3005
341-
, "valency" .= toJSON @Int 1
342-
]
343-
]
344-
]
345-
346-
H.lbsWriteFile (tmpAbsPath </> poolKeyDir 3 </> "topology.json") $ encode $
347-
object
348-
[ "Producers" .= toJSON
349-
[ object
350-
[ "addr" .= toJSON @String "127.0.0.1"
351-
, "port" .= toJSON @Int 3001
352-
, "valency" .= toJSON @Int 1
353-
]
354-
, object
355-
[ "addr" .= toJSON @String "127.0.0.1"
356-
, "port" .= toJSON @Int 3002
357-
, "valency" .= toJSON @Int 1
358-
]
359-
, object
360-
[ "addr" .= toJSON @String "127.0.0.1"
361-
, "port" .= toJSON @Int 3005
362-
, "valency" .= toJSON @Int 1
363-
]
364-
]
365-
]
366-
367-
let spoNodesWithPortNos = L.zip poolKeysFps [3001..]
327+
forM_ (zip [1..] portNumbers) $ \(i, myPortNumber) -> do
328+
let producers = flip map (filter (/= myPortNumber) portNumbers) $ \otherProducerPort ->
329+
object
330+
[ "addr" .= toJSON @String "127.0.0.1"
331+
, "port" .= toJSON otherProducerPort
332+
, "valency" .= toJSON @Int 1
333+
]
334+
335+
H.lbsWriteFile (tmpAbsPath </> poolKeyDir i </> "topology.json") $ encode $
336+
object [ "Producers" .= producers ]
337+
338+
let spoNodesWithPortNos = L.zip poolKeysFps portNumbers
368339
ePoolNodes <- forM (L.zip spoNodesWithPortNos poolKeys) $ \((node, port),key) -> do
369340
let nodeName = tail $ dropWhile (/= '/') node
370341
H.note_ $ "Node name: " <> nodeName

cardano-testnet/src/Testnet/Start/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE NumericUnderscores #-}
23
{-# LANGUAGE ScopedTypeVariables #-}
34

45
module Testnet.Start.Types
@@ -55,7 +56,7 @@ cardanoDefaultTestnetOptions = CardanoTestnetOptions
5556
, cardanoSlotLength = 0.1
5657
, cardanoTestnetMagic = 42
5758
, cardanoActiveSlotsCoeff = 0.1
58-
, cardanoMaxSupply = 10020000000
59+
, cardanoMaxSupply = 10_020_000_000
5960
, cardanoEnableP2P = False
6061
, cardanoNodeLoggingFormat = NodeLoggingFormatAsJson
6162
}

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
7373
let era = BabbageEra
7474
cTestnetOptions = cardanoDefaultTestnetOptions
7575
{ cardanoNodes = cardanoDefaultTestnetNodeOptions
76-
, cardanoSlotLength = 0.1
77-
, cardanoActiveSlotsCoeff = 0.1
7876
, cardanoNodeEra = AnyCardanoEra era -- TODO: We should only support the latest era and the upcoming era
7977
}
8078

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t
4242
era = BabbageEra
4343
options = cardanoDefaultTestnetOptions
4444
{ cardanoNodes = cardanoDefaultTestnetNodeOptions
45-
, cardanoSlotLength = 0.1
4645
, cardanoNodeEra = AnyCardanoEra era -- TODO: We should only support the latest era and the upcoming era
4746
}
4847

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/KesPeriodInfo.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
6666
anyEra = AnyCardanoEra era
6767
cTestnetOptions = cardanoDefaultTestnetOptions
6868
{ cardanoNodes = cardanoDefaultTestnetNodeOptions
69-
, cardanoSlotLength = 0.1
70-
, cardanoActiveSlotsCoeff = 0.1
7169
, cardanoNodeEra = AnyCardanoEra era -- TODO: We should only support the latest era and the upcoming era
7270
}
7371

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ hprop_shutdownOnSlotSynced = H.integrationRetryWorkspace 2 "shutdown-on-slot-syn
220220
(Right s):_ -> return s
221221

222222
let epsilon = 50
223-
224-
H.assert (maxSlot <= slotTip && slotTip <= maxSlot + epsilon)
223+
H.assertWithinTolerance slotTip maxSlot epsilon
225224

226225
hprop_shutdownOnSigint :: Property
227226
hprop_shutdownOnSigint = H.integrationRetryWorkspace 2 "shutdown-on-sigint" $ \tempAbsBasePath' -> do
@@ -231,7 +230,6 @@ hprop_shutdownOnSigint = H.integrationRetryWorkspace 2 "shutdown-on-sigint" $ \t
231230

232231
let fastTestnetOptions = cardanoDefaultTestnetOptions
233232
{ cardanoEpochLength = 300
234-
, cardanoSlotLength = 0.01
235233
}
236234
testnetRuntime
237235
<- cardanoTestnetDefault fastTestnetOptions conf

cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import qualified Cardano.Testnet.Test.Cli.Conway.Plutus
1313
import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo
1414
import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber
1515
import qualified Cardano.Testnet.Test.FoldBlocks
16-
import qualified Cardano.Testnet.Test.LedgerEvents.Gov.InfoAction as LedgerEvents
17-
import qualified Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution as LedgerEvents
1816
import qualified Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitutionSPO as LedgerEvents
1917
import qualified Cardano.Testnet.Test.LedgerEvents.SanityCheck as LedgerEvents
2018
import qualified Cardano.Testnet.Test.Node.Shutdown

0 commit comments

Comments
 (0)