Skip to content

Commit

Permalink
Add LedgerConfig golden test
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEichmann authored and jasagredo committed Feb 17, 2025
1 parent a2d9f4b commit 8becbc0
Show file tree
Hide file tree
Showing 19 changed files with 673 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docs/website/contents/for-developers/AddingAnEra.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ be adding is the Alonzo era, which comes after the Mary era.
* In `Test.Consensus.Cardano.Serialisation`, update `testCodecCfg` and
`dictNestedHdr`.

<<<<<<< HEAD
||||||| parent of 3a95082f7 (Add LedgerConfig golden test)
* In `Test.Consensus.Cardano.Examples`, update `eraExamples`, `combineEras`, and
the rest.

=======
* In `Test.Consensus.Cardano.Examples`, update `eraExamples`,
`mkCardanoExamples`, and the rest.

>>>>>>> 3a95082f7 (Add LedgerConfig golden test)
* In `Test.Consensus.Cardano.Golden`, update the `ToGoldenDirectory` instances.

* Create a `Test.ThreadNet.MaryAlonzo` module similar to
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ examples = Examples {
, exampleQuery = unlabelled exampleQuery
, exampleResult = unlabelled exampleResult
, exampleAnnTip = unlabelled exampleAnnTip
, exampleLedgerConfig = unlabelled ledgerConfig
, exampleLedgerState = unlabelled exampleLedgerState
, exampleChainDepState = unlabelled exampleChainDepState
, exampleExtLedgerState = unlabelled exampleExtLedgerState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<<<<<<< HEAD
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
||||||| parent of 3a95082f7 (Add LedgerConfig golden test)
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
=======
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
>>>>>>> 3a95082f7 (Add LedgerConfig golden test)
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
Expand All @@ -27,10 +37,16 @@ module Test.Consensus.Cardano.Examples (
, examples
) where

<<<<<<< HEAD:ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs
import Data.Coerce (Coercible)
import Data.SOP.BasicFunctors
import Data.SOP.Counting (Exactly (..))
import Data.SOP.Index (Index (..))
||||||| parent of 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
import Data.Coerce (Coercible)
=======
import Data.Coerce (coerce)
>>>>>>> 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
import Data.SOP.Strict
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
Expand All @@ -41,16 +57,70 @@ import Ouroboros.Consensus.HardFork.Combinator
import Ouroboros.Consensus.HardFork.Combinator.Embed.Nary
import qualified Ouroboros.Consensus.HardFork.Combinator.State as State
import qualified Ouroboros.Consensus.HardFork.History as History
import Ouroboros.Consensus.HeaderValidation (AnnTip)
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)
<<<<<<< HEAD
||||||| parent of 3a95082f7 (Add LedgerConfig golden test)
import Ouroboros.Consensus.Protocol.Praos.Translate ()
=======
<<<<<<< HEAD:ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs
import Ouroboros.Consensus.Protocol.Praos.Translate ()
>>>>>>> 3a95082f7 (Add LedgerConfig golden test)
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
||||||| parent of 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
import Ouroboros.Consensus.Storage.Serialisation
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util.Counting (Exactly (..))
import Ouroboros.Consensus.Util.SOP (Index (..))

import Ouroboros.Consensus.HardFork.Combinator
import Ouroboros.Consensus.HardFork.Combinator.Embed.Nary
import qualified Ouroboros.Consensus.HardFork.Combinator.State as State

import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
import qualified Ouroboros.Consensus.Byron.Ledger as Byron

=======
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util.Counting (Exactly (..))
import Ouroboros.Consensus.Util.SOP (Index (..), himap)

import Ouroboros.Consensus.HardFork.Combinator
import Ouroboros.Consensus.HardFork.Combinator.Embed.Nary
import qualified Ouroboros.Consensus.HardFork.Combinator.State as State

import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
import qualified Ouroboros.Consensus.Byron.Ledger as Byron

>>>>>>> 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley
<<<<<<< HEAD:ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
import Ouroboros.Consensus.Storage.Serialisation
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Network.Block (Serialised (..))
||||||| parent of 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs

import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Cardano.CanHardFork ()

import Test.Util.Serialisation.Golden (Examples, Labelled, labelled)
import qualified Test.Util.Serialisation.Golden as Golden
import Test.Util.Serialisation.Roundtrip (SomeResult (..))

=======

import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Cardano.CanHardFork
(ByronPartialLedgerConfig (..),
ShelleyPartialLedgerConfig (..), TriggerHardFork (..))

import Test.Util.Serialisation.Golden (Examples, Labelled, labelled)
import qualified Test.Util.Serialisation.Golden as Golden
import Test.Util.Serialisation.Roundtrip (SomeResult (..))

>>>>>>> 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
import qualified Test.Consensus.Byron.Examples as Byron
import qualified Test.Consensus.Shelley.Examples as Shelley
import Test.Util.Serialisation.Examples (Examples (..), Labelled,
Expand All @@ -72,11 +142,29 @@ eraExamples =

-- | By using this function, we can't forget to update this test when adding a
-- new era to 'CardanoEras'.
combineEras ::
mkCardanoExamples ::
NP Examples (CardanoEras Crypto)
-> Examples (CardanoBlock Crypto)
combineEras = mconcat . hcollapse . hap eraInjections
mkCardanoExamples perEraExamples = Golden.Examples {
exampleBlock = coerce $ viaInject @I (coerce Golden.exampleBlock)
, exampleSerialisedBlock = viaInject Golden.exampleSerialisedBlock
, exampleHeader = viaInject Golden.exampleHeader
, exampleSerialisedHeader = viaInject Golden.exampleSerialisedHeader
, exampleHeaderHash = coerce $ viaInject @WrapHeaderHash (coerce Golden.exampleHeaderHash)
, exampleGenTx = viaInject Golden.exampleGenTx
, exampleGenTxId = coerce $ viaInject @WrapGenTxId (coerce Golden.exampleGenTxId)
, exampleApplyTxErr = coerce $ viaInject @WrapApplyTxErr (coerce Golden.exampleApplyTxErr)
, exampleQuery = viaInject Golden.exampleQuery
, exampleResult = viaInject Golden.exampleResult
, exampleAnnTip = viaInject Golden.exampleAnnTip
, exampleLedgerState = viaInject Golden.exampleLedgerState
, exampleChainDepState = coerce $ viaInject @WrapChainDepState (coerce Golden.exampleChainDepState)
, exampleExtLedgerState = viaInject Golden.exampleExtLedgerState
, exampleSlotNo = coerce $ viaInject @(K SlotNo) (coerce Golden.exampleSlotNo)
, exampleLedgerConfig = exampleLedgerConfigCardano
}
where
<<<<<<< HEAD:ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs
eraInjections :: NP (Examples -.-> K (Examples (CardanoBlock Crypto)))
(CardanoEras Crypto)
eraInjections =
Expand All @@ -97,6 +185,76 @@ combineEras = mconcat . hcollapse . hap eraInjections
injExamples eraName idx =
prefixExamples eraName
. inject exampleStartBounds idx
||||||| parent of 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
eraInjections :: NP (Examples -.-> K (Examples (CardanoBlock Crypto)))
(CardanoEras Crypto)
eraInjections =
fn (K . injExamples "Byron" IZ)
:* fn (K . injExamples "Shelley" (IS IZ))
:* fn (K . injExamples "Allegra" (IS (IS IZ)))
:* fn (K . injExamples "Mary" (IS (IS (IS IZ))))
:* fn (K . injExamples "Alonzo" (IS (IS (IS (IS IZ)))))
:* Nil

injExamples ::
String
-> Index (CardanoEras Crypto) blk
-> Examples blk
-> Examples (CardanoBlock Crypto)
injExamples eraName idx =
Golden.prefixExamples eraName
. inject exampleStartBounds idx
=======
viaInject ::
forall f. Inject f
=> (forall blk. Examples blk -> Labelled (f blk))
-> Labelled (f (CardanoBlock Crypto))
viaInject getExamples =
mconcat
$ hcollapse
$ himap (\ix -> K . inj ix . getExamples) perEraExamplesPrefixed
where
inj :: forall blk. Index (CardanoEras Crypto) blk -> Labelled (f blk) -> Labelled (f (CardanoBlock Crypto))
inj idx = fmap (fmap (inject exampleStartBounds idx))

perEraExamplesPrefixed :: NP Examples (CardanoEras Crypto)
perEraExamplesPrefixed = hzipWith (\(K eraName) es -> Golden.prefixExamples eraName es) perEraNames perEraExamples
where
perEraNames = K "Byron"
:* K "Shelley"
:* K "Allegra"
:* K "Mary"
:* K "Alonzo"
:* Nil

exampleLedgerConfigCardano :: Labelled (HardForkLedgerConfig (CardanoEras Crypto))
exampleLedgerConfigCardano = [
( Nothing
, HardForkLedgerConfig
cardanoShape
(PerEraLedgerConfig (
WrapPartialLedgerConfig (ByronPartialLedgerConfig lcByron (TriggerHardForkAtEpoch shelleyTransitionEpoch))
:* WrapPartialLedgerConfig (ShelleyPartialLedgerConfig lcShelley (TriggerHardForkAtEpoch (History.boundEpoch allegraStartBound)))
:* WrapPartialLedgerConfig (ShelleyPartialLedgerConfig lcAllegra (TriggerHardForkAtEpoch (History.boundEpoch maryStartBound)))
:* WrapPartialLedgerConfig (ShelleyPartialLedgerConfig lcMary (TriggerHardForkAtEpoch (History.boundEpoch alonzoStartBound)))
:* WrapPartialLedgerConfig (ShelleyPartialLedgerConfig lcAlonzo TriggerHardForkNever)
:* Nil))
)
| WrapLedgerConfig lcByron <- labelledLcByron
, WrapLedgerConfig lcShelley <- labelledLcShelley
, WrapLedgerConfig lcAllegra <- labelledLcAllegra
, WrapLedgerConfig lcMary <- labelledLcMary
, WrapLedgerConfig lcAlonzo <- labelledLcAlonzo
]
where
( Comp labelledLcByron
:* Comp labelledLcShelley
:* Comp labelledLcAllegra
:* Comp labelledLcMary
:* Comp labelledLcAlonzo
:* Nil
) = hmap (Comp . fmap (WrapLedgerConfig . snd) . Golden.exampleLedgerConfig) perEraExamples
>>>>>>> 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs

{-------------------------------------------------------------------------------
Inject instances
Expand All @@ -111,6 +269,7 @@ instance Inject SomeResult where
inject _ idx (SomeResult q r) =
SomeResult (QueryIfCurrent (injectQuery idx q)) (Right r)

<<<<<<< HEAD:ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs
instance Inject Examples where
inject startBounds (idx :: Index xs x) Examples {..} = Examples {
exampleBlock = inj (Proxy @I) exampleBlock
Expand Down Expand Up @@ -139,6 +298,37 @@ instance Inject Examples where
=> Proxy f -> Labelled a -> Labelled b
inj p = fmap (fmap (inject' p startBounds idx))

||||||| parent of 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
instance Inject Examples where
inject startBounds (idx :: Index xs x) Golden.Examples {..} = Golden.Examples {
exampleBlock = inj (Proxy @I) exampleBlock
, exampleSerialisedBlock = inj (Proxy @Serialised) exampleSerialisedBlock
, exampleHeader = inj (Proxy @Header) exampleHeader
, exampleSerialisedHeader = inj (Proxy @SerialisedHeader) exampleSerialisedHeader
, exampleHeaderHash = inj (Proxy @WrapHeaderHash) exampleHeaderHash
, exampleGenTx = inj (Proxy @GenTx) exampleGenTx
, exampleGenTxId = inj (Proxy @WrapGenTxId) exampleGenTxId
, exampleApplyTxErr = inj (Proxy @WrapApplyTxErr) exampleApplyTxErr
, exampleQuery = inj (Proxy @(SomeSecond BlockQuery)) exampleQuery
, exampleResult = inj (Proxy @SomeResult) exampleResult
, exampleAnnTip = inj (Proxy @AnnTip) exampleAnnTip
, exampleLedgerState = inj (Proxy @LedgerState) exampleLedgerState
, exampleChainDepState = inj (Proxy @WrapChainDepState) exampleChainDepState
, exampleExtLedgerState = inj (Proxy @ExtLedgerState) exampleExtLedgerState
, exampleSlotNo = exampleSlotNo
}
where
inj ::
forall f a b.
( Inject f
, Coercible a (f x)
, Coercible b (f (HardForkBlock xs))
)
=> Proxy f -> Labelled a -> Labelled b
inj p = fmap (fmap (inject' p startBounds idx))

=======
>>>>>>> 4eff5de98... Add LedgerConfig golden test:ouroboros-consensus-cardano-test/src/Test/Consensus/Cardano/Examples.hs
{-------------------------------------------------------------------------------
Setup
-------------------------------------------------------------------------------}
Expand Down Expand Up @@ -302,7 +492,7 @@ multiEraExamples = mempty {
-- | The examples: the examples from each individual era lifted in to
-- 'CardanoBlock' /and/ the multi-era examples.
examples :: Examples (CardanoBlock Crypto)
examples = combineEras eraExamples <> multiEraExamples
examples = mkCardanoExamples eraExamples <> multiEraExamples

-- | Applying a Shelley thing to a Byron ledger
exampleEraMismatchByron :: MismatchEraInfo (CardanoEras Crypto)
Expand Down
Loading

0 comments on commit 8becbc0

Please sign in to comment.