Skip to content

Commit

Permalink
tests: Add a couple negative tests for block decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Mar 12, 2019
1 parent 0722b47 commit 4d26c62
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/unit/Cardano/Wallet/BinarySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import Data.ByteString
( ByteString )
import Data.ByteString.Base58
( bitcoinAlphabet, decodeBase58 )
import Data.Either
( isLeft )
import Test.Hspec
( Spec, describe, it, shouldBe )
( Spec, describe, it, shouldBe, shouldSatisfy )

import qualified Codec.CBOR.Decoding as CBOR
import qualified Codec.CBOR.Read as CBOR
Expand Down Expand Up @@ -61,6 +63,17 @@ spec = do
let decoded = unsafeDeserialiseFromBytes decodeBlock bs
decoded `shouldBe` block3

it "should fail to decode a junk block" $ do
let junk = mconcat (replicate 100 "junk")
decoded = CBOR.deserialiseFromBytes decodeBlock junk
decoded `shouldSatisfy` isLeft

it "should fail to decode a block with block header data" $ do
bs <- L8.readFile "test/data/Cardano/Wallet/BinarySpec-block-header-1"
let decoded = CBOR.deserialiseFromBytes decodeBlock bs
decoded `shouldBe`
Left (CBOR.DeserialiseFailure 3 "expected list of length 3")

describe "Encoding Tx" $ do
let txs = Set.toList (transactions block2 <> transactions block3)
let roundTripTx tx = do
Expand Down

0 comments on commit 4d26c62

Please sign in to comment.