View on GitHub
File Changes
                       Ouroboros.Network.Protocol.ChainSync.Test
                       Ouroboros.Network.Protocol.Handshake.Codec
                       Ouroboros.Network.Protocol.Handshake.Type
+
                       Ouroboros.Network.Protocol.Handshake.Test
                       Ouroboros.Network.Protocol.Handshake.Version
+
                       Ouroboros.Network.Protocol.TxSubmission.Codec
+
                       Ouroboros.Network.Protocol.TxSubmission.Type
+
                       Ouroboros.Network.Protocol.TxSubmission.Test
+

                      
                       Ouroboros.Network.Testing.ConcreteBlock
                       Test.ChainGenerators
                       Test.Ouroboros.Network.Testing.Utils
+
[email protected]:1567980109
\ No newline at end of file
+
[email protected]:1567980109
\ No newline at end of file

                      
module Ouroboros.Network.Protocol.TxSubmission.Test (
    tests
-
  ) where
+
   ,TxId (..)
+
   ,Tx (..)
+
   ) where

                      
import           Data.List (nub)
import qualified Data.List.NonEmpty as NonEmpty
import Ouroboros.Network.Protocol.Handshake.Codec (codecHandshake)
import Ouroboros.Network.Protocol.Handshake.Type as Handshake
import Ouroboros.Network.Protocol.Handshake.Test (VersionNumber)
+
import Ouroboros.Network.Protocol.TxSubmission.Codec (codecTxSubmission)
+
import Ouroboros.Network.Protocol.TxSubmission.Type as TxSubmission
+
import Ouroboros.Network.Protocol.TxSubmission.Test (TxId, Tx)
import Ouroboros.Network.Block (HeaderHash)

                      
import Ouroboros.Network.Testing.ConcreteBlock (BlockHeader (..), Block)
type RR = ReqResp DummyBytes DummyBytes
type BF = BlockFetch Block
type HS = Handshake VersionNumber CBOR.Term
+
type TS = TxSubmission TxId Tx

                      
specFile :: FilePath
specFile = "test/messages.cddl"
    1 -> tryParsers ["reqResp"]    reqRespParsers
    2 -> tryParsers ["pingPong"]   pingPongParsers
    3 -> tryParsers ["blockFetch"] blockFetchParsers
-
    4 -> return () -- "txSubmissionMessage" in branch
+
    4 -> tryParsers ["txSubmission"] $ error "txSubmission parsers in decodeMsg"
    5 -> tryParsers ["handshake"]  handshakeParsers

                      
    -- Point and list of point.
prop_specBF :: AnyMessageAndAgency BF -> Property
prop_specBF = prop_CDDLSpec (3, codecBlockFetch Serialise.encode (fmap const Serialise.decode) Serialise.encode Serialise.decode)

                      
+
prop_specTxSubmission :: AnyMessageAndAgency TS -> Property
+
prop_specTxSubmission = prop_CDDLSpec (4, codecTxSubmission Serialise.encode Serialise.decode Serialise.encode Serialise.decode)
+

                      
prop_specHandshake :: AnyMessageAndAgency HS -> Property
prop_specHandshake = prop_CDDLSpec (5, codecHandshake)
msgIntersectUnchanged  = [6, point]
chainSyncMsgDone       = [7]

                      
-
points = [*point]
+
points = [ *point ]

                      
; Request Response Protocol
; reference implementation of the codec in
; ouroboros-network/src/Ouroboros/Network/Protocol/TxSubmission/Codec.hs

                      
txSubmissionMessage
-
    = msgGetHashes
-
    / msgSendHashes
-
    / msgGetTx
-
    / msgTx
-
    / txSubmissionMsgDone
-

                      
-
msgGetHashes  = [0,int]
-
msgSendHashes = [1,[txHash]]
-
msgGetTx      = [2,txHash]
-
msgTx         = [3,transaction]
-
txSubmissionMsgDone = [4]
-

                      
-
txHash        = bytes .cbor any
-
transaction   = bytes .cbor any
-

                      
-
; MuxControl Protocol
-
; reference implementation of the codec in
-
; ouroboros-network/src/Ouroboros/Network/Mux/Control.hs
+
    = msgRequestTxIds
+
    / msgReplyTxIds
+
    / msgRequestTxs
+
    / msgReplyTxs
+
    / tsMsgDone

                      
-
muxControlMessage = msgInitReq / msgInitRsp / msgInitFail
+
msgRequestTxIds = [0, tsBlocking, txId, txId]
+
msgReplyTxIds   = [1, [ *txIdAndSize] ]
+
msgRequestTxs   = [2, [ *txId] ]
+
msgReplyTxs     = [3, [ *txId] ]
+
tsMsgDone       = [4]

                      
-
msgInitReq  = [0] ; ToDo
-
msgInitRsp  = [1]
-
msgInitFail = [2]
+
tsBlocking    = false / true
+
txIdAndSize   = [txId, txSizeInBytes]

                      
-
word64 = uint;
+
txId          = int
+
txSizeInBytes = word32

                      
block       = [blockHeader, blockBody]
-
blockHeader = [int, chainHash,word64, word64 , word64, int]
+
blockHeader = [int, chainHash, word64, word64 , word64, int]
chainHash   = genesisHash / blockHash
genesisHash = []
blockHash   = [int]
blockBody   = tstr

                      
-

                      
-
versionNumber = uint .size 4
handshakeMessage =
       msgProposeVersions
     / msgAcceptVersion
     / msgRefuse

                      
-
msgProposeVersions = [0 , versionTable]
+
msgProposeVersions = [0, versionTable]
+
msgAcceptVersion   = [1, versionNumber, extraParams]
+
msgRefuse          = [2, refuseReason ]

                      
; CDDL is not expressive enough to describe the all possible values of proposeVersions.
; proposeVersions is a tables that maps version numbers to version parameters.
; The codec requires that the keys are unique and in ascending order.
-
; This specification only enumerates version numbers from 1..4.
+
; This specification only enumerates version numbers from 0..2.
+

                      
+

                      
+
versionNumber = 0 / 1 / 2  ; The test instance of handshake only supports version numbers 1,2 and 3.
+
; versionNumber = uint     ; A real instance may support for example any unsigned integer as version number.

                      
params = any
extraParams = any
versionTable =
-
    { ? 1 => params
+
    { ? 0 => params
+
    , ? 1 => params
    , ? 2 => params
-
    , ? 3 => params
-
    , ? 4 => params
    }

                      
-
msgAcceptVersion   = [1, versionNumber, extraParams]
-
msgRefuse          = [2, refuseReason ]
-

                      
refuseReason
    = refuseReasonVersionMismatch
    / refuseReasonHandshakeDecodeError
    / refuseReasonRefused

                      
-
refuseReasonVersionMismatch      = [0 , [ versionNumber] ]
-
refuseReasonHandshakeDecodeError = [1 , versionNumber, tstr]
-
refuseReasonRefused              = [2 , versionNumber, tstr]
+
refuseReasonVersionMismatch      = [0, [ *versionNumber ] ]
+
refuseReasonHandshakeDecodeError = [1, versionNumber, tstr]
+
refuseReasonRefused              = [2, versionNumber, tstr]
+

                      
+
word16 = uint
+
word32 = uint
+
word64 = uint