From 5af4c62aa69f256409c59dca9661faa603f6236c Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 27 Jun 2024 01:32:28 +0200 Subject: [PATCH] Create initial dummy failing test --- cardano-api/cardano-api.cabal | 4 +- .../Golden/Cardano/Api/EpochLeadership.hs | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index 55f004035a..494692bfc5 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -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 @@ -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 diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs new file mode 100644 index 0000000000..1a2d90f3c0 --- /dev/null +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs @@ -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