Skip to content

Commit

Permalink
tests: Add tests for decoding actual pack file
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Mar 7, 2019
1 parent 77cd4bd commit 04c8491
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/unit/Cardano/Wallet/PackfileSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ module Cardano.Wallet.PackfileSpec (spec) where

import Prelude

import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8

import Data.Either
( fromRight, isRight )
import Test.Hspec
( Spec, describe, it, shouldBe )
( Spec, describe, it, shouldBe, shouldSatisfy )

import Cardano.Wallet.Binary.Packfile

Expand All @@ -23,6 +26,11 @@ testTwoBlobs = packFileHeader
<> "\0\0\0\11first block\0"
<> "\0\0\0\12second block"

-- Get this file from cardano-http-bridge with:
-- wget -O test/data/epoch-mainnet-104 http://localhost:8080/mainnet/epoch/104
testPackfile :: FilePath
testPackfile = "test/data/epoch-mainnet-104"

spec :: Spec
spec = do
describe "Decoding pack file" $ do
Expand Down Expand Up @@ -56,3 +64,16 @@ spec = do
it "should reject extra data" $ do
let decoded = decodePackfile (packFileHeader <> "a")
decoded `shouldBe` Left (BlobDecodeError "not enough bytes")

describe "Decoding a mainnet pack file" $ do
it "should decode pack file for mainnet epoch 104" $ do
bs <- L8.readFile testPackfile
let decoded = decodePackfile bs
decoded `shouldSatisfy` isRight
length (fromRight [] decoded) `shouldBe` 21600

it "first blocks in pack file for mainnet epoch 104 should be valid" $ do
bs <- L8.readFile testPackfile
let Right (first:second:_) = decodePackfile bs
B8.length first `shouldBe` 648092
B8.length second `shouldBe` 1181

0 comments on commit 04c8491

Please sign in to comment.