Skip to content

Commit

Permalink
Add generator module for Address type.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jan 11, 2021
1 parent 6bbc689 commit faac17a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/core/cardano-wallet-core.cabal
Expand Up @@ -207,6 +207,7 @@ library
-- The following modules define QC generators and shrinkers that can
-- be used by both `cardano-wallet-core` and `cardano-wallet`:
--
Cardano.Wallet.Primitive.Types.Address.Gen
Cardano.Wallet.Primitive.Types.Coin.Gen
Cardano.Wallet.Primitive.Types.TokenBundle.Gen
Cardano.Wallet.Primitive.Types.TokenMap.Gen
Expand Down
34 changes: 34 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types/Address/Gen.hs
@@ -0,0 +1,34 @@
module Cardano.Wallet.Primitive.Types.Address.Gen
( genAddressSmallRange
, shrinkAddressSmallRange
)
where

import Prelude

import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Test.QuickCheck
( Gen, elements )

import qualified Data.ByteString.Char8 as B8

--------------------------------------------------------------------------------
-- Addresses chosen from a small range (to allow collisions)
--------------------------------------------------------------------------------

genAddressSmallRange :: Gen (Address)
genAddressSmallRange = elements addresses

shrinkAddressSmallRange :: Address -> [Address]
shrinkAddressSmallRange a = filter (< a) addresses

addresses :: [Address]
addresses = mkAddress <$> ['0' .. '7']

--------------------------------------------------------------------------------
-- Internal utilities
--------------------------------------------------------------------------------

mkAddress :: Char -> Address
mkAddress c = Address $ "ADDR" `B8.snoc` c

0 comments on commit faac17a

Please sign in to comment.