Skip to content
Permalink
Browse files

add HandShake to CDDL spec and reverse tests

  • Loading branch information...
MarcFontaine committed Sep 11, 2019
1 parent 91cc387 commit 95a3a3b0df23a7beb0d7ee3eff0e98de66303961
@@ -310,7 +310,12 @@ test-suite cddl
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
@@ -11,7 +11,9 @@

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

import Data.List (nub)
import qualified Data.List.NonEmpty as NonEmpty
@@ -42,6 +42,9 @@ import Ouroboros.Network.Protocol.BlockFetch.Test ()
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)
@@ -52,6 +55,7 @@ type CS = ChainSync BlockHeader (Point BlockHeader)
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"
@@ -130,7 +134,7 @@ decodeMsg (tag, input) = case tag of
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.
@@ -268,5 +272,8 @@ prop_specReqResp = prop_CDDLSpec (1, codecReqResp)
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)
@@ -35,7 +35,7 @@ msgIntersectImproved = [5, point, point]
msgIntersectUnchanged = [6, point]
chainSyncMsgDone = [7]

points = [*point]
points = [ *point ]

; Request Response Protocol
; reference implementation of the codec in
@@ -93,71 +93,66 @@ slotNo = word64
; 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

0 comments on commit 95a3a3b

Please sign in to comment.
You can’t perform that action at this time.