Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move generators and shrinkers for
UTxOIndex
to dedicated Gen
module.
- Loading branch information
1 parent
66b6ab7
commit cca7bbc
Showing
3 changed files
with
52 additions
and
24 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
47 changes: 47 additions & 0 deletions
47
lib/core/src/Cardano/Wallet/Primitive/Types/UTxOIndex/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,47 @@ | ||
module Cardano.Wallet.Primitive.Types.UTxOIndex.Gen | ||
( genUTxOIndexSmall | ||
, shrinkUTxOIndexSmall | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Primitive.Types.Tx | ||
( TxIn, TxOut ) | ||
import Cardano.Wallet.Primitive.Types.Tx.Gen | ||
( genTxInSmallRange | ||
, genTxOutSmallRange | ||
, shrinkTxInSmallRange | ||
, shrinkTxOutSmallRange | ||
) | ||
import Cardano.Wallet.Primitive.Types.UTxOIndex | ||
( UTxOIndex ) | ||
import Control.Monad | ||
( replicateM ) | ||
import Test.QuickCheck | ||
( Gen, choose, shrinkList ) | ||
import Test.QuickCheck.Extra | ||
( shrinkInterleaved ) | ||
|
||
import qualified Cardano.Wallet.Primitive.Types.UTxOIndex as UTxOIndex | ||
|
||
genUTxOIndexSmall :: Gen UTxOIndex | ||
genUTxOIndexSmall = do | ||
entryCount <- choose (0, 64) | ||
UTxOIndex.fromSequence <$> replicateM entryCount genEntrySmallRange | ||
|
||
shrinkUTxOIndexSmall :: UTxOIndex -> [UTxOIndex] | ||
shrinkUTxOIndexSmall | ||
= take 16 | ||
. fmap UTxOIndex.fromSequence | ||
. shrinkList shrinkEntrySmallRange | ||
. UTxOIndex.toList | ||
|
||
genEntrySmallRange :: Gen (TxIn, TxOut) | ||
genEntrySmallRange = (,) | ||
<$> genTxInSmallRange | ||
<*> genTxOutSmallRange | ||
|
||
shrinkEntrySmallRange :: (TxIn, TxOut) -> [(TxIn, TxOut)] | ||
shrinkEntrySmallRange (i, o) = uncurry (,) <$> shrinkInterleaved | ||
(i, shrinkTxInSmallRange) | ||
(o, shrinkTxOutSmallRange) |
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