@@ -15,8 +15,8 @@ module Cardano.Testnet.Test.Cli.Babbage.LeadershipSchedule
1515 ) where
1616
1717import Cardano.Api
18+ import qualified Cardano.Api as Api
1819
19- import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (.. ))
2020import Cardano.Node.Configuration.Topology
2121import Cardano.Testnet
2222
@@ -32,7 +32,6 @@ import qualified Data.Map.Strict as Map
3232import Data.Text (Text )
3333import qualified Data.Text as Text
3434import qualified Data.Time.Clock as DTC
35- import GHC.Stack (callStack )
3635import qualified GHC.Stack as GHC
3736import System.FilePath ((</>) )
3837import qualified System.Info as SYS
@@ -49,6 +48,7 @@ import Testnet.Runtime
4948import Hedgehog (Property , (===) )
5049import qualified Hedgehog as H
5150import Hedgehog.Extras (threadDelay )
51+ import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
5252import qualified Hedgehog.Extras.Test.Base as H
5353import qualified Hedgehog.Extras.Test.File as H
5454
@@ -193,6 +193,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
193193 , " --tx-file" , delegRegTestDelegatorTxFp
194194 ]
195195
196+ -- TODO: Can be removed if checkStakeKeyRegistered uses foldEpochState
196197 threadDelay 15_000000
197198
198199 -------------------------------------------------------------------
@@ -253,74 +254,56 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
253254 testPoolStdOutFp <- case eRuntime of
254255 Left e -> H. failMessage GHC. callStack $ " Failed to start node: " <> show e
255256 Right runtime -> return $ nodeStdout runtime
256- threadDelay 5_000000
257257
258+ -- Wait for 2 epochs to pass
259+ void $ waitUntilEpoch (Api. File configurationFile)
260+ (Api. File $ IO. sprocketSystemName node1sprocket) (EpochNo 3 )
258261
259- tipDeadline <- H. noteShowM $ DTC. addUTCTime 210 <$> H. noteShowIO DTC. getCurrentTime
262+ currentLeaderShipScheduleFile <- H. noteTempFile work " current-schedule.log "
260263
261- H. byDeadlineM 10 tipDeadline " Wait for two epochs" $ do
262- void $ execCli' execConfig
263- [ " query" , " tip"
264- , " --out-file" , work </> " current-tip.json"
265- ]
266-
267- tipJson <- H. leftFailM . H. readJsonFile $ work </> " current-tip.json"
268- tip <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ QueryTipLocalStateOutput tipJson
269-
270- currEpoch <- case mEpoch tip of
271- Nothing -> H. failMessage callStack " cardano-cli query tip returned Nothing for EpochNo"
272- Just currEpoch -> return currEpoch
273-
274- H. note_ $ " Current Epoch: " <> show currEpoch
275- H. assert $ currEpoch > 2
276-
277- id do
278- currentLeaderShipScheduleFile <- H. noteTempFile work " current-schedule.log"
279-
280- leadershipScheduleDeadline <- H. noteShowM $ DTC. addUTCTime 180 <$> H. noteShowIO DTC. getCurrentTime
281-
282- H. byDeadlineM 5 leadershipScheduleDeadline " Failed to query for leadership schedule" $ do
283- void $ execCli' execConfig
284- [ " query" , " leadership-schedule"
285- , " --genesis" , shelleyGenesisFile tr
286- , " --stake-pool-id" , stakePoolIdNewSpo
287- , " --vrf-signing-key-file" , vrfSkey
288- , " --out-file" , currentLeaderShipScheduleFile
289- , " --current"
290- ]
264+ void $ execCli' execConfig
265+ [ " query" , " leadership-schedule"
266+ , " --genesis" , shelleyGenesisFile tr
267+ , " --stake-pool-id" , stakePoolIdNewSpo
268+ , " --vrf-signing-key-file" , vrfSkey
269+ , " --out-file" , currentLeaderShipScheduleFile
270+ , " --current"
271+ ]
291272
292- currentScheduleJson <- H. leftFailM $ H. readJsonFile currentLeaderShipScheduleFile
273+ currentScheduleJson <- H. leftFailM $ H. readJsonFile currentLeaderShipScheduleFile
293274
294- expectedLeadershipSlotNumbers <- H. noteShowM $ fmap (fmap slotNumber) $ H. leftFail $ J. parseEither (J. parseJSON @ [LeadershipSlot ]) currentScheduleJson
275+ expectedLeadershipSlotNumbers <- H. noteShowM $ fmap (fmap slotNumber) $ H. leftFail $ J. parseEither (J. parseJSON @ [LeadershipSlot ]) currentScheduleJson
295276
296- maxSlotExpected <- H. noteShow $ maximum expectedLeadershipSlotNumbers
277+ maxSlotExpected <- H. noteShow $ maximum expectedLeadershipSlotNumbers
297278
298- H. assert $ not (L. null expectedLeadershipSlotNumbers)
279+ H. assert $ not (L. null expectedLeadershipSlotNumbers)
299280
300- leadershipDeadline <- H. noteShowM $ DTC. addUTCTime 90 <$> H. noteShowIO DTC. getCurrentTime
281+ leadershipDeadline <- H. noteShowM $ DTC. addUTCTime 90 <$> H. noteShowIO DTC. getCurrentTime
301282
302283 -- We need enough time to pass such that the expected leadership slots generated by the
303284 -- leadership-schedule command have actually occurred.
304- (leaderSlots, notLeaderSlots) <- H. byDeadlineM 10 leadershipDeadline " Wait for chain to surpass all expected leadership slots" $ do
305- (someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
306- if L. null someLeaderSlots
307- then H. failure
308- else do
309- maxActualSlot <- H. noteShow $ maximum someLeaderSlots
310- H. assert $ maxActualSlot >= maxSlotExpected
311- pure (someLeaderSlots, someNotLeaderSlots)
312-
313- H. noteShow_ expectedLeadershipSlotNumbers
314- H. noteShow_ leaderSlots
315- H. noteShow_ notLeaderSlots
285+ -- TODO: We can further improve this if parameterize foldEpochState's callback on
286+ -- the current slot and current block number.
287+ (leaderSlots, notLeaderSlots) <- H. byDeadlineM 10 leadershipDeadline " Wait for chain to surpass all expected leadership slots" $ do
288+ (someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
289+ if L. null someLeaderSlots
290+ then H. failure
291+ else do
292+ maxActualSlot <- H. noteShow $ maximum someLeaderSlots
293+ H. assert $ maxActualSlot >= maxSlotExpected
294+ pure (someLeaderSlots, someNotLeaderSlots)
295+
296+ H. noteShow_ expectedLeadershipSlotNumbers
297+ H. noteShow_ leaderSlots
298+ H. noteShow_ notLeaderSlots
316299
317300 -- Double check that we've seen all slots
318- H. noteShow_ (" Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text )
319- ([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []
301+ H. noteShow_ (" Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text )
302+ ([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []
320303
321304 -- As there are no BFT nodes, the next leadership schedule should match slots assigned exactly
322- H. noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
323- H. assert $ L. null (expectedLeadershipSlotNumbers \\ leaderSlots)
305+ H. noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
306+ H. assert $ L. null (expectedLeadershipSlotNumbers \\ leaderSlots)
324307 -- TODO: Re-enable --next leadership schedule test
325308 {-
326309
0 commit comments