Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generator module for
Address
type.
- Loading branch information
1 parent
6bbc689
commit faac17a
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/core/src/Cardano/Wallet/Primitive/Types/Address/Gen.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |