From 5af4c62aa69f256409c59dca9661faa603f6236c Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 27 Jun 2024 01:32:28 +0200 Subject: [PATCH 1/6] 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 From 3e2dc23a2ee2a3ef1c24a1641fac7db3a143b402 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 27 Jun 2024 22:05:43 +0200 Subject: [PATCH 2/6] Make empty PoolDistr constructively --- cardano-api/cardano-api.cabal | 2 ++ .../Test/Golden/Cardano/Api/EpochLeadership.hs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index 494692bfc5..be02ce47d6 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -369,6 +369,7 @@ test-suite cardano-api-golden , cardano-ledger-alonzo , cardano-ledger-api ^>= 1.9 , cardano-ledger-babbage >= 1.6.0 + , cardano-ledger-binary , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 , cardano-ledger-shelley , cardano-ledger-shelley-test >= 1.2.0.1 @@ -379,6 +380,7 @@ test-suite cardano-api-golden , hedgehog >= 1.1 , hedgehog-extras ^>= 0.6.1.0 , microlens + , ouroboros-consensus-cardano , ouroboros-network-api , parsec , plutus-core ^>= 1.30 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 index 1a2d90f3c0..827e88ea38 100644 --- 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 @@ -9,18 +9,22 @@ import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotN 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.Ledger (KeyHash (..), StandardCrypto) import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) import Cardano.Api.Query (ProtocolState (..), SerialisedPoolDistribution (SerialisedPoolDistribution)) import Cardano.Api.Shelley (VrfKey, proxyToAsType, unStakePoolKeyHash) +import Cardano.Binary (serialize) import Cardano.Crypto.Seed (mkSeedFromBytes) import Cardano.Ledger.Api.PParams (emptyPParams) +import Cardano.Ledger.Binary.Encoding (toByronCBOR) import Cardano.Slotting.EpochInfo (EpochInfo (..)) import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) +import Ouroboros.Consensus.Shelley.Ledger.Query.Types (PoolDistr (..)) import Ouroboros.Network.Block (Serialised (..)) +import qualified Data.Map as Map import Data.Proxy (Proxy (..)) import qualified Data.Set as Set import Data.Time.Clock (secondsToNominalDiffTime) @@ -44,7 +48,8 @@ test_golden_currentEpochEligibleLeadershipSlots = testProperty "golden EpochLead ptclState = ProtocolState (Serialised "dummyProtocolState") poolid = StakePoolKeyHash { unStakePoolKeyHash = KeyHash "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8" } vrskey = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "") - serPoolDistr = SerialisedPoolDistribution (Serialised "dummyPoolDistr") + poolDistr :: PoolDistr StandardCrypto = PoolDistr Map.empty + serPoolDistr = SerialisedPoolDistribution (Serialised (serialize (toByronCBOR poolDistr))) currentEpoch = EpochNo 4 eEligibileSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey serPoolDistr currentEpoch expectedEligibleSlots = [SlotNo 2, SlotNo 6] From a6ed1be1559e5c3ad5902e997c261e036439f541 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 27 Jun 2024 22:44:43 +0200 Subject: [PATCH 3/6] Make ProtocolState constructively --- cardano-api/cardano-api.cabal | 3 +++ .../Golden/Cardano/Api/EpochLeadership.hs | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index be02ce47d6..cf10726eda 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -373,6 +373,7 @@ test-suite cardano-api-golden , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 , cardano-ledger-shelley , cardano-ledger-shelley-test >= 1.2.0.1 + , cardano-protocol-tpraos , cardano-slotting ^>= 0.2.0.0 , containers , errors @@ -380,7 +381,9 @@ test-suite cardano-api-golden , hedgehog >= 1.1 , hedgehog-extras ^>= 0.6.1.0 , microlens + , ouroboros-consensus , ouroboros-consensus-cardano + , ouroboros-consensus-protocol , ouroboros-network-api , parsec , plutus-core ^>= 1.30 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 index 827e88ea38..8e66ba4b90 100644 --- 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 @@ -1,4 +1,7 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeFamilies #-} module Test.Golden.Cardano.Api.EpochLeadership ( test_golden_currentEpochEligibleLeadershipSlots @@ -9,18 +12,23 @@ import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotN import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) import Cardano.Api.Genesis (shelleyGenesisDefaults) import Cardano.Api.GenesisParameters (EpochSize (..)) -import Cardano.Api.Ledger (KeyHash (..), StandardCrypto) +import Cardano.Api.Ledger (KeyHash (..), StandardCrypto, toCBOR) import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) +import Cardano.Api.Modes (ConsensusProtocol) import Cardano.Api.Query (ProtocolState (..), SerialisedPoolDistribution (SerialisedPoolDistribution)) import Cardano.Api.Shelley (VrfKey, proxyToAsType, unStakePoolKeyHash) -import Cardano.Binary (serialize) +import Cardano.Binary (ToCBOR, serialize) import Cardano.Crypto.Seed (mkSeedFromBytes) import Cardano.Ledger.Api.PParams (emptyPParams) +import Cardano.Ledger.BaseTypes (Nonce (..), WithOrigin (..)) import Cardano.Ledger.Binary.Encoding (toByronCBOR) +import qualified Cardano.Protocol.TPraos.API as API import Cardano.Slotting.EpochInfo (EpochInfo (..)) import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) +import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus +import Ouroboros.Consensus.Protocol.TPraos (TPraosState (..)) import Ouroboros.Consensus.Shelley.Ledger.Query.Types (PoolDistr (..)) import Ouroboros.Network.Block (Serialised (..)) @@ -33,8 +41,16 @@ import qualified Hedgehog as H import Test.Tasty (TestTree) import Test.Tasty.Hedgehog (testProperty) +encodeProtocolState + :: ToCBOR (Consensus.ChainDepState (ConsensusProtocol era)) + => Consensus.ChainDepState (ConsensusProtocol era) + -> ProtocolState era +encodeProtocolState cds = ProtocolState (Serialised pbs) + where pbs = serialize (toCBOR cds) + test_golden_currentEpochEligibleLeadershipSlots :: TestTree -test_golden_currentEpochEligibleLeadershipSlots = testProperty "golden EpochLeadership" $ +test_golden_currentEpochEligibleLeadershipSlots = + testProperty "golden EpochLeadership" $ H.property $ do let sbe = ShelleyBasedEraShelley sGen = shelleyGenesisDefaults @@ -45,7 +61,8 @@ test_golden_currentEpochEligibleLeadershipSlots = testProperty "golden EpochLead , epochInfoSlotLength_ = const (pure $ mkSlotLength 10) } pp = emptyPParams - ptclState = ProtocolState (Serialised "dummyProtocolState") + chainDepState = TPraosState Origin (API.initialChainDepState NeutralNonce Map.empty) + ptclState = encodeProtocolState chainDepState poolid = StakePoolKeyHash { unStakePoolKeyHash = KeyHash "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8" } vrskey = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "") poolDistr :: PoolDistr StandardCrypto = PoolDistr Map.empty From f0b3b6d56cb0f39932e4f938273d4f7021283909 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Sat, 29 Jun 2024 00:54:59 +0200 Subject: [PATCH 4/6] Fix test so that it passes --- .../Golden/Cardano/Api/EpochLeadership.hs | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) 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 index 8e66ba4b90..9cd4ac5e27 100644 --- 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 @@ -7,7 +7,8 @@ module Test.Golden.Cardano.Api.EpochLeadership ( test_golden_currentEpochEligibleLeadershipSlots ) where -import Cardano.Api (deterministicSigningKey) +import Cardano.Api (Key (verificationKeyHash), deterministicSigningKey, + getVerificationKey) import Cardano.Api.Block (EpochNo (..), Hash (StakePoolKeyHash), SlotNo (..)) import Cardano.Api.Eon.ShelleyBasedEra (ShelleyBasedEra (..)) import Cardano.Api.Genesis (shelleyGenesisDefaults) @@ -17,7 +18,7 @@ import Cardano.Api.LedgerState (currentEpochEligibleLeadershipSlots) import Cardano.Api.Modes (ConsensusProtocol) import Cardano.Api.Query (ProtocolState (..), SerialisedPoolDistribution (SerialisedPoolDistribution)) -import Cardano.Api.Shelley (VrfKey, proxyToAsType, unStakePoolKeyHash) +import Cardano.Api.Shelley (Hash (VrfKeyHash), VrfKey, proxyToAsType, unStakePoolKeyHash) import Cardano.Binary (ToCBOR, serialize) import Cardano.Crypto.Seed (mkSeedFromBytes) @@ -29,11 +30,13 @@ import Cardano.Slotting.EpochInfo (EpochInfo (..)) import Cardano.Slotting.Time (RelativeTime (..), mkSlotLength) import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import Ouroboros.Consensus.Protocol.TPraos (TPraosState (..)) -import Ouroboros.Consensus.Shelley.Ledger.Query.Types (PoolDistr (..)) +import Ouroboros.Consensus.Shelley.Ledger.Query.Types (IndividualPoolStake (..), + PoolDistr (..)) import Ouroboros.Network.Block (Serialised (..)) import qualified Data.Map as Map import Data.Proxy (Proxy (..)) +import Data.Ratio ((%)) import qualified Data.Set as Set import Data.Time.Clock (secondsToNominalDiffTime) @@ -54,21 +57,42 @@ test_golden_currentEpochEligibleLeadershipSlots = 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) + eInfo = EpochInfo { epochInfoSize_ = const (Right (EpochSize 100)) + , epochInfoFirst_ = \(EpochNo x) -> pure $ SlotNo (x * 100) + , epochInfoEpoch_ = \(SlotNo x) -> pure $ EpochNo (x `div` 100) + , epochInfoSlotToRelativeTime_ = \(SlotNo x) -> pure $ RelativeTime (secondsToNominalDiffTime (fromIntegral x * 60)) + , epochInfoSlotLength_ = const (pure $ mkSlotLength 100) } pp = emptyPParams chainDepState = TPraosState Origin (API.initialChainDepState NeutralNonce Map.empty) ptclState = encodeProtocolState chainDepState - poolid = StakePoolKeyHash { unStakePoolKeyHash = KeyHash "58eef2925db2789f76ea057c51069e52c5e0a44550f853c6cdf620f8" } - vrskey = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "") - poolDistr :: PoolDistr StandardCrypto = PoolDistr Map.empty + poolid = StakePoolKeyHash { unStakePoolKeyHash = KeyHash "83c5da842d7437e411d3c4db8aaa7a7d2c1642aee932108c9857282d" } + vrskey1 = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "V5UlALekTHL9bIbe3Yb0Kk4T49gn9smf") + VrfKeyHash hash1 = verificationKeyHash $ getVerificationKey vrskey1 + vrskey2 = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "OLjPbWC6JCjSwO4lqUms0EgkinoLoIhz") + VrfKeyHash hash2 = verificationKeyHash $ getVerificationKey vrskey2 + vrskey3 = deterministicSigningKey (proxyToAsType (Proxy :: Proxy VrfKey)) (mkSeedFromBytes "eF0R2dENRrHM8iyb9q7puTw4y2l8e2z4") + VrfKeyHash hash3 = verificationKeyHash $ getVerificationKey vrskey3 + poolDistr :: PoolDistr StandardCrypto = PoolDistr $ + Map.fromList [ ( KeyHash "a2927c1e43974b036d8e6838d410279266946e8a094895cfc748c91d" + , IndividualPoolStake { individualPoolStake = 1 % 3 + , individualPoolStakeVrf = hash1 + } + ) + , ( KeyHash "83c5da842d7437e411d3c4db8aaa7a7d2c1642aee932108c9857282d" + , IndividualPoolStake { individualPoolStake = 1 % 3 + , individualPoolStakeVrf = hash2 + } + ) + , ( KeyHash "362c2c2128ee75ca39690c27b42e809301231098003443669e2b03f3" + , IndividualPoolStake { individualPoolStake = 1 % 3 + , individualPoolStakeVrf = hash3 + } + ) + ] serPoolDistr = SerialisedPoolDistribution (Serialised (serialize (toByronCBOR poolDistr))) currentEpoch = EpochNo 4 - eEligibileSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey serPoolDistr currentEpoch - expectedEligibleSlots = [SlotNo 2, SlotNo 6] + eEligibileSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey1 serPoolDistr currentEpoch + expectedEligibleSlots = [ SlotNo 406, SlotNo 432, SlotNo 437, SlotNo 443, SlotNo 484 ] eligibileSlots <- H.evalEither eEligibileSlots eligibileSlots H.=== Set.fromList expectedEligibleSlots From 65ac3e0af97bc0ee64ef8c6041f908d3ae3f2297 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Mon, 1 Jul 2024 16:24:10 +0200 Subject: [PATCH 5/6] Fix typo spotted by @smelc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Hurlin --- .../Test/Golden/Cardano/Api/EpochLeadership.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index 9cd4ac5e27..901dc4b6c8 100644 --- 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 @@ -92,7 +92,7 @@ test_golden_currentEpochEligibleLeadershipSlots = ] serPoolDistr = SerialisedPoolDistribution (Serialised (serialize (toByronCBOR poolDistr))) currentEpoch = EpochNo 4 - eEligibileSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey1 serPoolDistr currentEpoch + eEligibleSlots = currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid vrskey1 serPoolDistr currentEpoch expectedEligibleSlots = [ SlotNo 406, SlotNo 432, SlotNo 437, SlotNo 443, SlotNo 484 ] - eligibileSlots <- H.evalEither eEligibileSlots - eligibileSlots H.=== Set.fromList expectedEligibleSlots + eligibleSlots <- H.evalEither eEligibleSlots + eligibleSlots H.=== Set.fromList expectedEligibleSlots From 2c2b428c217c3276ae40f1b2d6ee81835acd20bb Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Mon, 1 Jul 2024 17:02:46 +0200 Subject: [PATCH 6/6] Move test to `cardano-api-test` --- cardano-api/cardano-api.cabal | 19 +++++----- .../Test}/Cardano/Api/EpochLeadership.hs | 36 ++++++++++++------- .../test/cardano-api-test/cardano-api-test.hs | 2 ++ 3 files changed, 36 insertions(+), 21 deletions(-) rename cardano-api/test/{cardano-api-golden/Test/Golden => cardano-api-test/Test}/Cardano/Api/EpochLeadership.hs (87%) diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index cf10726eda..275718a708 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -311,12 +311,16 @@ test-suite cardano-api-test , cardano-api , cardano-api:gen , cardano-api:internal + , cardano-binary , cardano-crypto , cardano-crypto-class ^>= 2.1.2 , cardano-crypto-test ^>= 1.5 , cardano-crypto-tests ^>= 2.1 , cardano-ledger-api ^>= 1.9 + , cardano-ledger-binary , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 + , cardano-protocol-tpraos + , cardano-slotting , containers , directory , hedgehog >= 1.1 @@ -324,12 +328,18 @@ test-suite cardano-api-test , hedgehog-quickcheck , interpolatedstring-perl6 , mtl + , ouroboros-consensus + , ouroboros-consensus-cardano + , ouroboros-consensus-protocol + , ouroboros-network-api , QuickCheck , tasty , tasty-hedgehog , tasty-quickcheck + , time other-modules: Test.Cardano.Api.Crypto + Test.Cardano.Api.EpochLeadership Test.Cardano.Api.Eras Test.Cardano.Api.IO Test.Cardano.Api.Json @@ -369,11 +379,9 @@ test-suite cardano-api-golden , cardano-ledger-alonzo , cardano-ledger-api ^>= 1.9 , cardano-ledger-babbage >= 1.6.0 - , cardano-ledger-binary , cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8 , cardano-ledger-shelley , cardano-ledger-shelley-test >= 1.2.0.1 - , cardano-protocol-tpraos , cardano-slotting ^>= 0.2.0.0 , containers , errors @@ -381,10 +389,6 @@ test-suite cardano-api-golden , hedgehog >= 1.1 , hedgehog-extras ^>= 0.6.1.0 , microlens - , ouroboros-consensus - , ouroboros-consensus-cardano - , ouroboros-consensus-protocol - , ouroboros-network-api , parsec , plutus-core ^>= 1.30 , plutus-ledger-api ^>= 1.30 @@ -397,8 +401,7 @@ test-suite cardano-api-golden build-tool-depends: tasty-discover:tasty-discover - other-modules: Test.Golden.Cardano.Api.EpochLeadership - , Test.Golden.Cardano.Api.Genesis + other-modules: 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-test/Test/Cardano/Api/EpochLeadership.hs similarity index 87% rename from cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs rename to cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs index 901dc4b6c8..4e73d29214 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/EpochLeadership.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/EpochLeadership.hs @@ -3,8 +3,8 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} -module Test.Golden.Cardano.Api.EpochLeadership - ( test_golden_currentEpochEligibleLeadershipSlots +module Test.Cardano.Api.EpochLeadership + ( tests ) where import Cardano.Api (Key (verificationKeyHash), deterministicSigningKey, @@ -41,20 +41,23 @@ import qualified Data.Set as Set import Data.Time.Clock (secondsToNominalDiffTime) import qualified Hedgehog as H -import Test.Tasty (TestTree) +import qualified Hedgehog.Extras as H +import Test.Tasty (TestTree, testGroup) import Test.Tasty.Hedgehog (testProperty) -encodeProtocolState - :: ToCBOR (Consensus.ChainDepState (ConsensusProtocol era)) - => Consensus.ChainDepState (ConsensusProtocol era) - -> ProtocolState era -encodeProtocolState cds = ProtocolState (Serialised pbs) - where pbs = serialize (toCBOR cds) +-- +-- The list of all tests +-- +tests :: TestTree +tests = + testGroup "Epoch Leadership" + [ test_currentEpochEligibleLeadershipSlots + ] -test_golden_currentEpochEligibleLeadershipSlots :: TestTree -test_golden_currentEpochEligibleLeadershipSlots = - testProperty "golden EpochLeadership" $ - H.property $ do +test_currentEpochEligibleLeadershipSlots :: TestTree +test_currentEpochEligibleLeadershipSlots = + testProperty "currentEpochEligibleLeadershipSlots happy path" $ + H.propertyOnce $ do let sbe = ShelleyBasedEraShelley sGen = shelleyGenesisDefaults eInfo = EpochInfo { epochInfoSize_ = const (Right (EpochSize 100)) @@ -96,3 +99,10 @@ test_golden_currentEpochEligibleLeadershipSlots = expectedEligibleSlots = [ SlotNo 406, SlotNo 432, SlotNo 437, SlotNo 443, SlotNo 484 ] eligibleSlots <- H.evalEither eEligibleSlots eligibleSlots H.=== Set.fromList expectedEligibleSlots + where + encodeProtocolState + :: ToCBOR (Consensus.ChainDepState (ConsensusProtocol era)) + => Consensus.ChainDepState (ConsensusProtocol era) + -> ProtocolState era + encodeProtocolState cds = ProtocolState (Serialised pbs) + where pbs = serialize (toCBOR cds) diff --git a/cardano-api/test/cardano-api-test/cardano-api-test.hs b/cardano-api/test/cardano-api-test/cardano-api-test.hs index b0322a6f1d..9b8918d350 100644 --- a/cardano-api/test/cardano-api-test/cardano-api-test.hs +++ b/cardano-api/test/cardano-api-test/cardano-api-test.hs @@ -7,6 +7,7 @@ import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncod import qualified Test.Gen.Cardano.Api.Byron import qualified Test.Cardano.Api.Crypto +import qualified Test.Cardano.Api.EpochLeadership import qualified Test.Cardano.Api.Eras import qualified Test.Cardano.Api.IO import qualified Test.Cardano.Api.Json @@ -39,6 +40,7 @@ tests = testGroup "Cardano.Api" [ Test.Gen.Cardano.Api.Byron.tests , Test.Cardano.Api.Crypto.tests + , Test.Cardano.Api.EpochLeadership.tests , Test.Cardano.Api.Eras.tests , Test.Cardano.Api.IO.tests , Test.Cardano.Api.Json.tests