-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add coverage for toBalanceConstraintsParams
.
#2962
Add coverage for toBalanceConstraintsParams
.
#2962
Conversation
subtract
in adjustComputeSelectionLimit
.adjustComputeSelectionLimit
.
433d8f0
to
5acc15b
Compare
adjustComputeSelectionLimit
.toBalanceConstraintsParams
.
f9aacc4
to
14d5bac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the walkthrough call. Left one comment / thought.
prop_reduceSelectionLimitBy_lessThanOrEqual | ||
:: SelectionLimit -> Int -> Property | ||
prop_reduceSelectionLimitBy_lessThanOrEqual limit reduction = | ||
prop_reduceSelectionLimitBy_coverage_limit limit .&&. | ||
prop_reduceSelectionLimitBy_coverage_reduction reduction .&&. | ||
limit `reduceSelectionLimitBy` reduction <= limit | ||
|
||
prop_reduceSelectionLimitBy_reductionNegative | ||
:: SelectionLimit -> Negative Int -> Property | ||
prop_reduceSelectionLimitBy_reductionNegative limit (Negative reduction) = | ||
prop_reduceSelectionLimitBy_coverage_limit limit .&&. | ||
limit `reduceSelectionLimitBy` reduction == limit | ||
|
||
prop_reduceSelectionLimitBy_reductionZero | ||
:: SelectionLimit -> Property | ||
prop_reduceSelectionLimitBy_reductionZero limit = | ||
prop_reduceSelectionLimitBy_coverage_limit limit .&&. | ||
limit `reduceSelectionLimitBy` 0 == limit | ||
|
||
prop_reduceSelectionLimitBy_reductionPositive | ||
:: SelectionLimit -> Positive Int -> Property | ||
prop_reduceSelectionLimitBy_reductionPositive limit (Positive reduction) = | ||
prop_reduceSelectionLimitBy_coverage_limit limit .&&. | ||
limit == fmap (+ reduction) (limit `reduceSelectionLimitBy` reduction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
& fst & view #computeMinimumCost | ||
|
||
costOriginal :: Coin | ||
costOriginal = computeMinimumCostOriginal skeleton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again it occurred to me: isn't it strange that the outer constraints contain the unadjusted and wrong minimum cost? If someone were to call the outer computeMinimumCost
they would get the wrong results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone were to call the outer
computeMinimumCost
they would get the wrong results?
The only way a caller could call this function is if they prepared a SelectionSkeleton
externally.
If the caller chose to do this, then the onus would be on the caller to provide a correct SelectionSkeleton
that accurately represented the transaction for which they wanted to compute a minimum cost. But assuming they did prepare an accurate SelectionSkeleton
, then this function would still give them the correct result, since the contract required of computeMinimumCost
is that:
computeMinimumCost skeleton >= actualCostOfSerializedTx skeleton
bors r+ |
Merge conflict. |
This function reduces a selection limit by a given amount. We use this function to replace the incorrect subtraction in `adjustComputeSelectionLimit`. Background: The `subtract` function (from `Prelude`) is equivalent to `flip (-)`, which means that `subtract a b` is equivalent to `b - a`, rather than the other way round. Thanks to @KtorZ for discovering this.
This property verifies that the `toBalanceConstraintsParams` function adjusts the `computeSelectionLimit` function in an appropriate way, namely that: - the selection limit is only reduced when collateral is required; and that - the selection limit is reduced by the correct amount.
This property verifies that the `toBalanceConstraintsParams` function adjusts the `computeMinimumCost` function in an appropriate way, namely that: - the cost is only increased when collateral is required; and that - the cost is increased by the correct amount.
14d5bac
to
e3ea261
Compare
bors r+ |
Build succeeded: |
Issue Number
ADP-1037
Summary
This PR:
subtract
with a dedicated functionreduceSelectionLimitBy
.reduceSelectionLimitBy
has the correct behaviour for all selection limits.toBalanceConstraintsParams
performs the correct adjustment to thecomputeMinimumCost
function.toBalanceConstraintsParams
performs the correct adjustment to thecomputeSelectionLimit
function.Background
The
subtract
function (fromPrelude
) is equivalent toflip (-)
, which means thatsubtract a b
is equivalent tob - a
, rather than the other way round.Thanks to @KtorZ for discovering this.