Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generators and shrinkers for type
UTxOSelection
.
- Loading branch information
1 parent
3b4e54c
commit be3bad0
Showing
2 changed files
with
63 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
62 changes: 62 additions & 0 deletions
62
lib/core/src/Cardano/Wallet/Primitive/Types/UTxOSelection/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,62 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Cardano.Wallet.Primitive.Types.UTxOSelection.Gen | ||
( genUTxOSelection | ||
, genUTxOSelectionNonEmpty | ||
, shrinkUTxOSelection | ||
, shrinkUTxOSelectionNonEmpty | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Primitive.Types.Tx | ||
( TxIn ) | ||
import Cardano.Wallet.Primitive.Types.Tx.Gen | ||
( coarbitraryTxIn ) | ||
import Cardano.Wallet.Primitive.Types.UTxOIndex.Gen | ||
( genUTxOIndex, shrinkUTxOIndex ) | ||
import Cardano.Wallet.Primitive.Types.UTxOSelection | ||
( UTxOSelection, UTxOSelectionNonEmpty ) | ||
import Data.Maybe | ||
( mapMaybe ) | ||
import Test.QuickCheck | ||
( Gen, arbitrary, liftShrink2, shrinkMapBy, suchThatMap ) | ||
import Test.QuickCheck.Extra | ||
( genFunction ) | ||
|
||
import qualified Cardano.Wallet.Primitive.Types.UTxOSelection as UTxOSelection | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Selections that may be empty | ||
-------------------------------------------------------------------------------- | ||
|
||
genUTxOSelection :: Gen UTxOSelection | ||
genUTxOSelection = UTxOSelection.fromIndexFiltered | ||
<$> genUTxOIndex | ||
<*> genFilter | ||
where | ||
genFilter :: Gen (TxIn -> Bool) | ||
genFilter = genFunction coarbitraryTxIn (arbitrary @Bool) | ||
|
||
shrinkUTxOSelection :: UTxOSelection -> [UTxOSelection] | ||
shrinkUTxOSelection = | ||
shrinkMapBy UTxOSelection.fromIndexPair UTxOSelection.toIndexPair $ | ||
liftShrink2 | ||
shrinkUTxOIndex | ||
shrinkUTxOIndex | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Selections that are non-empty | ||
-------------------------------------------------------------------------------- | ||
|
||
genUTxOSelectionNonEmpty :: Gen UTxOSelectionNonEmpty | ||
genUTxOSelectionNonEmpty = | ||
genUTxOSelection `suchThatMap` UTxOSelection.toNonEmpty | ||
|
||
shrinkUTxOSelectionNonEmpty :: UTxOSelectionNonEmpty -> [UTxOSelectionNonEmpty] | ||
shrinkUTxOSelectionNonEmpty | ||
= mapMaybe UTxOSelection.toNonEmpty | ||
. shrinkUTxOSelection | ||
. UTxOSelection.fromNonEmpty | ||
|