forked from schmittlauch/Hash2Pub
add tests for serialising and deserialising messages
This commit is contained in:
parent
666a9602ba
commit
0d91452641
|
@ -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 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)
|
-- 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.
|
-- can be split into multiple parts.
|
||||||
serialiseMessage :: FediChordMessage -- mesage to be serialised in preparation for sending
|
serialiseMessage :: Int -- maximum message size in bytes
|
||||||
-> 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
|
-> [BS.ByteString] -- list of ASN.1 DER encoded messages together representing
|
||||||
-- the contents of the input message
|
-- the contents of the input message
|
||||||
serialiseMessage msg maxBytesLength =
|
serialiseMessage maxBytesLength msg =
|
||||||
splitPayloadUntilSmallEnough 1
|
splitPayloadUntilSmallEnough 1
|
||||||
where
|
where
|
||||||
splitPayloadUntilSmallEnough numParts
|
splitPayloadUntilSmallEnough numParts
|
||||||
|
|
|
@ -169,7 +169,7 @@ spec = do
|
||||||
stabReqPayload = StabiliseRequestPayload
|
stabReqPayload = StabiliseRequestPayload
|
||||||
pingReqPayload = PingRequestPayload
|
pingReqPayload = PingRequestPayload
|
||||||
qidResPayload1 = QueryIDResponsePayload {
|
qidResPayload1 = QueryIDResponsePayload {
|
||||||
queryResult = FOUND $ exampleNodeState
|
queryResult = FOUND exampleNodeState
|
||||||
}
|
}
|
||||||
qidResPayload2 = QueryIDResponsePayload {
|
qidResPayload2 = QueryIDResponsePayload {
|
||||||
queryResult = FORWARD $ Set.fromList [
|
queryResult = FORWARD $ Set.fromList [
|
||||||
|
@ -228,6 +228,8 @@ spec = do
|
||||||
encodeDecodeAndCheck $ responseWith Leave lResPayload
|
encodeDecodeAndCheck $ responseWith Leave lResPayload
|
||||||
encodeDecodeAndCheck $ responseWith Stabilise stabResPayload
|
encodeDecodeAndCheck $ responseWith Stabilise stabResPayload
|
||||||
encodeDecodeAndCheck $ responseWith Ping pingResPayload
|
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
|
-- some example data
|
||||||
|
|
Loading…
Reference in a new issue