Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cbor round trip tests for Block for each era #4869

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +34 to +35
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These do not make sense, because block header as defined in this package is never used with Babbage onwards

Suggested change
roundTripBlock @BabbageEra
roundTripBlock @ConwayEra

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wondered about whether it brings any value at all like this, but I agree, no point testing unrealistic stuff.
I will try adding for TxSeq instead!


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)
Comment on lines +37 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add this funciton to the testlib, so it can be used in consensus as well. For this it needs to be parameterized by block header

Suggested change
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)
roundTripBlock ::
forall era bh.
( EraSegWits era
, Arbitrary (Tx era)
) =>
Spec
roundTripBlock =
prop (show (typeRep $ Proxy @(Block bh era))) $
withMaxSuccess 3 $
roundTripAnnEraExpectation @era @(Block bh era)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! good point, thanks.

Loading