Skip to content

Commit

Permalink
Added the Size type, Property tests for each Spec type.
Browse files Browse the repository at this point in the history
Added new style RelSpec (SumV) which uses Size as Range.
Moved Size and SumV to own file. SumCond renamed as OrdCond.
Adds class methods adjust, partitionBy, greater, were removed.
Cleanup, restructured Monad(no dependency)
  • Loading branch information
TimSheard authored and lehins committed Mar 21, 2023
1 parent 603e08b commit 0252512
Show file tree
Hide file tree
Showing 22 changed files with 2,044 additions and 1,713 deletions.
Expand Up @@ -42,6 +42,8 @@ import Data.Maybe (catMaybes)
import Data.Typeable (Typeable)
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
import Test.Cardano.Ledger.Binary.Twiddle

-- import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (Mock)
import Test.Cardano.Ledger.Shelley.Serialisation.EraIndepGenerators ()
import Test.Cardano.Ledger.Shelley.Serialisation.Generators ()
import Test.QuickCheck
Expand Down Expand Up @@ -135,7 +137,7 @@ instance
<*> arbitrary

instance
(EraTxOut era, Arbitrary (TxOut era)) =>
(EraTxOut era, Arbitrary (TxOut era), Arbitrary (PParamsUpdate era)) =>
Arbitrary (AlonzoTxBody era)
where
arbitrary =
Expand Down Expand Up @@ -316,7 +318,7 @@ instance Arbitrary TagMismatchDescription where
oneof [pure PassedUnexpectedly, FailedUnexpectedly <$> ((:|) <$> arbitrary <*> arbitrary)]

instance
(Era era, Arbitrary (PredicateFailure (EraRule "PPUP" era))) =>
(Era era, Arbitrary (PPUPPredFailure era)) =>
Arbitrary (AlonzoUtxosPredFailure era)
where
arbitrary =
Expand Down
Expand Up @@ -21,6 +21,7 @@ import Data.Int (Int64)
import Data.Sequence.Strict (StrictSeq, fromList)
import Generic.Random (genericArbitraryU)
import Test.Cardano.Ledger.Binary.Random (mkDummyHash)
import Test.Cardano.Ledger.Mary.ValueSpec ()
import Test.Cardano.Ledger.Shelley.Generator.TxAuxData (genMetadata')
import Test.Cardano.Ledger.Shelley.Serialisation.Generators ()
import Test.QuickCheck (
Expand Down Expand Up @@ -82,9 +83,8 @@ instance
forall era c.
( Era era
, c ~ EraCrypto era
, Crypto c
, FromCBOR (Annotator (Timelock era))
, ToCBOR (Script era)
, DecCBOR (Annotator (Timelock era))
, EncCBOR (Script era)
, Arbitrary (Script era)
) =>
Arbitrary (AllegraTxAuxData era)
Expand Down Expand Up @@ -112,7 +112,6 @@ genScriptSeq = do

instance
( Era era
, Crypto (EraCrypto era)
, Arbitrary (Value era)
, Arbitrary (TxOut era)
, Arbitrary (PPUPPredFailure era)
Expand All @@ -122,7 +121,7 @@ instance
arbitrary = genericArbitraryU

instance
(EraTxOut era, Crypto (EraCrypto era), Arbitrary (TxOut era)) =>
(EraTxOut era, Arbitrary (TxOut era), Arbitrary (PParamsUpdate era)) =>
Arbitrary (AllegraTxBody era)
where
arbitrary =
Expand All @@ -141,7 +140,7 @@ instance
-------------------------------------------------------------------------------}

instance
(EraTxOut era, Crypto (EraCrypto era), Arbitrary (TxOut era)) =>
(EraTxOut era, Arbitrary (TxOut era), Arbitrary (PParamsUpdate era)) =>
Arbitrary (MaryTxBody era)
where
arbitrary =
Expand All @@ -154,28 +153,7 @@ instance
<*> arbitrary
<*> scale (`div` 15) arbitrary
<*> arbitrary
<*> arbitrary
<*> genMintValues

instance Crypto c => Arbitrary (PolicyID c) where
arbitrary = PolicyID <$> arbitrary

instance Crypto c => Arbitrary (MultiAsset c) where
arbitrary = MultiAsset <$> arbitrary

instance Crypto c => Arbitrary (MaryValue c) where
arbitrary = MaryValue <$> (fromIntegral <$> positives) <*> (multiAssetFromListBounded <$> triples)
where
triples = arbitrary :: Gen [(PolicyID c, AssetName, Word64)]
positives = arbitrary :: Gen Word64

shrink (MaryValue ada assets) =
concat
[ -- Shrink the ADA value
flip MaryValue assets <$> shrink ada
, -- Shrink the non-ADA assets by reducing the list length
MaryValue ada <$> shrink assets
]
<*> scale (`div` 15) genMintValues

-- | When generating values for the mint field, we do two things:
--
Expand Down
Expand Up @@ -25,8 +25,6 @@ import Cardano.Ledger.BaseTypes (
BlockNo (..),
SlotNo (..),
)
import Cardano.Ledger.Coin (CompactForm (..))
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Crypto (Crypto, DSIGN)
import Cardano.Ledger.Shelley.API hiding (SignedDSIGN)
import Cardano.Ledger.Shelley.Core
Expand Down Expand Up @@ -91,10 +89,7 @@ instance Mock c => Arbitrary (BHeader c) where -- TODO: Move to TPraos
instance Crypto c => Arbitrary (TP.HashHeader c) where -- TODO: Move to TPraos
arbitrary = TP.HashHeader <$> arbitrary

instance Era era => Arbitrary (ProposedPPUpdates era) where
arbitrary = ProposedPPUpdates <$> pure Map.empty

instance Era era => Arbitrary (Update era) where
instance (Era era, Arbitrary (PParamsUpdate era)) => Arbitrary (Update era) where
arbitrary = genericArbitraryU
shrink = genericShrink

Expand Down Expand Up @@ -132,12 +127,6 @@ instance Era era => Arbitrary (ShelleyTxAuxData era) where
maxTxWits :: Int
maxTxWits = 5

instance
(Core.EraTxOut era, Arbitrary (Core.Value era)) =>
Arbitrary (ShelleyTxOut era)
where
arbitrary = ShelleyTxOut <$> arbitrary <*> arbitrary

instance Arbitrary MIRPot where
arbitrary = genericArbitraryU

Expand Down Expand Up @@ -188,90 +177,6 @@ instance Crypto c => Arbitrary (DCert c) where
arbitrary = genericArbitraryU
shrink = genericShrink


instance Era era => Arbitrary (PPUPState era) where
arbitrary = genericArbitraryU
shrink = genericShrink

instance Crypto c => Arbitrary (DPState c) where
arbitrary = genericArbitraryU
shrink = genericShrink

instance
( Core.EraTxOut era
, Arbitrary (Core.TxOut era)
, Arbitrary (State (Core.EraRule "PPUP" era))
) =>
Arbitrary (UTxOState era)
where
arbitrary = genericArbitraryU
shrink = recursivelyShrink

instance Crypto c => Arbitrary (IncrementalStake c) where
arbitrary = IStake <$> arbitrary <*> arbitrary
shrink = genericShrink

-- The 'genericShrink' function returns first the immediate subterms of a
-- value (in case it is a recursive data-type), and then shrinks the value
-- itself. Since 'UTxOState' is not a recursive data-type, there are no
-- subterms, and we can use `recursivelyShrink` directly. This is particularly
-- important when abstracting away the different fields of the ledger state,
-- since the generic subterms instances will overlap due to GHC not having
-- enough context to infer if 'a' and 'b' are the same types (since in this
-- case this will depend on the definition of 'era').
--
-- > instance OVERLAPPING_ GSubtermsIncl (K1 i a) a where
-- > instance OVERLAPPING_ GSubtermsIncl (K1 i a) b where

instance
( Core.EraTxOut era
, Arbitrary (Core.TxOut era)
, Arbitrary (State (Core.EraRule "PPUP" era))
) =>
Arbitrary (LedgerState era)
where
arbitrary = genericArbitraryU
shrink = genericShrink

instance
( EraTxOut era
, Mock (EraCrypto era)
, Arbitrary (TxOut era)
, Arbitrary (Value era)
, Arbitrary (PParams era)
, Arbitrary (State (EraRule "PPUP" era))
, Arbitrary (StashedAVVMAddresses era)
) =>
Arbitrary (NewEpochState era)
where
arbitrary = genericArbitraryU

instance
( Core.EraTxOut era
, Arbitrary (Core.TxOut era)
, Arbitrary (Core.Value era)
, Arbitrary (Core.PParams era)
, Arbitrary (State (Core.EraRule "PPUP" era))
) =>
Arbitrary (EpochState era)
where
arbitrary =
EpochState
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

instance Crypto c => Arbitrary (LeaderOnlyReward c) where
arbitrary = genericArbitraryU
shrink = genericShrink

instance Crypto c => Arbitrary (RewardUpdate c) where
arbitrary = genericArbitraryU
shrink = genericShrink

instance Crypto c => Arbitrary (STS.OBftSlot c) where
arbitrary = genericArbitraryU
shrink = genericShrink
Expand All @@ -296,7 +201,7 @@ instance Era era => Arbitrary (MultiSig era) where
arbitrary = sizedMultiSig maxMultiSigDepth

instance
(Crypto c, Arbitrary (Core.PParams (ShelleyEra c))) =>
(Crypto c, Arbitrary (PParams (ShelleyEra c))) =>
Arbitrary (ShelleyGenesis c)
where
arbitrary = do
Expand All @@ -322,7 +227,7 @@ instance Crypto c => Arbitrary (ShelleyGenesisStaking c) where

instance
( EraScript era
, Arbitrary (Core.Script era)
, Arbitrary (Script era)
) =>
Arbitrary (ShelleyTxWits era)
where
Expand All @@ -344,8 +249,8 @@ instance Era era => Arbitrary (STS.ShelleyPoolPredFailure era) where

instance
( Era era
, Arbitrary (STS.PredicateFailure (Core.EraRule "POOL" era))
, Arbitrary (STS.PredicateFailure (Core.EraRule "DELEG" era))
, Arbitrary (STS.PredicateFailure (EraRule "POOL" era))
, Arbitrary (STS.PredicateFailure (EraRule "DELEG" era))
) =>
Arbitrary (STS.ShelleyDelplPredFailure era)
where
Expand All @@ -361,7 +266,7 @@ instance

instance
( Era era
, Arbitrary (STS.PredicateFailure (Core.EraRule "DELPL" era))
, Arbitrary (STS.PredicateFailure (EraRule "DELPL" era))
) =>
Arbitrary (STS.ShelleyDelegsPredFailure era)
where
Expand Down Expand Up @@ -429,8 +334,8 @@ genBlock = Block <$> arbitrary <*> (toTxSeq @era <$> arbitrary)
-- This generator uses 'mkBlock' provide more coherent blocks.
genCoherentBlock ::
forall era h.
( Mock (EraCrypto era)
, EraSegWits era
( EraSegWits era
, Mock (EraCrypto era)
, Arbitrary (Tx era)
, h ~ BHeader (EraCrypto era)
) =>
Expand Down Expand Up @@ -477,56 +382,3 @@ instance
where
arbitrary = ApplyTxError <$> arbitrary
shrink (ApplyTxError xs) = [ApplyTxError xs' | xs' <- shrink xs]

instance (Mock c) => Arbitrary (PulsingRewUpdate c) where
arbitrary =
oneof
[ Complete <$> arbitrary
, Pulsing <$> arbitrary <*> arbitrary
]

instance
Crypto c =>
Arbitrary (RewardSnapShot c)
where
arbitrary =
RewardSnapShot
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

instance
Crypto c =>
Arbitrary (PoolRewardInfo c)
where
arbitrary =
PoolRewardInfo
<$> (StakeShare <$> arbitrary)
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

instance
Crypto c =>
Arbitrary (FreeVars c)
where
arbitrary =
FreeVars
<$> arbitrary {- addrsRew -}
<*> arbitrary {- totalStake -}
<*> arbitrary {- pp_mv -}
<*> arbitrary {- poolRewardInfo -}
<*> arbitrary {- delegations -}

instance
Crypto c =>
Arbitrary (Pulser c)
where
arbitrary = RSLP <$> arbitrary <*> arbitrary <*> arbitrary <*> (RewardAns <$> arbitrary <*> arbitrary)

16 changes: 8 additions & 8 deletions libs/cardano-data/cardano-data.cabal
Expand Up @@ -16,19 +16,19 @@ source-repository head
subdir: libs/cardano-data

library
exposed-modules:
Data.CanonicalMaps
Data.Pulse
Data.MapExtras
Data.UMap
Data.ListMap
Data.Universe

hs-source-dirs: src
default-language: Haskell2010
ghc-options:
-Wall -Wcompat -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wredundant-constraints -Wunused-packages

exposed-modules:
Data.CanonicalMaps,
Data.Pulse,
Data.MapExtras,
Data.UMap,
Data.ListMap,
Data.Universe

build-depends:
base >=4.14 && <4.17,
Expand Down

0 comments on commit 0252512

Please sign in to comment.