Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2632: Fix `prop_{create,extend}` in `SelectionSpec`. r=jonathanknowles a=jonathanknowles # Issue Number #2630 / ADP-898 # Summary This PR fixes the following flaky tests: - `Migration.SelectionSpec.prop_create` - `Migration.SelectionSpec.prop_extend` These tests would both fail around 2% of the time, for the same underlying reason. # Testing This PR was tested by running the entire `SelectionSpec` **1000** times. No failures were observed. # Analysis Both `Selection.create` and `Selection.extend` are required to produce a balanced `Selection` where the fee (and fee excess) is minimized. Both of these functions rely on `minimizeFee`: this function is required to be **idempotent**, so that: > `∀ s. minimizeFee (minimizeFee s) == minimizeFee s`. To check that `create` and `extend` produce selections with minimal fees, it's sufficient to verify that the selections they return have fees that _cannot be minimized further_. To do this, our pre-existing property tests _already_ call `minimizeFee` and verify that the result does not change: ```hs verify (feeExcess selection == feeExcessExpected) where (feeExcessExpected, _) = minimizeFee constraints (feeExcess selection, outputs selection) ``` However, in addition to this check, we were needlessly asserting that `balance` should be idempotent. The `balance` function is not actually designed for this: it's designed to always be called with outputs that are minimal in their ada quantities. # Changes This PR: - removes the unnecessary and invalid assertion for the idempotency of `balance`. - makes the pre-condition for `balance` explicit with a documentation comment. - adds an explicit idempotency test for `minimizeFee`. - improves error reporting in case of test failures, by displaying the actual fee excess. Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
- Loading branch information