From 3ab8034cc196892e117972544c831f620a252877 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Wed, 4 Sep 2024 17:52:30 +0200 Subject: [PATCH] Use newtype derived Arbitrary where possible --- hydra-tx/src/Hydra/Tx/Party.hs | 4 +--- hydra-tx/src/Hydra/Tx/Snapshot.hs | 10 ++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/hydra-tx/src/Hydra/Tx/Party.hs b/hydra-tx/src/Hydra/Tx/Party.hs index cc55b7f1b68..6884832d1e1 100644 --- a/hydra-tx/src/Hydra/Tx/Party.hs +++ b/hydra-tx/src/Hydra/Tx/Party.hs @@ -24,6 +24,7 @@ import Hydra.Tx.Crypto (AsType (AsHydraKey), HydraKey) newtype Party = Party {vkey :: VerificationKey HydraKey} deriving stock (Eq, Show, Generic) deriving anyclass (ToJSON, FromJSON) + deriving newtype (Arbitrary) instance ToJSONKey Party where toJSONKey = toJSONKeyText (serialiseToRawBytesHexText . vkey) @@ -43,9 +44,6 @@ instance Ord Party where Party{vkey = a} <= Party{vkey = b} = verificationKeyHash a <= verificationKeyHash b -instance Arbitrary Party where - arbitrary = Party <$> arbitrary - instance FromCBOR Party where fromCBOR = Party <$> fromCBOR diff --git a/hydra-tx/src/Hydra/Tx/Snapshot.hs b/hydra-tx/src/Hydra/Tx/Snapshot.hs index 0335d92b6ee..30af5757954 100644 --- a/hydra-tx/src/Hydra/Tx/Snapshot.hs +++ b/hydra-tx/src/Hydra/Tx/Snapshot.hs @@ -23,29 +23,23 @@ import Test.QuickCheck.Instances.Natural () newtype SnapshotNumber = UnsafeSnapshotNumber Natural deriving stock (Eq, Ord, Generic) - deriving newtype (Show, ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral) + deriving newtype (Show, ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral, Arbitrary) -- NOTE: On-chain scripts ensure snapshot number does not become negative. fromChainSnapshotNumber :: Onchain.SnapshotNumber -> SnapshotNumber fromChainSnapshotNumber = UnsafeSnapshotNumber . fromMaybe 0 . integerToNatural -instance Arbitrary SnapshotNumber where - arbitrary = UnsafeSnapshotNumber <$> arbitrary - newtype SnapshotVersion = UnsafeSnapshotVersion Natural deriving stock (Eq, Ord, Generic) - deriving newtype (Show, ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral) + deriving newtype (Show, ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral, Arbitrary) -- NOTE: On-chain scripts ensure snapshot version does not become negative. fromChainSnapshotVersion :: Onchain.SnapshotVersion -> SnapshotVersion fromChainSnapshotVersion = UnsafeSnapshotVersion . fromMaybe 0 . integerToNatural -instance Arbitrary SnapshotVersion where - arbitrary = UnsafeSnapshotVersion <$> arbitrary - -- * Snapshot data Snapshot tx = Snapshot