diff --git a/test/Spec.hs b/test/Spec.hs index 42290c2ceecf821de3c9865751784c9cf481f11e..c41d9d39912d2f88bbc2a1186749f08745048a5e 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -28,27 +28,31 @@ tests = property $ do share <- forAll shares tripping share Binary.encode decode' - , testCase "known-correct serialized shares round-trip though Share" $ do - -- The files are in "bucket" format. We need to extract the - -- "slot". We do so by stripping a prefix and suffix. To avoid - -- having to parse the prefix, we assert that the suffix is a - -- predictable size. - bucket <- LB.readFile "test/data/3of10.0" - let withoutPrefix = LB.drop (32 + 20 + 32 + 8 + 8 + 368) bucket - dataSize = LB.length withoutPrefix - 4 - shareData = LB.take dataSize withoutPrefix - suffix = LB.drop dataSize withoutPrefix - - -- Our assumption about the data we're working on... - assertEqual "Cannot account for extra leases" suffix "\0\0\0\0" - - let decoded = decode' shareData - let encoded = (Binary.encode :: Share -> LB.ByteString) <$> decoded - assertEqual "original /= encoded" (Right shareData) encoded + , testCase "known-correct serialized shares round-trip though Share" $ + mapM_ knownCorrectRoundTrip [0 :: Int .. 9] ] - where - decode' :: Binary.Binary b => LB.ByteString -> Either (LB.ByteString, ByteOffset, String) b - decode' = ((\(_, _, a) -> a) <$>) . Binary.decodeOrFail + +knownCorrectRoundTrip :: Show a => a -> IO () +knownCorrectRoundTrip n = do + -- The files are in "bucket" format. We need to extract the + -- "slot". We do so by stripping a prefix and suffix. To avoid + -- having to parse the prefix, we assert that the suffix is a + -- predictable size. + bucket <- LB.readFile ("test/data/3of10." <> show n) + let withoutPrefix = LB.drop (32 + 20 + 32 + 8 + 8 + 368) bucket + dataSize = LB.length withoutPrefix - 4 + shareData = LB.take dataSize withoutPrefix + suffix = LB.drop dataSize withoutPrefix + + -- Our assumption about the data we're working on... + assertEqual "Cannot account for extra leases" suffix "\0\0\0\0" + + let decoded = decode' shareData + let encoded = (Binary.encode :: Share -> LB.ByteString) <$> decoded + assertEqual "original /= encoded" (Right shareData) encoded + +decode' :: Binary.Binary b => LB.ByteString -> Either (LB.ByteString, ByteOffset, String) b +decode' = ((\(_, _, a) -> a) <$>) . Binary.decodeOrFail main :: IO () main = do