Skip to content

Commit

Permalink
Merge pull request #2469 from input-output-hk/jonathanknowles/multi-a…
Browse files Browse the repository at this point in the history
…sset-coin-selection-integration

Multi-asset coin selection integration: test suite additions
  • Loading branch information
KtorZ authored Jan 27, 2021
2 parents f44e56c + 5e3d602 commit af28496
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ prepareOutputsWith minCoinValueFor = fmap $ \out ->
--
-- inputsSelected ∪ utxoRemaining == utxoAvailable
-- inputsSelected ∩ utxoRemaining == ∅
-- outputsCovered == outputsToCover
--
performSelection
:: forall m. (HasCallStack, MonadRandom m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ prop_prepareOutputsWith_preparedOrExistedBefore minCoinValueDef outs =
-- Performing a selection
--------------------------------------------------------------------------------

-- | The result of calling 'performSelection'.
--
-- We define this type alias to shorten type signatures.
--
type PerformSelectionResult =
Either SelectionError (SelectionResult TokenBundle)

genSelectionCriteria :: Gen UTxOIndex -> Gen SelectionCriteria
genSelectionCriteria genUTxOIndex = do
utxoAvailable <- genUTxOIndex
Expand Down Expand Up @@ -455,12 +462,12 @@ prop_performSelection_small minCoinValueFor costFor (Blind (Small criteria)) =
selectionUnlimited :: Bool
selectionUnlimited = not selectionLimited

selectionSufficient :: Either SelectionError SelectionResult -> Bool
selectionSufficient :: PerformSelectionResult -> Bool
selectionSufficient = \case
Right _ -> True
_ -> False

selectionInsufficient :: Either SelectionError SelectionResult -> Bool
selectionInsufficient :: PerformSelectionResult -> Bool
selectionInsufficient = \case
Left (SelectionInsufficient _) -> True
_ -> False
Expand All @@ -482,7 +489,7 @@ prop_performSelection
:: MinCoinValueFor
-> CostFor
-> Blind SelectionCriteria
-> (Either SelectionError SelectionResult -> Property -> Property)
-> (PerformSelectionResult -> Property -> Property)
-> Property
prop_performSelection minCoinValueFor costFor (Blind criteria) coverage =
monadicIO $ do
Expand Down Expand Up @@ -526,6 +533,7 @@ prop_performSelection minCoinValueFor costFor (Blind criteria) coverage =
== UTxOIndex.insertMany inputsSelected utxoRemaining
assert $ utxoRemaining
== UTxOIndex.deleteMany (fst <$> inputsSelected) utxoAvailable
assert $ view #outputsCovered result == NE.toList outputsToCover
case selectionLimit of
MaximumInputLimit limit ->
assert $ NE.length inputsSelected <= limit
Expand All @@ -538,8 +546,8 @@ prop_performSelection minCoinValueFor costFor (Blind criteria) coverage =
{ inputsSkeleton =
UTxOIndex.fromSequence inputsSelected
, outputsSkeleton =
outputsToCover
, changeSkeleton =
NE.toList outputsToCover
, changeSkeleton = NE.toList $
fmap (TokenMap.getAssets . view #tokens) changeGenerated
}
balanceSelected =
Expand Down Expand Up @@ -885,8 +893,8 @@ linearCost SelectionSkeleton{inputsSkeleton, outputsSkeleton, changeSkeleton}
= Coin
$ fromIntegral
$ UTxOIndex.size inputsSkeleton
+ NE.length outputsSkeleton
+ NE.length changeSkeleton
+ F.length outputsSkeleton
+ F.length changeSkeleton

data MakeChangeData = MakeChangeData
{ inputBundles
Expand Down

0 comments on commit af28496

Please sign in to comment.