Skip to content

Commit

Permalink
refactoring #13 | define Arbitrary instance for creating consecutive …
Browse files Browse the repository at this point in the history
…blocks
  • Loading branch information
KtorZ committed Mar 11, 2019
1 parent 95928b3 commit c02f1c9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/unit/Cardano/Wallet/BlockSyncerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ instance Arbitrary TickingArgs where
generateBlockChunks n = do
vectorOf n (choose (0, 15))

newtype Blocks = Blocks [(Hash "BlockHeader", Block)]
deriving Show

instance Arbitrary Blocks where
arbitrary = do
n <- arbitrary
let h0 = BlockHeader 1 0 (Hash "initial block")
return $ Blocks $ take n $ iterate next
( blockHeaderHash h0
, Block h0 mempty
)
where
next :: (Hash "BlockHeader", Block) -> (Hash "BlockHeader", Block)
next (prev, b) =
let
epoch = epochIndex (header b)
slot = slotNumber (header b) + 1
h = BlockHeader epoch slot prev
in
(blockHeaderHash h, Block h mempty)


mkConsecutiveTestBlocks
:: Int
Expand All @@ -122,8 +143,6 @@ mkConsecutiveTestBlocks n =
(blockHeaderHash h, Block h mempty)




blockHeaderHash :: BlockHeader -> Hash "BlockHeader"
blockHeaderHash =
Hash . CBOR.toStrictByteString . encodeBlockHeader
Expand Down

0 comments on commit c02f1c9

Please sign in to comment.