-
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 functions {gen,shrink}Tx
to Primitive.Tx.Gen
#2843
Conversation
This enables the `mockHash` function to be used from core modules.
This function is analogous to `liftShrink2`, but can be applied to 6-tuples. This commit could have also added `liftShrink{3,4,5}`, but these are not currently used. They can be added in future, if needed.
These functions make it possible to generate (and shrink) key-value maps with custom generators (and shrinkers) for keys and values.
This change applies individual scaling factors to transaction generators in order to speed up test execution times, without compromising coverage.
forAllShrink (listOf genTxInputs) (shrinkList shrinkTxInputs) | ||
$ \pendingTxInputs -> | ||
inner utxo pendingTxInputs | ||
forAllShrink (scale (`div` 2) $ listOf genTx) (shrinkList shrinkTx) |
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.
Why do we scale (div 2)
here?
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.
Like I think I understand the size paramater, but I'm not sure why we need to divide it by two here.
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.
By using scale (div 2)
, we halve the value of the size parameter passed to all the inner generators of genTx
, meaning that average size of transactions will be halved (even though the actual size may vary).
In testing, I found that this didn't affect the coverage conditions we care about, while making the tests run faster.
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.
In general, users of genTx
can choose the size of transactions to generate by manipulating the size parameter in this way.
It's the same principle for most of the other generators that we provide in Gen
modules. (Since most of these now generate "sized" values, according to the size parameter.)
If you find that you can scale down the size parameter and keep the coverage you want (which should be explicitly tested), then I think it makes sense to do so, as we can reduce the overall test execution time.
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.
We could also have used scale (mod n)
here, for some value of n
, which would place a fixed upper limit on the size of transactions (while still allowing the size to vary).
bors r+ |
2843: Add functions `{gen,shrink}Tx` to `Primitive.Tx.Gen` r=jonathanknowles a=jonathanknowles ### Issue Number ADP-1084 ### Comments This PR adds a reusable generator and shrinker for transactions (of type `Tx`) to the `Primitive.Tx.Gen` module. It uses these functions to simplify or eliminate `Arbitrary` instances in the following modules: - `Cardano.Wallet.Primitive.ModelSpec` - `Cardano.Wallet.Primitive.TypesSpec` - `Cardano.WalletSpec` Co-authored-by: Jonathan Knowles <[email protected]> Co-authored-by: IOHK <[email protected]>
txWithoutIdToTx :: TxWithoutId -> Tx | ||
txWithoutIdToTx t@TxWithoutId {..} = Tx {..} | ||
where | ||
txId = mockHash $ txWithoutIdToTuple t |
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.
We probably don't need to convert to a tuple here, as TxWithoutId
already has a Show
instance:
txId = mockHash $ txWithoutIdToTuple t | |
txId = mockHash t |
Will fix this in follow-up PR.
Build failed: This seems to have been caused by weeder errors: #expected |
7fb845d
to
0551124
Compare
bors r+ |
2843: Add functions `{gen,shrink}Tx` to `Primitive.Tx.Gen` r=jonathanknowles a=jonathanknowles ### Issue Number ADP-1084 ### Comments This PR adds a reusable generator and shrinker for transactions (of type `Tx`) to the `Primitive.Tx.Gen` module. It uses these functions to simplify or eliminate `Arbitrary` instances in the following modules: - `Cardano.Wallet.Primitive.ModelSpec` - `Cardano.Wallet.Primitive.TypesSpec` - `Cardano.WalletSpec` 2844: Lower coverage requirement for `prop_selectRandom_one_withAdaOnly`. r=jonathanknowles a=jonathanknowles This PR lowers a coverage check requirement in `prop_selectRandom_one_withAdaOnly`. It should fix the following failure, which was seen in overnight testing (2 out of 100 runs): ```hs Failures: test/unit/Cardano/Wallet/Primitive/Types/UTxOIndexSpec.hs:144:9: 1) Cardano.Wallet.Primitive.Types.UTxOIndex, Indexed UTxO set properties, Index Selection, prop_selectRandom_one_withAdaOnly Insufficient coverage (after 1600 tests): 85.18% selected an entry Only 85.18% selected an entry, but expected 90.00% To rerun use: --match "/Cardano.Wallet.Primitive.Types.UTxOIndex/Indexed UTxO set properties/Index Selection/prop_selectRandom_one_withAdaOnly/" ``` Co-authored-by: Jonathan Knowles <[email protected]> Co-authored-by: IOHK <[email protected]>
Build failed (retrying...):
|
2843: Add functions `{gen,shrink}Tx` to `Primitive.Tx.Gen` r=jonathanknowles a=jonathanknowles ### Issue Number ADP-1084 ### Comments This PR adds a reusable generator and shrinker for transactions (of type `Tx`) to the `Primitive.Tx.Gen` module. It uses these functions to simplify or eliminate `Arbitrary` instances in the following modules: - `Cardano.Wallet.Primitive.ModelSpec` - `Cardano.Wallet.Primitive.TypesSpec` - `Cardano.WalletSpec` Co-authored-by: Jonathan Knowles <[email protected]> Co-authored-by: IOHK <[email protected]>
bors r+ |
Build succeeded: |
Issue Number
ADP-1084
Comments
This PR adds a reusable generator and shrinker for transactions (of type
Tx
) to thePrimitive.Tx.Gen
module.It uses these functions to simplify or eliminate
Arbitrary
instances in the following modules:Cardano.Wallet.Primitive.ModelSpec
Cardano.Wallet.Primitive.TypesSpec
Cardano.WalletSpec