Skip to content
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

Simplify QC generators for commonly-used types. #2768

Merged
merged 10 commits into from
Jul 27, 2021
Merged

Conversation

rvl
Copy link
Contributor

@rvl rvl commented Jul 20, 2021

Issue Number

#2695

Overview

This PR simplifies the generators (and shrinkers) for the following types:

  • Coin
  • TokenQuantity
  • TokenPolicyId
  • TokenName
  • AssetId

Each type now has a single generator and shrinker that relies on the QC size parameter. These have the following form:

  • genType
  • shrinkType

Where strictly-positive values are required, we also have:

  • genTypePositive
  • shrinkTypePositive

Where values across the full range of a type are required, we also have:

  • genTypeFullRange
  • shrinkTypeFullRange

This PR also adjusts coverage checks for some properties.

Future work

In a future PR, we can simplify generators for TokenMap, TokenBundle, UTxOIndex, TxIn, TxOut.

@rvl rvl force-pushed the jonathanknowles/2695/weeder branch from 48c39be to 4eeb09d Compare July 20, 2021 05:22
@rvl rvl force-pushed the rvl/2695/weeder branch from cb2c01d to 3f6fe49 Compare July 20, 2021 09:51
Base automatically changed from rvl/2695/weeder to master July 20, 2021 14:38
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/2695/weeder branch 2 times, most recently from b37f8bd to c2fad8d Compare July 23, 2021 07:52
@jonathanknowles jonathanknowles changed the title Remove more Gen weeds Simplify QC generators for commonly-used types. Jul 23, 2021
Spotted this refactoring opportunity while reviewing test coverage for UTxO
properties.

The following are equivalent:

- Set.null (a `Set.intersection` b)
- a `Set.disjoint` b
This commit:

  - Renames `genCoinAny` to `genCoinFullRange`, making it clear from the
    name that values are chosen from across the full range of a `Coin`.

  - Gives the generator a slight bias toward the limits of the range,
    but otherwise preserves the uniform distribution across the whole
    range.
Instead of having `genCoinSmall` and `genCoinLarge` variants, we instead
define a single shared generator that makes use of the implicit `size`
parameter.

This commit also adjusts the call sites of these generators to use one
of the following generators, depending on the use case:

- `genCoin`
- `genCoinPositive`
- `genCoinFullRange`
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/2695/weeder branch from c2fad8d to ff2f2bc Compare July 23, 2021 08:15
In this test, the expected numbers of inputs are highly sensitive to the
size distribution of token bundles within generated transaction outputs.

This commit imposes a limit on the sizes of generated token bundles, so
that the expected numbers of inputs are as close as possible to the
previous set of values.
With large values, we want to limit the number of results returned in
order to avoid processing long lists of shrunken values.
estimateMaxInputsTests @IcarusKey
[(1,73),(5,67),(10,63),(20,52),(50,14)]
[(1,73),(5,69),(10,64),(20,54),(50,17)]
Copy link
Member

@jonathanknowles jonathanknowles Jul 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try to retain the old values here, but in the end settled for making the (1, *) pairs match, and getting the rest to match as closely as possible.

@jonathanknowles
Copy link
Member

bors try

iohk-bors bot added a commit that referenced this pull request Jul 23, 2021
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 23, 2021

try

Build failed:

cardano-wallet             >   src/Test/Integration/Scenario/CLI/Network.hs:94:11:
cardano-wallet             >   1) CLI Specifications, COMMON_CLI_NETWORK, CLI_NETWORK - cardano-wallet network information
cardano-wallet             > [cardano-wallet.network:Warning:51730] [2021-07-23 16:59:49.71 UTC] Connection lost with the node. Network.Socket.recvBuf: resource vanished (Connection reset by peer)
cardano-wallet             > [cardano-wallet.network:Warning:51879] [2021-07-23 16:59:49.73 UTC] Connection lost with the node. Network.Socket.recvBuf: resource vanished (Connection reset by peer)
cardano-wallet             >        expected: ExitSuccess
cardano-wallet             >         but got: ExitFailure 1
cardano-wallet             >
cardano-wallet             >   To rerun use: --match "/CLI Specifications/COMMON_CLI_NETWORK/CLI_NETWORK - cardano-wallet network information/"
cardano-wallet             >
cardano-wallet             > Randomized with seed 279127255

@jonathanknowles

This comment has been minimized.

iohk-bors bot added a commit that referenced this pull request Jul 24, 2021
@iohk-bors

This comment has been minimized.

@jonathanknowles
Copy link
Member

bors try

iohk-bors bot added a commit that referenced this pull request Jul 25, 2021
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 25, 2021

try

Build succeeded:

Copy link
Contributor Author

@rvl rvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was kinda hoping the weeds in TokenMap and TokenBundle would be fixed, but thanks.

@rvl rvl merged commit bb25526 into master Jul 27, 2021
@rvl rvl deleted the jonathanknowles/2695/weeder branch July 27, 2021 05:52
@jonathanknowles
Copy link
Member

@rvl wrote:

I was kinda hoping the weeds in TokenMap and TokenBundle would be fixed, but thanks.

That's next on my list: will do this when I get a spare moment!

Thanks for the review. 👍🏻

iohk-bors bot added a commit that referenced this pull request Aug 17, 2021
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles

### Issue Number

Follow-up from #2768
Supports work for #2819 

### Comments

This PR adjusts generators for the following types to use the QC size parameter:
- `Address`
- `Hash "Tx"`
- `TxIndex` (`Word32`)
- `TxIn`
- `TxOut`
- `UTxO`
- `UTxOIndex`

Some minor adjustments to coverage conditions were necessary (but surprisingly few).

This PR also:
- Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators.
- Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators).

Co-authored-by: Jonathan Knowles <[email protected]>
iohk-bors bot added a commit that referenced this pull request Aug 17, 2021
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles

### Issue Number

Follow-up from #2768
Supports work for #2819 

### Comments

This PR adjusts generators for the following types to use the QC size parameter:
- `Address`
- `Hash "Tx"`
- `TxIndex` (`Word32`)
- `TxIn`
- `TxOut`
- `UTxO`
- `UTxOIndex`

Some minor adjustments to coverage conditions were necessary (but surprisingly few).

This PR also:
- Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators.
- Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators).

Co-authored-by: Jonathan Knowles <[email protected]>
iohk-bors bot added a commit that referenced this pull request Aug 17, 2021
2829: Rewrite generators to use the QC size parameter r=jonathanknowles a=jonathanknowles

### Issue Number

Follow-up from #2768
Supports work for #2819 

### Comments

This PR adjusts generators for the following types to use the QC size parameter:
- `Address`
- `Hash "Tx"`
- `TxIndex` (`Word32`)
- `TxIn`
- `TxOut`
- `UTxO`
- `UTxOIndex`

Some minor adjustments to coverage conditions were necessary (but surprisingly few).

This PR also:
- Adds the module `UTxO.Gen`, so that we can generate values of `UTxO` without having to generate indices (which add extra overhead), and redefines the `UTxOIndex` generators in terms of these generators.
- Adds the functions `genSized2` and `genSized2With`, which restore size linearity to generators of compound values (those defined in terms of other generators).

Co-authored-by: Jonathan Knowles <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants