Skip to content

Commit

Permalink
Fix shrinker for ProtocolParameters.
Browse files Browse the repository at this point in the history
Currently, the shrinker always returns the empty list:

```hs
> :set -XTypeApplications
> import Cardano.Wallet.Primitive.Types (ProtocolParameters)
> import Cardano.Wallet.DB.Arbitrary
> import Test.QuickCheck
> generate (arbitrary @ProtocolParameters)
ProtocolParameters {decentralizationLevel = ...}
> a = it
> shrink a
[]
```

By using `genericRoundRobinShrink`, we can get actual shrinking:

```hs
> generate (arbitrary @ProtocolParameters)
ProtocolParameters {decentralizationLevel = ...}
> a = it
> length $ shrink a
68
```
  • Loading branch information
jonathanknowles committed Mar 29, 2022
1 parent d602ee8 commit 4d2f641
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/core/test/unit/Cardano/Wallet/DB/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ import Data.Word.Odd
( Word31 )
import Fmt
( Buildable (..), Builder, blockListF', prefixF, suffixF, tupleF )
import Generics.SOP
( NP (..) )
import GHC.Generics
( Generic )
import Numeric.Natural
Expand Down Expand Up @@ -205,6 +207,8 @@ import Test.QuickCheck
)
import Test.QuickCheck.Arbitrary.Generic
( genericArbitrary )
import Test.QuickCheck.Extra
( genericRoundRobinShrink, (<:>), (<@>) )
import Test.Utils.Time
( genUniformTime )

Expand Down Expand Up @@ -665,17 +669,18 @@ arbitrarySharedAccount =
-------------------------------------------------------------------------------}

instance Arbitrary ProtocolParameters where
shrink ProtocolParameters {..} = ProtocolParameters
<$> shrink decentralizationLevel
<*> shrink txParameters
<*> shrink desiredNumberOfStakePools
<*> shrink minimumUTxOvalue
<*> shrink stakeKeyDeposit
<*> shrink eras
<*> shrink maximumCollateralInputCount
<*> shrink minimumCollateralPercentage
<*> shrink executionUnitPrices
<*> pure Nothing
shrink = genericRoundRobinShrink
<@> shrink
<:> shrink
<:> shrink
<:> shrink
<:> shrink
<:> shrink
<:> shrink
<:> shrink
<:> shrink
<:> const [Nothing]
<:> Nil
arbitrary = ProtocolParameters
<$> arbitrary
<*> arbitrary
Expand Down

0 comments on commit 4d2f641

Please sign in to comment.