Skip to content

Commit

Permalink
Move test to cardano-api-test
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 1, 2024
1 parent 65ac3e0 commit 2c2b428
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
19 changes: 11 additions & 8 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,35 @@ 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
, hedgehog-extras
, 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
Expand Down Expand Up @@ -369,22 +379,16 @@ 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
, filepath
, 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions cardano-api/test/cardano-api-test/cardano-api-test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c2b428

Please sign in to comment.