Skip to content
Snippets Groups Projects
Commit 8fe3be49 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Test against all 10 shares

parent aebe0b73
No related branches found
No related tags found
1 merge request!3Add a Binary instance to deserialize from and serialize to the canonical byte representation
......@@ -28,12 +28,17 @@ tests =
property $ do
share <- forAll shares
tripping share Binary.encode decode'
, testCase "known-correct serialized shares round-trip though Share" $ do
, testCase "known-correct serialized shares round-trip though Share" $
mapM_ knownCorrectRoundTrip [0 :: Int .. 9]
]
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.0"
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
......@@ -45,8 +50,7 @@ tests =
let decoded = decode' shareData
let encoded = (Binary.encode :: Share -> LB.ByteString) <$> decoded
assertEqual "original /= encoded" (Right shareData) encoded
]
where
decode' :: Binary.Binary b => LB.ByteString -> Either (LB.ByteString, ByteOffset, String) b
decode' = ((\(_, _, a) -> a) <$>) . Binary.decodeOrFail
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment