Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-asset coin selection integration: test suite additions #2469

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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