Skip to content

Commit

Permalink
Create initial dummy failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 1, 2024
1 parent dfaf1e9 commit 5af4c62
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ test-suite cardano-api-golden
, hedgehog >= 1.1
, hedgehog-extras ^>= 0.6.1.0
, microlens
, ouroboros-network-api
, parsec
, plutus-core ^>= 1.30
, plutus-ledger-api ^>= 1.30
Expand All @@ -391,7 +392,8 @@ test-suite cardano-api-golden

build-tool-depends: tasty-discover:tasty-discover

other-modules: Test.Golden.Cardano.Api.Genesis
other-modules: Test.Golden.Cardano.Api.EpochLeadership
, Test.Golden.Cardano.Api.Genesis
, Test.Golden.Cardano.Api.Ledger
, Test.Golden.Cardano.Api.Typed.Script
, Test.Golden.Cardano.Api.Value
Expand Down
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

0 comments on commit 5af4c62

Please sign in to comment.