-
Notifications
You must be signed in to change notification settings - Fork 214
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 more property tests for distributeSurplus
.
#3243
Add more property tests for distributeSurplus
.
#3243
Conversation
When testing `distributeSurplus`, we definitely want to test the behaviour when the given surplus is zero. The existing `Arbitrary` instance for `Coin` always generates non-zero coins. This commit introduces a helper type `TxBalanceSurplus`, with an `Arbitrary` instance that allows zero-valued coins.
Specifically, check that we cover the case where the surplus is zero.
Fixes issue #3242. This bug caused the following property to sporadically fail: "distributeSurplusDelta, when no change output is present, will burn surplus as excess fees" Example failure seeds: --seed 862218635 --seed 1926926873 --seed 404630283 --seed 1602363838 --seed 1472406660 --seed 31096920 --seed 166643919 Failures were always of the form: ```hs expected: Right (TxFeeAndChange {fee = Coin 1, change = []}) but got: Left (ErrMoreSurplusNeeded (Coin 0)) ``` This indicates that it was possible for `burnSurplusAsFees` to fail with an indicated shortfall of zero. To fix this, we update `burnSurplusAsFees` to only fail if the computed shortfall is non-zero. We also adjust the following property to check that failure cases are covered, and to verify that the shortfall is correct: `prop_distributeSurplusDelta_coversCostIncreaseAndConservesSurplus`
e0ba91a
to
578e50a
Compare
-- | ||
-- - Any increase in cost is covered: | ||
-- If the total cost has increased by 𝛿c, then the fee value | ||
-- will have increased by at least 𝛿c. |
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.
👍
instance Arbitrary (TxBalanceSurplus Coin) where | ||
-- We want to test cases where the surplus is zero. So it's important that | ||
-- we do not restrict ourselves to positive coins here. | ||
arbitrary = TxBalanceSurplus <$> frequency |
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.
Ah! 👍
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.
To be honest, I wonder if not the Arbitrary Coin
instance probably should include Coin 0
.
I tried this, and all the tests in the module seemed to pass. But still out of caution refraining from changing this now. It would be easier to change after we reorganize the module structure.
bors r+ |
Build succeeded: |
Issue
ADP-1514
(Also fixes #3242)
Summary
This PR adds a pair of property tests for
distributeSurplus
:prop_distributeSurplus_onSuccess_conservesSurplus
prop_distributeSurplus_onSuccess_coversCostIncrease
This PR also adds descriptions of these properties to the comment for
TransactionLayer.distributeSurplus
.Finally, this PR also improves test coverage of the surplus value, by defining and using a
TxBalanceSurplus Coin
generator that:Coin
values (previously, this value was excluded).