diff --git a/ouroboros-network-protocols/CHANGELOG.md b/ouroboros-network-protocols/CHANGELOG.md index 25cd3cf2a24..6e2d7736c80 100644 --- a/ouroboros-network-protocols/CHANGELOG.md +++ b/ouroboros-network-protocols/CHANGELOG.md @@ -1,5 +1,13 @@ # Revision history for ouroboros-network-protocols +## next version + +### Breaking changes + +* Definition of `TxId` has changed, it's now a newtype wrapper for + `Codec.CBOR.Term.Term` type, which indicates that `ouroboros-network` does + not specify what `TxId` or `Tx` types are. + ## 0.5.0.3 -- 2023-05-26 * `ghc-9.6` compatibility diff --git a/ouroboros-network-protocols/test-cddl/specs/common.cddl b/ouroboros-network-protocols/test-cddl/specs/common.cddl index e04d96fab53..0320bd04072 100644 --- a/ouroboros-network-protocols/test-cddl/specs/common.cddl +++ b/ouroboros-network-protocols/test-cddl/specs/common.cddl @@ -21,10 +21,11 @@ origin = [] blockHeaderHash = [slotNo, int] slotNo = word64 -; In `ouroboros-network` we don't know what are tx (and txId), we mock them -; with `int`s, that's because `ouroboros-network` is polymorphic over them. -txId = int -tx = int +; In this spec we don't specify what transaction idenfiers (txId) or +; transactions (tx) are themselves, `ouroboros-network` is polymorphic over +; them. +txId = any +tx = any rejectReason = int word16 = 0..65535 diff --git a/ouroboros-network-protocols/testlib/Ouroboros/Network/Protocol/TxSubmission2/Test.hs b/ouroboros-network-protocols/testlib/Ouroboros/Network/Protocol/TxSubmission2/Test.hs index e52f910babf..1cce0e2addb 100644 --- a/ouroboros-network-protocols/testlib/Ouroboros/Network/Protocol/TxSubmission2/Test.hs +++ b/ouroboros-network-protocols/testlib/Ouroboros/Network/Protocol/TxSubmission2/Test.hs @@ -31,6 +31,7 @@ import Control.Monad.IOSim import Control.Monad.ST (runST) import Control.Tracer (Tracer (..), nullTracer) +import qualified Codec.CBOR.Term as CBOR import Codec.Serialise (DeserialiseFailure, Serialise) import qualified Codec.Serialise as Serialise (decode, encode) @@ -52,6 +53,7 @@ import Test.Ouroboros.Network.Testing.Utils (prop_codec_cborM, prop_codec_valid_cbor_encoding, splits2, splits3) import Test.QuickCheck as QC +import Test.QuickCheck.Instances.ByteString () import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) @@ -94,8 +96,22 @@ instance ShowProxy Tx where txId :: Tx -> TxId txId (Tx txid) = txid -newtype TxId = TxId Int - deriving (Eq, Ord, Show, Arbitrary, Serialise) +-- | We use any `CBOR.Term`. This allows us to use `any` in cddl specs. +-- +newtype TxId = TxId CBOR.Term + deriving (Eq, Ord, Show, Serialise) + +instance Arbitrary TxId where + arbitrary = oneof [ TxId . CBOR.TInt <$> arbitrary + , TxId . CBOR.TBytes <$> arbitrary + , TxId . CBOR.TBool <$> arbitrary + ] + shrink (TxId term) = + case term of + CBOR.TInt a -> TxId . CBOR.TInt <$> shrink a + CBOR.TBytes a -> TxId . CBOR.TBytes <$> shrink a + CBOR.TBool a -> TxId . CBOR.TBool <$> shrink a + _ -> [] instance ShowProxy TxId where showProxy _ = "TxId"