-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Test.Golden.Cardano.Api.EpochLeadership | ||
( test_golden_currentEpochEligibleLeadershipSlots | ||
) where | ||
|
||
import Cardano.Api (deterministicSigningKey) | ||
import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotNo (..)) | ||
import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) | ||
import Cardano.Api.Genesis (shelleyGenesisDefaults) | ||
import Cardano.Api.GenesisParameters (EpochSize (..)) | ||
import Cardano.Api.Ledger (KeyHash (KeyHash)) | ||
import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) | ||
import Cardano.Api.Query (ProtocolState (..), | ||
SerialisedPoolDistribution (SerialisedPoolDistribution)) | ||
import Cardano.Api.Shelley (VrfKey, proxyToAsType, unStakePoolKeyHash) | ||
|
||
import Cardano.Crypto.Seed (mkSeedFromBytes) | ||
import Cardano.Ledger.Api.PParams (emptyPParams) | ||
import Cardano.Slotting.EpochInfo (EpochInfo (..)) | ||
import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) | ||
import Ouroboros.Network.Block (Serialised (..)) | ||
|
||
import Data.Proxy (Proxy (..)) | ||
import qualified Data.Set as Set | ||
import Data.Time.Clock (secondsToNominalDiffTime) | ||
|
||
import qualified Hedgehog as H | ||
import Test.Tasty (TestTree) | ||
import Test.Tasty.Hedgehog (testProperty) | ||
|
||
test_golden_currentEpochEligibleLeadershipSlots :: TestTree | ||
test_golden_currentEpochEligibleLeadershipSlots = testProperty "golden EpochLeadership" $ | ||
H.property $ do | ||
let sbe = ShelleyBasedEraShelley | ||
sGen = shelleyGenesisDefaults | ||
eInfo = EpochInfo { epochInfoSize_ = const (Right (EpochSize 10)) | ||
, epochInfoFirst_ = \(EpochNo x) -> pure $ SlotNo (x * 10) | ||
, epochInfoEpoch_ = \(SlotNo x) -> pure $ EpochNo (x `div` 10) | ||
, epochInfoSlotToRelativeTime_ = \(SlotNo x) -> pure $ RelativeTime (secondsToNominalDiffTime (fromIntegral x * 10)) | ||
, epochInfoSlotLength_ = const (pure $ mkSlotLength 10) | ||
} | ||
pp = emptyPParams | ||
ptclState = ProtocolState (Serialised "dummyProtocolState") | ||
poolid = StakePoolKeyHash { unStakePoolKeyHash = KeyHash "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8" } | ||
vrskey = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "") | ||
serPoolDistr = SerialisedPoolDistribution (Serialised "dummyPoolDistr") | ||
currentEpoch = EpochNo 4 | ||
eEligibileSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey serPoolDistr currentEpoch | ||
expectedEligibleSlots = [SlotNo 2, SlotNo 6] | ||
eligibileSlots <- H.evalEither eEligibileSlots | ||
eligibileSlots H.=== Set.fromList expectedEligibleSlots |