Skip to content

Commit

Permalink
Add (failing) property for serialisation roundtrip of events
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Sep 21, 2023
1 parent b5624e3 commit 55c3753
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ test-suite cardano-node-test
Test.Cardano.Node.FilePermissions
Test.Cardano.Node.Gen
Test.Cardano.Node.Json
Test.Cardano.Node.LedgerEvent
Test.Cardano.Node.POM
Test.Cardano.Tracing.OrphanInstances.HardFork

Expand Down
1 change: 1 addition & 0 deletions cardano-node/src/Cardano/Node/LedgerEvent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Cardano.Node.LedgerEvent (
, convertPoolRewards
, ledgerEventName
, eventCodecVersion
, deserializeEvent
, serializeEvent
, tailEvent
) where
Expand Down
28 changes: 28 additions & 0 deletions cardano-node/test/Test/Cardano/Node/LedgerEvent.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Test.Cardano.Node.LedgerEvent where

import Cardano.Node.LedgerEvent
import Data.ByteString.Short(toShort)
import Hedgehog (Property, discover)
import qualified Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range


prop_roundtrip_LedgerEvent_CBOR :: Property
prop_roundtrip_LedgerEvent_CBOR =
Hedgehog.property $ do
event <- Hedgehog.forAll genEvent
Hedgehog.tripping event (serializeEvent maxBound) (deserializeEvent maxBound)

genEvent :: Hedgehog.Gen AnchoredEvent
genEvent =
AnchoredEvent
<$> (toShort <$> Gen.bytes (Range.constant 16 16))
<*> (fromIntegral <$> Gen.word64 Range.constantBounded)
<*> (LedgerStartAtEpoch . fromIntegral <$> Gen.word16 Range.constantBounded)

tests :: IO Bool
tests =
Hedgehog.checkParallel $$discover
2 changes: 2 additions & 0 deletions cardano-node/test/cardano-node-test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import qualified Test.Cardano.Config.Mainnet
import qualified Test.Cardano.Node.FilePermissions
#endif
import qualified Test.Cardano.Node.Json
import qualified Test.Cardano.Node.LedgerEvent
import qualified Test.Cardano.Node.POM
import qualified Test.Cardano.Tracing.OrphanInstances.HardFork

Expand All @@ -32,6 +33,7 @@ main = do
#endif
[ Test.Cardano.Config.Mainnet.tests
, Test.Cardano.Node.Json.tests
, Test.Cardano.Node.LedgerEvent.tests
, Test.Cardano.Node.POM.tests
, Test.Cardano.Tracing.OrphanInstances.HardFork.tests
]

0 comments on commit 55c3753

Please sign in to comment.