Skip to content

Commit

Permalink
Use UTxOSelection.isSubSelectionOf in prop_runSelection_*.
Browse files Browse the repository at this point in the history
This commit adjusts the `prop_runSelection_*` properties to assert that
the available UTxO (at the start) is always a subselection of the result.
  • Loading branch information
jonathanknowles committed Sep 28, 2021
1 parent 4414b35 commit efbdd18
Showing 1 changed file with 20 additions and 2 deletions.
Expand Up @@ -1229,17 +1229,22 @@ prop_runSelection_UTxO_empty balanceRequested = monadicIO $ do
result <- run $ runSelection
RunSelectionParams
{ selectionLimit = NoLimit
, utxoAvailable = UTxOSelection.fromIndex UTxOIndex.empty
, utxoAvailable
, minimumBalance = balanceRequested
}
let balanceSelected = UTxOSelection.selectedBalance result
let balanceLeftover = UTxOSelection.leftoverBalance result
assertWith
"utxoAvailable `UTxOSelection.isSubSelectionOf` result"
(utxoAvailable `UTxOSelection.isSubSelectionOf` result)
assertWith
"balanceSelected == TokenBundle.empty"
(balanceSelected == TokenBundle.empty)
assertWith
"balanceLeftover == TokenBundle.empty"
(balanceLeftover == TokenBundle.empty)
where
utxoAvailable = UTxOSelection.fromIndex UTxOIndex.empty

prop_runSelection_UTxO_notEnough :: UTxOSelection -> Property
prop_runSelection_UTxO_notEnough utxoAvailable = monadicIO $ do
Expand All @@ -1251,6 +1256,9 @@ prop_runSelection_UTxO_notEnough utxoAvailable = monadicIO $ do
}
let balanceSelected = UTxOSelection.selectedBalance result
let balanceLeftover = UTxOSelection.leftoverBalance result
assertWith
"utxoAvailable `UTxOSelection.isSubSelectionOf` result"
(utxoAvailable `UTxOSelection.isSubSelectionOf` result)
assertWith
"balanceSelected == balanceAvailable"
(balanceSelected == balanceAvailable)
Expand All @@ -1271,6 +1279,9 @@ prop_runSelection_UTxO_exactlyEnough utxoAvailable = monadicIO $ do
}
let balanceSelected = UTxOSelection.selectedBalance result
let balanceLeftover = UTxOSelection.leftoverBalance result
assertWith
"utxoAvailable `UTxOSelection.isSubSelectionOf` result"
(utxoAvailable `UTxOSelection.isSubSelectionOf` result)
assertWith
"balanceLeftover == TokenBundle.empty"
(balanceLeftover == TokenBundle.empty)
Expand Down Expand Up @@ -1310,6 +1321,9 @@ prop_runSelection_UTxO_moreThanEnough utxoAvailable = monadicIO $ do
, "balance leftover:"
, pretty (Flat balanceLeftover)
]
assertWith
"utxoAvailable `UTxOSelection.isSubSelectionOf` result"
(utxoAvailable `UTxOSelection.isSubSelectionOf` result)
assertWith
"balanceRequested `leq` balanceSelected"
(balanceRequested `leq` balanceSelected)
Expand All @@ -1334,7 +1348,7 @@ prop_runSelection_UTxO_muchMoreThanEnough (Blind (Large index)) =
result <- run $ runSelection
RunSelectionParams
{ selectionLimit = NoLimit
, utxoAvailable = UTxOSelection.fromIndex index
, utxoAvailable
, minimumBalance = balanceRequested
}
let balanceSelected = UTxOSelection.selectedBalance result
Expand All @@ -1354,6 +1368,9 @@ prop_runSelection_UTxO_muchMoreThanEnough (Blind (Large index)) =
, "balance leftover:"
, pretty (Flat balanceLeftover)
]
assertWith
"utxoAvailable `UTxOSelection.isSubSelectionOf` result"
(utxoAvailable `UTxOSelection.isSubSelectionOf` result)
assertWith
"balanceRequested `leq` balanceSelected"
(balanceRequested `leq` balanceSelected)
Expand All @@ -1366,6 +1383,7 @@ prop_runSelection_UTxO_muchMoreThanEnough (Blind (Large index)) =
balanceAvailable = view #balance index
balanceRequested = adjustAllTokenBundleQuantities (`div` 256) $
cutAssetSetSizeInHalf balanceAvailable
utxoAvailable = UTxOSelection.fromIndex index

--------------------------------------------------------------------------------
-- Running a selection (non-empty)
Expand Down

0 comments on commit efbdd18

Please sign in to comment.