Skip to content

Commit

Permalink
Merge pull request #50 from input-output-hk/KtorZ/#3/blocksyncer-cove…
Browse files Browse the repository at this point in the history
…rage

Tweak Blocks Generator + Moar Tests + Better Coverage
  • Loading branch information
KtorZ authored Mar 12, 2019
2 parents 1a920d7 + b44073f commit eb3a993
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ test-suite unit
, containers
, hspec
, memory
, hspec-expectations
, QuickCheck
, time-units
type:
Expand Down
17 changes: 10 additions & 7 deletions test/unit/Cardano/Wallet/BlockSyncerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.Wallet.BlockSyncerSpec
( spec
Expand All @@ -26,12 +27,12 @@ import Data.Functor
( ($>) )
import Data.Time.Units
( Millisecond, fromMicroseconds )
import Data.Word
( Word8 )
import Test.Hspec
( Spec, describe, it, shouldReturn )
import Test.QuickCheck
( Arbitrary (..), Property, property, withMaxSuccess )
import Test.QuickCheck.Gen
( Gen, choose )
( Arbitrary (..), Gen, Property, checkCoverage, choose, cover )
import Test.QuickCheck.Monadic
( monadicIO )

Expand All @@ -44,7 +45,7 @@ spec :: Spec
spec = do
describe "Block syncer downloads blocks properly" $ do
it "Check ticking function when blocks are sent"
(withMaxSuccess 10 $ property tickingFunctionTest)
(checkCoverage tickingFunctionTest)


{-------------------------------------------------------------------------------
Expand All @@ -55,7 +56,9 @@ tickingFunctionTest
:: (TickingTime, Blocks)
-> Property
tickingFunctionTest (TickingTime tickTime, Blocks blocks) =
monadicIO $ liftIO $ do
cover 80 (sum (length <$> blocks) /= 0) "Non empty blocks" prop
where
prop = monadicIO $ liftIO $ do
(readerChan, reader) <- mkReader
(writerChan, writer) <- mkWriter blocks
waitFor writerChan $
Expand Down Expand Up @@ -104,7 +107,7 @@ newtype TickingTime = TickingTime Millisecond
instance Arbitrary TickingTime where
-- No shrinking
arbitrary = do
tickTime <- fromMicroseconds . (* 1000) <$> choose (50, 100)
tickTime <- fromMicroseconds . (* 1000) <$> choose (1, 3)
return $ TickingTime tickTime


Expand All @@ -114,7 +117,7 @@ newtype Blocks = Blocks [[Block]]
instance Arbitrary Blocks where
-- No Shrinking
arbitrary = do
n <- arbitrary
n <- fromIntegral . (`mod` 42) <$> arbitrary @Word8
let h0 = BlockHeader 1 0 (Hash "initial block")
let blocks = map snd $ take n $ iterate next
( blockHeaderHash h0
Expand Down

0 comments on commit eb3a993

Please sign in to comment.