diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/Coin/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/Coin/Gen.hs index 4b6098745e8..1ab0fd857b6 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/Coin/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/Coin/Gen.hs @@ -5,10 +5,7 @@ module Cardano.Wallet.Primitive.Types.Coin.Gen , genCoinSmall , genCoinSmallPositive , genCoinLargePositive - , shrinkCoinAny - , shrinkCoinSmall - , shrinkCoinSmallPositive - , shrinkCoinLargePositive + , shrinkCoin ) where import Prelude @@ -25,9 +22,6 @@ import Test.QuickCheck genCoinAny :: Gen Coin genCoinAny = Coin <$> choose (unCoin minBound, unCoin maxBound) -shrinkCoinAny :: Coin -> [Coin] -shrinkCoinAny (Coin c) = Coin <$> shrink c - -------------------------------------------------------------------------------- -- Coins chosen to be small and possibly zero -------------------------------------------------------------------------------- @@ -35,8 +29,8 @@ shrinkCoinAny (Coin c) = Coin <$> shrink c genCoinSmall :: Gen Coin genCoinSmall = Coin <$> choose (0, 10) -shrinkCoinSmall :: Coin -> [Coin] -shrinkCoinSmall (Coin c) = Coin <$> shrink c +shrinkCoin :: Coin -> [Coin] +shrinkCoin (Coin c) = Coin <$> shrink c -------------------------------------------------------------------------------- -- Coins chosen to be small and strictly positive @@ -45,15 +39,9 @@ shrinkCoinSmall (Coin c) = Coin <$> shrink c genCoinSmallPositive :: Gen Coin genCoinSmallPositive = Coin <$> choose (1, 10) -shrinkCoinSmallPositive :: Coin -> [Coin] -shrinkCoinSmallPositive (Coin c) = Coin <$> filter (> 0) (shrink c) - -------------------------------------------------------------------------------- -- Coins chosen from a large range and strictly positive -------------------------------------------------------------------------------- genCoinLargePositive :: Gen Coin genCoinLargePositive = Coin <$> choose (1, 1_000_000_000_000) - -shrinkCoinLargePositive :: Coin -> [Coin] -shrinkCoinLargePositive (Coin c) = Coin <$> filter (> 0) (shrink c) diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle/Gen.hs index c53af75b297..c6eae42e4bd 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle/Gen.hs @@ -3,8 +3,7 @@ module Cardano.Wallet.Primitive.Types.TokenBundle.Gen , genTokenBundleSmallRange , genTokenBundleSmallRangePositive , genVariableSizedTokenBundle - , shrinkTokenBundleSmallRange - , shrinkTokenBundleSmallRangePositive + , shrinkTokenBundle ) where import Prelude @@ -12,15 +11,11 @@ import Prelude import Cardano.Wallet.Primitive.Types.Coin ( Coin (..) ) import Cardano.Wallet.Primitive.Types.Coin.Gen - ( genCoinSmall - , genCoinSmallPositive - , shrinkCoinSmall - , shrinkCoinSmallPositive - ) + ( genCoinSmall, genCoinSmallPositive, shrinkCoin ) import Cardano.Wallet.Primitive.Types.TokenBundle ( TokenBundle (..) ) import Cardano.Wallet.Primitive.Types.TokenMap.Gen - ( genAssetIdLargeRange, genTokenMapSmallRange, shrinkTokenMapSmallRange ) + ( genAssetIdLargeRange, genTokenMapSmallRange, shrinkTokenMap ) import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.Tx @@ -88,19 +83,13 @@ genTokenBundleSmallRange = TokenBundle <$> genCoinSmall <*> genTokenMapSmallRange -shrinkTokenBundleSmallRange :: TokenBundle -> [TokenBundle] -shrinkTokenBundleSmallRange (TokenBundle c m) = +shrinkTokenBundle :: TokenBundle -> [TokenBundle] +shrinkTokenBundle (TokenBundle c m) = uncurry TokenBundle <$> shrinkInterleaved - (c, shrinkCoinSmall) - (m, shrinkTokenMapSmallRange) + (c, shrinkCoin) + (m, shrinkTokenMap) genTokenBundleSmallRangePositive :: Gen TokenBundle genTokenBundleSmallRangePositive = TokenBundle <$> genCoinSmallPositive <*> genTokenMapSmallRange - -shrinkTokenBundleSmallRangePositive :: TokenBundle -> [TokenBundle] -shrinkTokenBundleSmallRangePositive (TokenBundle c m) = - uncurry TokenBundle <$> shrinkInterleaved - (c, shrinkCoinSmallPositive) - (m, shrinkTokenMapSmallRange) diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap/Gen.hs index 22f483aaf04..8adfab1bdd8 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap/Gen.hs @@ -8,8 +8,8 @@ module Cardano.Wallet.Primitive.Types.TokenMap.Gen , genAssetIdSmallRange , genTokenMapSized , genTokenMapSmallRange - , shrinkAssetIdSmallRange - , shrinkTokenMapSmallRange + , shrinkAssetId + , shrinkTokenMap , AssetIdF (..) ) where @@ -24,13 +24,13 @@ import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen , genTokenPolicyIdLargeRange , genTokenPolicyIdSized , genTokenPolicyIdSmallRange - , shrinkTokenNameSmallRange - , shrinkTokenPolicyIdSmallRange + , shrinkTokenName + , shrinkTokenPolicyId , tokenNamesMediumRange , tokenPolicies ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen - ( genTokenQuantitySized, genTokenQuantitySmall, shrinkTokenQuantitySmall ) + ( genTokenQuantitySized, genTokenQuantitySmall, shrinkTokenQuantity ) import Control.Monad ( replicateM ) import Data.List @@ -78,6 +78,11 @@ genAssetIdSized = sized $ \size -> do <$> resize sizeSquareRoot genTokenPolicyIdSized <*> resize sizeSquareRoot genTokenNameSized +shrinkAssetId :: AssetId -> [AssetId] +shrinkAssetId (AssetId p t) = uncurry AssetId <$> shrinkInterleaved + (p, shrinkTokenPolicyId) + (t, shrinkTokenName) + -------------------------------------------------------------------------------- -- Asset identifiers chosen from a small range (to allow collisions) -------------------------------------------------------------------------------- @@ -87,11 +92,6 @@ genAssetIdSmallRange = AssetId <$> genTokenPolicyIdSmallRange <*> genTokenNameSmallRange -shrinkAssetIdSmallRange :: AssetId -> [AssetId] -shrinkAssetIdSmallRange (AssetId p t) = uncurry AssetId <$> shrinkInterleaved - (p, shrinkTokenPolicyIdSmallRange) - (t, shrinkTokenNameSmallRange) - -------------------------------------------------------------------------------- -- Asset identifiers chosen from a large range (to minimize collisions) -------------------------------------------------------------------------------- @@ -115,6 +115,16 @@ genTokenMapSized = sized $ \size -> do <$> genAssetIdSized <*> genTokenQuantitySized +shrinkTokenMap :: TokenMap -> [TokenMap] +shrinkTokenMap + = fmap TokenMap.fromFlatList + . shrinkList shrinkAssetQuantity + . TokenMap.toFlatList + where + shrinkAssetQuantity (a, q) = shrinkInterleaved + (a, shrinkAssetId) + (q, shrinkTokenQuantity) + -------------------------------------------------------------------------------- -- Token maps with assets and quantities chosen from small ranges -------------------------------------------------------------------------------- @@ -132,16 +142,6 @@ genTokenMapSmallRange = do <$> genAssetIdSmallRange <*> genTokenQuantitySmall -shrinkTokenMapSmallRange :: TokenMap -> [TokenMap] -shrinkTokenMapSmallRange - = fmap TokenMap.fromFlatList - . shrinkList shrinkAssetQuantity - . TokenMap.toFlatList - where - shrinkAssetQuantity (a, q) = shrinkInterleaved - (a, shrinkAssetIdSmallRange) - (q, shrinkTokenQuantitySmall) - -------------------------------------------------------------------------------- -- Filtering functions -------------------------------------------------------------------------------- diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenPolicy/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenPolicy/Gen.hs index fd68d218925..f1c25a1d9fe 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenPolicy/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenPolicy/Gen.hs @@ -7,8 +7,8 @@ module Cardano.Wallet.Primitive.Types.TokenPolicy.Gen , genTokenPolicyIdLargeRange , genTokenPolicyIdSmallRange , mkTokenPolicyId - , shrinkTokenNameSmallRange - , shrinkTokenPolicyIdSmallRange + , shrinkTokenName + , shrinkTokenPolicyId , tokenNamesMediumRange , tokenNamesSmallRange , tokenPolicies @@ -39,6 +39,13 @@ genTokenNameSized :: Gen TokenName genTokenNameSized = sized $ \size -> elements $ UnsafeTokenName . B8.snoc "Token" <$> take size ['A' ..] +shrinkTokenName :: TokenName -> [TokenName] +shrinkTokenName x + | x == simplest = [] + | otherwise = [simplest] + where + simplest = head tokenNamesSmallRange + -------------------------------------------------------------------------------- -- Token names chosen from a small range (to allow collisions) -------------------------------------------------------------------------------- @@ -46,13 +53,6 @@ genTokenNameSized = sized $ \size -> genTokenNameSmallRange :: Gen TokenName genTokenNameSmallRange = elements tokenNamesSmallRange -shrinkTokenNameSmallRange :: TokenName -> [TokenName] -shrinkTokenNameSmallRange x - | x == simplest = [] - | otherwise = [simplest] - where - simplest = head tokenNamesSmallRange - tokenNamesSmallRange :: [TokenName] tokenNamesSmallRange = UnsafeTokenName . B8.snoc "Token" <$> ['A' .. 'D'] @@ -90,8 +90,8 @@ genTokenPolicyIdSized = sized $ \size -> genTokenPolicyIdSmallRange :: Gen TokenPolicyId genTokenPolicyIdSmallRange = elements tokenPolicies -shrinkTokenPolicyIdSmallRange :: TokenPolicyId -> [TokenPolicyId] -shrinkTokenPolicyIdSmallRange x +shrinkTokenPolicyId :: TokenPolicyId -> [TokenPolicyId] +shrinkTokenPolicyId x | x == simplest = [] | otherwise = [simplest] where diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenQuantity/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenQuantity/Gen.hs index 06d695a138a..81055f6ce4c 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/TokenQuantity/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/TokenQuantity/Gen.hs @@ -5,9 +5,7 @@ module Cardano.Wallet.Primitive.Types.TokenQuantity.Gen , genTokenQuantityLarge , genTokenQuantityMassive , genTokenQuantityMixed - , shrinkTokenQuantitySmall - , shrinkTokenQuantitySmallPositive - , shrinkTokenQuantityMixed + , shrinkTokenQuantity , tokenQuantitySmall , tokenQuantityLarge , tokenQuantityMassive @@ -42,9 +40,6 @@ genTokenQuantitySmall = quantityFromInteger <$> oneof , choose (1, quantityToInteger tokenQuantitySmall) ] -shrinkTokenQuantitySmall :: TokenQuantity -> [TokenQuantity] -shrinkTokenQuantitySmall = shrinkTokenQuantity - -------------------------------------------------------------------------------- -- Small strictly-positive token quantities -------------------------------------------------------------------------------- @@ -53,10 +48,6 @@ genTokenQuantitySmallPositive :: Gen TokenQuantity genTokenQuantitySmallPositive = quantityFromInteger <$> choose (1, quantityToInteger tokenQuantitySmall) -shrinkTokenQuantitySmallPositive :: TokenQuantity -> [TokenQuantity] -shrinkTokenQuantitySmallPositive q = quantityFromInteger <$> - filter (> 0) (shrink $ quantityToInteger q) - -------------------------------------------------------------------------------- -- Large token quantities -------------------------------------------------------------------------------- @@ -88,9 +79,6 @@ genTokenQuantityMixed = oneof , genTokenQuantityMassive ] -shrinkTokenQuantityMixed :: TokenQuantity -> [TokenQuantity] -shrinkTokenQuantityMixed = shrinkTokenQuantity - -------------------------------------------------------------------------------- -- Utilities -------------------------------------------------------------------------------- diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types/Tx/Gen.hs b/lib/core/src/Cardano/Wallet/Primitive/Types/Tx/Gen.hs index 32c65c4fc1d..bf919e161f8 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types/Tx/Gen.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types/Tx/Gen.hs @@ -24,7 +24,7 @@ import Cardano.Wallet.Primitive.Types.Hash import Cardano.Wallet.Primitive.Types.TokenBundle ( TokenBundle ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genTokenBundleSmallRange, shrinkTokenBundleSmallRange ) + ( genTokenBundleSmallRange, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.Tx ( TxIn (..), TxOut (..) ) import Control.Monad @@ -119,7 +119,7 @@ genTxOutSmallRange = TxOut shrinkTxOutSmallRange :: TxOut -> [TxOut] shrinkTxOutSmallRange (TxOut a b) = uncurry TxOut <$> shrinkInterleaved (a, shrinkAddressSmallRange) - (b, filter tokenBundleHasNonZeroCoin . shrinkTokenBundleSmallRange) + (b, filter tokenBundleHasNonZeroCoin . shrinkTokenBundle) tokenBundleHasNonZeroCoin :: TokenBundle -> Bool tokenBundleHasNonZeroCoin b = TokenBundle.getCoin b /= Coin 0 diff --git a/lib/core/test/unit/Cardano/Pool/DB/Arbitrary.hs b/lib/core/test/unit/Cardano/Pool/DB/Arbitrary.hs index 0f6a540d746..481724f0708 100644 --- a/lib/core/test/unit/Cardano/Pool/DB/Arbitrary.hs +++ b/lib/core/test/unit/Cardano/Pool/DB/Arbitrary.hs @@ -47,7 +47,7 @@ import Cardano.Wallet.Primitive.Types import Cardano.Wallet.Primitive.Types.Coin ( Coin (..) ) import Cardano.Wallet.Primitive.Types.Coin.Gen - ( genCoinLargePositive, shrinkCoinLargePositive ) + ( genCoinLargePositive, shrinkCoin ) import Cardano.Wallet.Primitive.Types.Hash ( Hash (..) ) import Control.Arrow @@ -141,7 +141,7 @@ instance Arbitrary (Quantity "lovelace" Word64) where arbitrary = Quantity <$> arbitrary instance Arbitrary Coin where - shrink = shrinkCoinLargePositive + shrink = shrinkCoin arbitrary = genCoinLargePositive arbitraryEpochLength :: Word32 diff --git a/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs b/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs index 7f0fb0a159b..3ded4a1744b 100644 --- a/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs @@ -244,11 +244,11 @@ import Cardano.Wallet.Primitive.Types.RewardAccount import Cardano.Wallet.Primitive.Types.TokenBundle ( AssetId (..), TokenBundle ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genTokenBundleSmallRange, shrinkTokenBundleSmallRange ) + ( genTokenBundleSmallRange, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.TokenMap ( TokenMap ) import Cardano.Wallet.Primitive.Types.TokenMap.Gen - ( genAssetIdSmallRange, genTokenMapSmallRange, shrinkTokenMapSmallRange ) + ( genAssetIdSmallRange, genTokenMapSmallRange, shrinkTokenMap ) import Cardano.Wallet.Primitive.Types.TokenPolicy ( AssetDecimals (..) , AssetLogo (..) @@ -1247,9 +1247,6 @@ instance Arbitrary KeyHash where instance Arbitrary (Script Cosigner) where arbitrary = genScriptCosigners -instance Arbitrary ScriptTemplate where - arbitrary = genScriptTemplate - instance Arbitrary ApiCredential where arbitrary = do pubKey <- BS.pack <$> replicateM 32 arbitrary @@ -1304,6 +1301,9 @@ instance Arbitrary ApiSharedWallet where [ ApiSharedWallet . Right <$> arbitrary , ApiSharedWallet . Left <$> arbitrary ] +instance Arbitrary ScriptTemplate where + arbitrary = genScriptTemplate + instance Arbitrary ApiScriptTemplateEntry where arbitrary = genScriptTemplateEntry @@ -2136,12 +2136,12 @@ instance Arbitrary UTxO where return $ UTxO $ Map.fromList utxo instance Arbitrary TokenBundle where - shrink = shrinkTokenBundleSmallRange arbitrary = genTokenBundleSmallRange + shrink = shrinkTokenBundle instance Arbitrary TokenMap where - shrink = shrinkTokenMapSmallRange arbitrary = genTokenMapSmallRange + shrink = shrinkTokenMap instance Arbitrary TxOut where -- Shrink token bundle but not address diff --git a/lib/core/test/unit/Cardano/Wallet/DB/Sqlite/TypesSpec.hs b/lib/core/test/unit/Cardano/Wallet/DB/Sqlite/TypesSpec.hs index 8fbf51c29cc..92d434fe894 100644 --- a/lib/core/test/unit/Cardano/Wallet/DB/Sqlite/TypesSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/DB/Sqlite/TypesSpec.hs @@ -21,7 +21,7 @@ import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen ( genTokenQuantityMixed - , shrinkTokenQuantityMixed + , shrinkTokenQuantity , tokenQuantityLarge , tokenQuantityMassive , tokenQuantitySmall @@ -119,4 +119,4 @@ instance Arbitrary Word31 where instance Arbitrary TokenQuantity where arbitrary = genTokenQuantityMixed - shrink = shrinkTokenQuantityMixed + shrink = shrinkTokenQuantity diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/CoinSelection/MA/RoundRobinSpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/CoinSelection/MA/RoundRobinSpec.hs index ca6f0d07bff..c67f4df8925 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/CoinSelection/MA/RoundRobinSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/CoinSelection/MA/RoundRobinSpec.hs @@ -71,25 +71,21 @@ import Cardano.Wallet.Primitive.Types.Address import Cardano.Wallet.Primitive.Types.Coin ( Coin (..), addCoin ) import Cardano.Wallet.Primitive.Types.Coin.Gen - ( genCoinLargePositive - , genCoinSmall - , genCoinSmallPositive - , shrinkCoinSmallPositive - ) + ( genCoinLargePositive, genCoinSmall, genCoinSmallPositive, shrinkCoin ) import Cardano.Wallet.Primitive.Types.Hash ( Hash (..) ) import Cardano.Wallet.Primitive.Types.TokenBundle ( Flat (..), TokenBundle (..) ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genTokenBundleSmallRangePositive, shrinkTokenBundleSmallRangePositive ) + ( genTokenBundleSmallRangePositive, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.TokenMap ( AssetId (..), TokenMap ) import Cardano.Wallet.Primitive.Types.TokenMap.Gen ( genAssetIdLargeRange , genAssetIdSmallRange , genTokenMapSmallRange - , shrinkAssetIdSmallRange - , shrinkTokenMapSmallRange + , shrinkAssetId + , shrinkTokenMap ) import Cardano.Wallet.Primitive.Types.TokenPolicy ( TokenName (..), TokenPolicyId (..) ) @@ -98,7 +94,7 @@ import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen - ( genTokenQuantitySmallPositive, shrinkTokenQuantitySmallPositive ) + ( genTokenQuantitySmallPositive, shrinkTokenQuantity ) import Cardano.Wallet.Primitive.Types.Tx ( TokenBundleSizeAssessment (..) , TokenBundleSizeAssessor (..) @@ -3482,7 +3478,7 @@ instance Arbitrary a => Arbitrary (AssetCount a) where instance Arbitrary AssetId where arbitrary = genAssetIdSmallRange - shrink = shrinkAssetIdSmallRange + shrink = shrinkAssetId instance Arbitrary Natural where arbitrary = arbitrarySizedNatural @@ -3497,7 +3493,7 @@ instance Arbitrary (MockRoundRobinState TokenName Word8) where instance Arbitrary TokenBundle where arbitrary = genTokenBundleSmallRangePositive - shrink = shrinkTokenBundleSmallRangePositive + shrink = shrinkTokenBundle instance Arbitrary (Large TokenBundle) where arbitrary = fmap Large $ TokenBundle @@ -3520,11 +3516,11 @@ genTokenMapLarge = do instance Arbitrary TokenMap where arbitrary = genTokenMapSmallRange - shrink = shrinkTokenMapSmallRange + shrink = shrinkTokenMap instance Arbitrary TokenQuantity where arbitrary = genTokenQuantitySmallPositive - shrink = shrinkTokenQuantitySmallPositive + shrink = shrinkTokenQuantity instance Arbitrary TxOut where arbitrary = genTxOutSmallRange @@ -3556,7 +3552,7 @@ instance Arbitrary (Small UTxOIndex) where instance Arbitrary Coin where arbitrary = genCoinSmallPositive - shrink = shrinkCoinSmallPositive + shrink = shrinkCoin instance Arbitrary MinCoinValueFor where arbitrary = arbitraryBoundedEnum diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenBundleSpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenBundleSpec.hs index 096489334bb..e6ac12278e8 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenBundleSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenBundleSpec.hs @@ -16,11 +16,11 @@ import Cardano.Numeric.Util import Cardano.Wallet.Primitive.Types.TokenBundle ( TokenBundle (..), add, difference, isCoin, subtract, unsafeSubtract ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genTokenBundleSmallRange, shrinkTokenBundleSmallRange ) + ( genTokenBundleSmallRange, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen - ( genTokenQuantitySmallPositive, shrinkTokenQuantitySmallPositive ) + ( genTokenQuantitySmallPositive, shrinkTokenQuantity ) import Data.Ratio ( (%) ) import Test.Hspec @@ -179,8 +179,8 @@ prop_equipartitionQuantitiesWithUpperBound_sum m maxQuantity = instance Arbitrary TokenBundle where arbitrary = genTokenBundleSmallRange - shrink = shrinkTokenBundleSmallRange + shrink = shrinkTokenBundle instance Arbitrary TokenQuantity where arbitrary = genTokenQuantitySmallPositive - shrink = shrinkTokenQuantitySmallPositive + shrink = shrinkTokenQuantity diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenMapSpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenMapSpec.hs index 641b4b9ab07..7d5a8203651 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenMapSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenMapSpec.hs @@ -25,24 +25,23 @@ import Cardano.Wallet.Primitive.Types.TokenMap.Gen , genAssetIdSmallRange , genTokenMapSized , genTokenMapSmallRange - , shrinkAssetIdSmallRange - , shrinkTokenMapSmallRange + , shrinkAssetId + , shrinkTokenMap ) import Cardano.Wallet.Primitive.Types.TokenPolicy ( TokenName, TokenPolicyId, mkTokenName ) import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen ( genTokenNameSmallRange , genTokenPolicyIdSmallRange - , shrinkTokenNameSmallRange - , shrinkTokenPolicyIdSmallRange + , shrinkTokenName + , shrinkTokenPolicyId ) import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen ( genTokenQuantitySmall , genTokenQuantitySmallPositive - , shrinkTokenQuantitySmall - , shrinkTokenQuantitySmallPositive + , shrinkTokenQuantity ) import Control.Monad ( replicateM ) @@ -1013,11 +1012,11 @@ instance Arbitrary a => Arbitrary (NonEmpty a) where instance Arbitrary AssetId where arbitrary = genAssetIdSmallRange - shrink = shrinkAssetIdSmallRange + shrink = shrinkAssetId instance Arbitrary TokenMap where arbitrary = genTokenMapSmallRange - shrink = shrinkTokenMapSmallRange + shrink = shrinkTokenMap instance Arbitrary (Large TokenMap) where arbitrary = Large <$> do @@ -1035,11 +1034,11 @@ instance Arbitrary (Large TokenMap) where instance Arbitrary TokenName where arbitrary = genTokenNameSmallRange - shrink = shrinkTokenNameSmallRange + shrink = shrinkTokenName instance Arbitrary TokenPolicyId where arbitrary = genTokenPolicyIdSmallRange - shrink = shrinkTokenPolicyIdSmallRange + shrink = shrinkTokenPolicyId instance Arbitrary TokenQuantity where -- We generate small token quantities in order to increase the chance of @@ -1051,8 +1050,8 @@ instance Arbitrary TokenQuantity where -- verify that the token map invariant (that a map contains no -- zero-valued tokens) is maintained. arbitrary = genTokenQuantitySmall - shrink = shrinkTokenQuantitySmall + shrink = shrinkTokenQuantity instance Arbitrary (Positive TokenQuantity) where arbitrary = Positive <$> genTokenQuantitySmallPositive - shrink = fmap Positive . shrinkTokenQuantitySmallPositive . getPositive + shrink = fmap Positive . shrinkTokenQuantity . getPositive diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenQuantitySpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenQuantitySpec.hs index 07388dda545..137d3697931 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenQuantitySpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/TokenQuantitySpec.hs @@ -15,7 +15,7 @@ import Prelude import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen - ( genTokenQuantityMixed, shrinkTokenQuantityMixed ) + ( genTokenQuantityMixed, shrinkTokenQuantity ) import Data.Aeson ( FromJSON (..), ToJSON (..) ) import Data.Proxy @@ -195,4 +195,4 @@ instance Arbitrary TokenQuantity where -- roundtrip serialization works even with large values, both positive and -- negative. arbitrary = genTokenQuantityMixed - shrink = shrinkTokenQuantityMixed + shrink = shrinkTokenQuantity diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/UTxOIndexSpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/UTxOIndexSpec.hs index 7ef4f03657c..48626ede889 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Types/UTxOIndexSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Types/UTxOIndexSpec.hs @@ -14,7 +14,7 @@ import Prelude import Cardano.Wallet.Primitive.Types.TokenMap ( AssetId ) import Cardano.Wallet.Primitive.Types.TokenMap.Gen - ( genAssetIdSmallRange, shrinkAssetIdSmallRange ) + ( genAssetIdSmallRange, shrinkAssetId ) import Cardano.Wallet.Primitive.Types.Tx ( TxIn, TxOut ) import Cardano.Wallet.Primitive.Types.Tx.Gen @@ -686,7 +686,7 @@ txOutIsAdaOnly = TokenBundle.isCoin . view #tokens instance Arbitrary AssetId where arbitrary = genAssetIdSmallRange - shrink = shrinkAssetIdSmallRange + shrink = shrinkAssetId instance Arbitrary UTxOIndex where arbitrary = genUTxOIndexSmall @@ -717,10 +717,10 @@ shrinkSelectionFilterSmallRange = \case Any -> [] WithAdaOnly -> [Any] WithAsset a -> - case WithAsset <$> shrinkAssetIdSmallRange a of + case WithAsset <$> shrinkAssetId a of [] -> [WithAdaOnly] xs -> xs WithAssetOnly a -> - case WithAssetOnly <$> shrinkAssetIdSmallRange a of + case WithAssetOnly <$> shrinkAssetId a of [] -> [WithAsset a] xs -> xs diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/Compatibility/LedgerSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/Compatibility/LedgerSpec.hs index e84cfc29247..fe1639b34d8 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/Compatibility/LedgerSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/Compatibility/LedgerSpec.hs @@ -13,14 +13,11 @@ import Prelude import Cardano.Wallet.Primitive.Types.Coin ( Coin (..) ) import Cardano.Wallet.Primitive.Types.Coin.Gen - ( genCoinAny, shrinkCoinAny ) + ( genCoinAny, shrinkCoin ) import Cardano.Wallet.Primitive.Types.TokenBundle ( Flat (..), TokenBundle ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genFixedSizeTokenBundle - , genTokenBundleSmallRange - , shrinkTokenBundleSmallRange - ) + ( genFixedSizeTokenBundle, genTokenBundleSmallRange, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.TokenPolicy ( TokenName, TokenPolicyId ) import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen @@ -28,7 +25,7 @@ import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen import Cardano.Wallet.Primitive.Types.TokenQuantity ( TokenQuantity (..) ) import Cardano.Wallet.Primitive.Types.TokenQuantity.Gen - ( genTokenQuantityMixed, shrinkTokenQuantityMixed ) + ( genTokenQuantityMixed, shrinkTokenQuantity ) import Cardano.Wallet.Primitive.Types.Tx ( txOutMaxTokenQuantity, txOutMinTokenQuantity ) import Cardano.Wallet.Shelley.Compatibility.Ledger @@ -261,7 +258,7 @@ newtype FixedSize256 a = FixedSize256 { unFixedSize256 :: a } instance Arbitrary Coin where arbitrary = genCoinAny - shrink = shrinkCoinAny + shrink = shrinkCoin instance Arbitrary (ProtocolMinimum Coin) where arbitrary @@ -278,7 +275,7 @@ instance Arbitrary (ProtocolMinimum Coin) where instance Arbitrary TokenBundle where arbitrary = genTokenBundleSmallRange - shrink = shrinkTokenBundleSmallRange + shrink = shrinkTokenBundle instance Arbitrary (FixedSize8 TokenBundle) where arbitrary = FixedSize8 <$> genFixedSizeTokenBundle 8 @@ -302,4 +299,4 @@ instance Arbitrary TokenPolicyId where instance Arbitrary TokenQuantity where arbitrary = genTokenQuantityMixed - shrink = shrinkTokenQuantityMixed + shrink = shrinkTokenQuantity diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/CompatibilitySpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/CompatibilitySpec.hs index e3f540795c4..0991c47a86b 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/CompatibilitySpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/CompatibilitySpec.hs @@ -66,7 +66,7 @@ import Cardano.Wallet.Primitive.Types.TokenBundle.Gen ( genFixedSizeTokenBundle , genTokenBundleSmallRange , genVariableSizedTokenBundle - , shrinkTokenBundleSmallRange + , shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.Tx ( TokenBundleSizeAssessment (..), TokenBundleSizeAssessor (..) ) @@ -726,7 +726,7 @@ instance Show XPrv where instance Arbitrary TokenBundle.TokenBundle where arbitrary = genTokenBundleSmallRange - shrink = shrinkTokenBundleSmallRange + shrink = shrinkTokenBundle newtype FixedSize32 a = FixedSize32 { unFixedSize32 :: a } deriving (Eq, Show) diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs index b6462654804..2b027693b29 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs @@ -61,7 +61,7 @@ import Cardano.Wallet.Primitive.Types.Address import Cardano.Wallet.Primitive.Types.Coin ( Coin (..), coinToInteger ) import Cardano.Wallet.Primitive.Types.Coin.Gen - ( genCoinLargePositive, shrinkCoinLargePositive ) + ( genCoinLargePositive, shrinkCoin ) import Cardano.Wallet.Primitive.Types.Hash ( Hash (..) ) import Cardano.Wallet.Primitive.Types.RewardAccount @@ -69,14 +69,11 @@ import Cardano.Wallet.Primitive.Types.RewardAccount import Cardano.Wallet.Primitive.Types.TokenBundle ( AssetId, TokenBundle, tokenName ) import Cardano.Wallet.Primitive.Types.TokenBundle.Gen - ( genFixedSizeTokenBundle - , genTokenBundleSmallRange - , shrinkTokenBundleSmallRange - ) + ( genFixedSizeTokenBundle, genTokenBundleSmallRange, shrinkTokenBundle ) import Cardano.Wallet.Primitive.Types.TokenPolicy ( TokenName (UnsafeTokenName), TokenPolicyId, unTokenName ) import Cardano.Wallet.Primitive.Types.TokenPolicy.Gen - ( genTokenPolicyIdSmallRange, shrinkTokenPolicyIdSmallRange ) + ( genTokenPolicyIdSmallRange, shrinkTokenPolicyId ) import Cardano.Wallet.Primitive.Types.Tx ( TxConstraints (..) , TxIn (..) @@ -760,7 +757,7 @@ instance Arbitrary (Hash "Tx") where -- instance Arbitrary Coin where arbitrary = genCoinLargePositive - shrink = shrinkCoinLargePositive + shrink = shrinkCoin instance Arbitrary TxOut where arbitrary = TxOut addr <$> genTokenBundleSmallRange @@ -769,7 +766,7 @@ instance Arbitrary TxOut where instance Arbitrary TokenBundle where arbitrary = genTokenBundleSmallRange - shrink = shrinkTokenBundleSmallRange + shrink = shrinkTokenBundle instance Arbitrary TxMetadata where arbitrary = TxMetadata <$> arbitrary @@ -1086,7 +1083,7 @@ instance Arbitrary AssetId where instance Arbitrary TokenPolicyId where arbitrary = genTokenPolicyIdSmallRange - shrink = shrinkTokenPolicyIdSmallRange + shrink = shrinkTokenPolicyId instance Arbitrary (Script KeyHash) where arbitrary = do