@@ -8,44 +8,41 @@ module Spec.Cli.KesPeriodInfo
8
8
( hprop_kes_period_info
9
9
) where
10
10
11
-
12
- import Prelude
13
-
14
11
import Cardano.Api
15
- import Cardano.Api.Shelley
16
-
12
+ import Cardano.Api.Shelley (PoolId )
17
13
import Control.Monad (void )
18
- import qualified Data.Aeson as J
19
- import qualified Data.Map.Strict as Map
20
14
import Data.Monoid (Last (.. ))
21
15
import Data.Set (Set )
22
- import qualified Data.Set as Set
23
- import qualified Data.Text as T
24
16
import GHC.Stack (callStack )
25
- import qualified System.Directory as IO
17
+ import Hedgehog (Property , (===) )
18
+ import Prelude
26
19
import System.Environment (getEnvironment )
27
20
import System.FilePath ((</>) )
28
21
29
22
import Cardano.CLI.Shelley.Output
30
23
import Cardano.CLI.Shelley.Run.Query
31
24
32
- import Hedgehog (Property , (===) )
25
+ import Testnet.Cardano (TestnetOptions (.. ), TestnetRuntime (.. ),
26
+ defaultTestnetNodeOptions , defaultTestnetOptions , testnet )
27
+ import Testnet.Utils (waitUntilEpoch )
28
+
29
+ import qualified Data.Aeson as J
30
+ import qualified Data.Map.Strict as Map
31
+ import qualified Data.Set as Set
32
+ import qualified Data.Text as T
33
33
import qualified Hedgehog as H
34
34
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
35
35
import qualified Hedgehog.Extras.Test.Base as H
36
- import qualified Hedgehog.Extras.Test.Concurrent as H
37
36
import qualified Hedgehog.Extras.Test.File as H
38
37
import qualified Hedgehog.Extras.Test.Process as H
38
+ import qualified System.Directory as IO
39
39
import qualified System.Info as SYS
40
40
import qualified Test.Base as H
41
41
import qualified Test.Process as H
42
42
import qualified Test.Runtime as TR
43
43
import qualified Testnet.Cardano as TC
44
- import Testnet.Cardano (TestnetOptions (.. ), TestnetRuntime (.. ),
45
- defaultTestnetNodeOptions , defaultTestnetOptions , testnet )
46
44
import qualified Testnet.Conf as H
47
45
import Testnet.Conf (ProjectBase (.. ), YamlFilePath (.. ))
48
- import Testnet.Utils (waitUntilEpoch )
49
46
50
47
import Testnet.Properties.Cli.KesPeriodInfo
51
48
@@ -107,7 +104,7 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
107
104
108
105
utxo1Json <- H. leftFailM . H. readJsonFile $ work </> " utxo-1.json"
109
106
UTxO utxo1 <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ (UTxO AlonzoEra ) utxo1Json
110
- txin <- H. noteShow $ head $ Map. keys utxo1
107
+ txin <- H. noteShow =<< H. headM ( Map. keys utxo1)
111
108
112
109
-- Staking keys
113
110
utxoStakingVkey2 <- H. note $ tempAbsPath </> " shelley/utxo-keys/utxo2-stake.vkey"
@@ -188,27 +185,24 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
188
185
, " --testnet-magic" , show @ Int testnetMagic
189
186
]
190
187
191
- -- Things take long on non-linux machines
192
- if H. isLinux
193
- then H. threadDelay 5000000
194
- else H. threadDelay 10000000
188
+ delegsAndRewards <- H. byDurationM 3 12 $ do
189
+ -- Check to see if pledge's stake address was registered
195
190
196
- -- Check to see if pledge's stake address was registered
197
-
198
- void $ H. execCli' execConfig
199
- [ " query" , " stake-address-info"
200
- , " --address" , poolownerstakeaddr
201
- , " --testnet-magic" , show @ Int testnetMagic
202
- , " --out-file" , work </> " pledgeownerregistration.json"
203
- ]
191
+ void $ H. execCli' execConfig
192
+ [ " query" , " stake-address-info"
193
+ , " --address" , poolownerstakeaddr
194
+ , " --testnet-magic" , show @ Int testnetMagic
195
+ , " --out-file" , work </> " pledgeownerregistration.json"
196
+ ]
204
197
205
- pledgerStakeInfo <- H. leftFailM . H. readJsonFile $ work </> " pledgeownerregistration.json"
206
- delegsAndRewardsMap <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ DelegationsAndRewards pledgerStakeInfo
207
- let delegsAndRewards = mergeDelegsAndRewards delegsAndRewardsMap
198
+ pledgerStakeInfo <- H. leftFailM . H. readJsonFile $ work </> " pledgeownerregistration.json"
199
+ delegsAndRewardsMap <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ DelegationsAndRewards pledgerStakeInfo
200
+ delegsAndRewards <- H. noteShow $ mergeDelegsAndRewards delegsAndRewardsMap
208
201
209
- length delegsAndRewards === 1
202
+ length delegsAndRewards === 1
203
+ return delegsAndRewards
210
204
211
- let (pledgerSAddr, _rewards, _poolId) = head delegsAndRewards
205
+ (pledgerSAddr, _rewards, _poolId) <- H. headM delegsAndRewards
212
206
213
207
-- Pledger and owner are and can be the same
214
208
T. unpack (serialiseAddress pledgerSAddr) === poolownerstakeaddr
@@ -227,7 +221,7 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
227
221
228
222
utxoWithStaking1Json <- H. leftFailM . H. readJsonFile $ work </> " utxo-addr-with-staking-1.json"
229
223
UTxO utxoWithStaking1 <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ (UTxO AlonzoEra ) utxoWithStaking1Json
230
- txinForStakeReg <- H. noteShow $ head $ Map. keys utxoWithStaking1
224
+ txinForStakeReg <- H. noteShow =<< H. headM ( Map. keys utxoWithStaking1)
231
225
232
226
void $ H. execCli [ " stake-address" , " registration-certificate"
233
227
, " --stake-verification-key-file" , utxoStakingVkey2
@@ -262,21 +256,21 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
262
256
]
263
257
264
258
H. note_ $ " Check to see if " <> utxoStakingVkey2 <> " was registered..."
265
- H. threadDelay 10000000
266
-
267
- void $ H. execCli' execConfig
268
- [ " query" , " stake-address-info"
269
- , " --address" , utxostakingaddr
270
- , " --testnet-magic" , show @ Int testnetMagic
271
- , " --out-file" , work </> " stake-address-info-utxo-staking-vkey-2.json"
272
- ]
273
259
274
- userStakeAddrInfoJSON <- H. leftFailM . H. readJsonFile $ work </> " stake-address-info-utxo-staking-vkey-2.json"
275
- delegsAndRewardsMapUser <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ DelegationsAndRewards userStakeAddrInfoJSON
276
- let delegsAndRewardsUser = mergeDelegsAndRewards delegsAndRewardsMapUser
277
- userStakeAddrInfo = filter (\ (sAddr,_,_) -> utxostakingaddr == T. unpack (serialiseAddress sAddr)) delegsAndRewardsUser
278
- (userSAddr, _rewards, _poolId) = head userStakeAddrInfo
260
+ userSAddr <- H. byDurationM 3 12 $ do
261
+ void $ H. execCli' execConfig
262
+ [ " query" , " stake-address-info"
263
+ , " --address" , utxostakingaddr
264
+ , " --testnet-magic" , show @ Int testnetMagic
265
+ , " --out-file" , work </> " stake-address-info-utxo-staking-vkey-2.json"
266
+ ]
279
267
268
+ userStakeAddrInfoJSON <- H. leftFailM . H. readJsonFile $ work </> " stake-address-info-utxo-staking-vkey-2.json"
269
+ delegsAndRewardsMapUser <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ DelegationsAndRewards userStakeAddrInfoJSON
270
+ delegsAndRewardsUser <- H. noteShow $ mergeDelegsAndRewards delegsAndRewardsMapUser
271
+ userStakeAddrInfo <- H. noteShow $ filter (\ (sAddr,_,_) -> utxostakingaddr == T. unpack (serialiseAddress sAddr)) delegsAndRewardsUser
272
+ (userSAddr, _rewards, _poolId) <- H. headM userStakeAddrInfo
273
+ return userSAddr
280
274
281
275
H. note_ $ " Check staking key: " <> show utxoStakingVkey2 <> " was registered"
282
276
T. unpack (serialiseAddress userSAddr) === utxostakingaddr
@@ -295,7 +289,7 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
295
289
296
290
utxo2Json <- H. leftFailM . H. readJsonFile $ work </> " utxo-2.json"
297
291
UTxO utxo2 <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ (UTxO AlonzoEra ) utxo2Json
298
- txin2 <- H. noteShow $ head $ Map. keys utxo2
292
+ txin2 <- H. noteShow =<< H. headM ( Map. keys utxo2)
299
293
300
294
H. note_ " Create delegation certificate of pledger"
301
295
@@ -337,22 +331,19 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
337
331
, " --testnet-magic" , show @ Int testnetMagic
338
332
]
339
333
340
- if H. isLinux
341
- then H. threadDelay 5000000
342
- else H. threadDelay 20000000
343
-
344
- void $ H. execCli' execConfig
345
- [ " query" , " stake-pools"
346
- , " --testnet-magic" , show @ Int testnetMagic
347
- , " --out-file" , work </> " current-registered.pools.json"
348
- ]
334
+ H. byDurationM 3 12 $ do
335
+ void $ H. execCli' execConfig
336
+ [ " query" , " stake-pools"
337
+ , " --testnet-magic" , show @ Int testnetMagic
338
+ , " --out-file" , work </> " current-registered.pools.json"
339
+ ]
349
340
350
- currRegPools <- H. leftFailM . H. readJsonFile $ work </> " current-registered.pools.json"
351
- poolIds <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ (Set PoolId ) currRegPools
352
- poolId <- H. noteShow $ head $ Set. toList poolIds
341
+ currRegPools <- H. leftFailM . H. readJsonFile $ work </> " current-registered.pools.json"
342
+ poolIds <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ (Set PoolId ) currRegPools
343
+ poolId <- H. noteShow =<< H. headM ( Set. toList poolIds)
353
344
354
- H. note_ " Check stake pool was successfully registered"
355
- T. unpack (serialiseToBech32 poolId) === stakePoolId
345
+ H. note_ " Check stake pool was successfully registered"
346
+ T. unpack (serialiseToBech32 poolId) === stakePoolId
356
347
357
348
H. note_ " Check pledge was successfully delegated"
358
349
void $ H. execCli' execConfig
@@ -364,9 +355,10 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
364
355
365
356
pledgeStakeAddrInfoJSON <- H. leftFailM . H. readJsonFile $ work </> " pledge-stake-address-info.json"
366
357
delegsAndRewardsMapPledge <- H. noteShowM $ H. jsonErrorFail $ J. fromJSON @ DelegationsAndRewards pledgeStakeAddrInfoJSON
367
- let delegsAndRewardsPledge = mergeDelegsAndRewards delegsAndRewardsMapPledge
368
- pledgeStakeAddrInfo = filter (\ (sAddr,_,_) -> poolownerstakeaddr == T. unpack (serialiseAddress sAddr)) delegsAndRewardsPledge
369
- (pledgeSAddr, _rewards, pledgerDelegPoolId) = head pledgeStakeAddrInfo
358
+ delegsAndRewardsPledge <- H. noteShow $ mergeDelegsAndRewards delegsAndRewardsMapPledge
359
+ pledgeStakeAddrInfo <- H. noteShow $ filter (\ (sAddr,_,_) -> poolownerstakeaddr == T. unpack (serialiseAddress sAddr)) delegsAndRewardsPledge
360
+
361
+ (pledgeSAddr, _rewards, pledgerDelegPoolId) <- H. headM pledgeStakeAddrInfo
370
362
371
363
H. note_ " Check pledge has been delegated to pool"
372
364
case pledgerDelegPoolId of
@@ -467,4 +459,3 @@ hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman"
467
459
-- TODO: Linking to the node log file like this is fragile.
468
460
spoLogFile <- H. note $ tempAbsPath </> " logs/node-pool1.stdout.log"
469
461
prop_node_minted_block spoLogFile
470
-
0 commit comments