add tests for serialising and deserialising messages

This commit is contained in:
Trolli Schmittlauch 2020-05-09 23:43:39 +02:00
parent 666a9602ba
commit 0d91452641
2 changed files with 6 additions and 4 deletions

View file

@ -71,11 +71,11 @@ chunkLength numParts totalSize = ceiling $ (realToFrac totalSize :: Double) / re
-- The number of parts per message is limited to 150 for DOS protection reasons.
-- The returned byte strings might exceed the desired maximum length, as only the payload (and not all of them)
-- can be split into multiple parts.
serialiseMessage :: FediChordMessage -- mesage to be serialised in preparation for sending
-> Int -- maximum message size in bytes
serialiseMessage :: Int -- maximum message size in bytes
-> FediChordMessage -- mesage to be serialised in preparation for sending
-> [BS.ByteString] -- list of ASN.1 DER encoded messages together representing
-- the contents of the input message
serialiseMessage msg maxBytesLength =
serialiseMessage maxBytesLength msg =
splitPayloadUntilSmallEnough 1
where
splitPayloadUntilSmallEnough numParts

View file

@ -169,7 +169,7 @@ spec = do
stabReqPayload = StabiliseRequestPayload
pingReqPayload = PingRequestPayload
qidResPayload1 = QueryIDResponsePayload {
queryResult = FOUND $ exampleNodeState
queryResult = FOUND exampleNodeState
}
qidResPayload2 = QueryIDResponsePayload {
queryResult = FORWARD $ Set.fromList [
@ -228,6 +228,8 @@ spec = do
encodeDecodeAndCheck $ responseWith Leave lResPayload
encodeDecodeAndCheck $ responseWith Stabilise stabResPayload
encodeDecodeAndCheck $ responseWith Ping pingResPayload
it "messages are encoded and decoded to ASN.1 DER properly" $ do
deserialiseMessage (head $ serialiseMessage 652 $ responseWith Ping pingResPayload) `shouldBe` Right (responseWith Ping pingResPayload)
-- some example data