Skip to content

Commit

Permalink
Add cbor RoundTrip tests for blocks for each era
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Feb 3, 2025
1 parent 513b568 commit 23d176c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libs/cardano-protocol-tpraos/cardano-protocol-tpraos.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ test-suite tests
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test
other-modules: Test.Cardano.Protocol.Binary.CddlSpec
other-modules:
Test.Cardano.Protocol.Binary.CddlSpec
Test.Cardano.Protocol.Binary.RoundTrip
default-language: Haskell2010
ghc-options:
-Wall
Expand All @@ -112,7 +114,12 @@ test-suite tests
build-depends:
base,
bytestring,
cardano-ledger-allegra,
cardano-ledger-alonzo,
cardano-ledger-babbage,
cardano-ledger-binary:{cardano-ledger-binary, testlib},
cardano-ledger-mary,
cardano-ledger-conway:{cardano-ledger-conway, testlib},
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
cardano-protocol-tpraos,
cardano-protocol-tpraos:{cardano-protocol-tpraos, testlib},
2 changes: 2 additions & 0 deletions libs/cardano-protocol-tpraos/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ module Main where

import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Protocol.Binary.CddlSpec as Cddl
import qualified Test.Cardano.Protocol.Binary.RoundTrip as RoundTrip

main :: IO ()
main =
ledgerTestMain $
describe "TPraos" $ do
Cddl.spec
RoundTrip.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.Protocol.Binary.RoundTrip (spec) where

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Babbage (BabbageEra)
import Cardano.Ledger.Block (Block)
import Cardano.Ledger.Conway (ConwayEra)
import Cardano.Ledger.Core
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Protocol.Crypto (StandardCrypto)
import Cardano.Protocol.TPraos.BHeader (BHeader)
import Data.Typeable
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Binary.RoundTrip
import Test.Cardano.Protocol.TPraos.Arbitrary ()

spec :: Spec
spec = do
describe "RoundTrip" $ do
roundTripBlock @ShelleyEra
roundTripBlock @AllegraEra
roundTripBlock @MaryEra
roundTripBlock @AlonzoEra
roundTripBlock @BabbageEra
roundTripBlock @ConwayEra

roundTripBlock ::
forall era.
( EraSegWits era
, Arbitrary (Tx era)
) =>
Spec
roundTripBlock =
prop (show (typeRep $ Proxy @(Block (BHeader StandardCrypto) era))) $
withMaxSuccess 3 $
roundTripAnnEraExpectation @era @(Block (BHeader StandardCrypto) era)

0 comments on commit 23d176c

Please sign in to comment.