diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index 1d567e4abe5..e32ae4d3e2e 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -71,7 +71,6 @@ library Hydra.Cardano.Api.UTxO Hydra.Cardano.Api.ValidityInterval Hydra.Cardano.Api.Value - Hydra.Cardano.Api.VerificationKey Hydra.Cardano.Api.Witness -- NOTE: We only use an upper bound on cardano-api and have the other @@ -79,7 +78,6 @@ library build-depends: , aeson >=2 , base >=4.16 - , base16-bytestring , bytestring , cardano-api ^>=10.1 , cardano-binary @@ -97,5 +95,4 @@ library , lens , plutus-ledger-api , QuickCheck - , serialise , text >=2 diff --git a/hydra-cardano-api/src/Cardano/Api/UTxO.hs b/hydra-cardano-api/src/Cardano/Api/UTxO.hs index 08cc50d10f2..67a585a09fd 100644 --- a/hydra-cardano-api/src/Cardano/Api/UTxO.hs +++ b/hydra-cardano-api/src/Cardano/Api/UTxO.hs @@ -43,9 +43,6 @@ newtype UTxO' out = UTxO , FromJSON ) -instance Traversable UTxO' where - traverse fn (UTxO m) = UTxO <$> traverse fn m - -- | Create a 'UTxO' from a list of 'TxIn' and 'out' pairs. fromPairs :: [(TxIn, out)] -> UTxO' out fromPairs = UTxO . Map.fromList diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api.hs b/hydra-cardano-api/src/Hydra/Cardano/Api.hs index f2f3d32e8de..0fa56d4d624 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api.hs @@ -148,7 +148,6 @@ import Hydra.Cardano.Api.TxOutValue as Extras import Hydra.Cardano.Api.UTxO as Extras import Hydra.Cardano.Api.ValidityInterval as Extras import Hydra.Cardano.Api.Value as Extras -import Hydra.Cardano.Api.VerificationKey () import Hydra.Cardano.Api.Witness as Extras import Cardano.Api qualified diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs index d5313ddddb0..63308db7ccf 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs @@ -17,16 +17,6 @@ fromPlutusScript = -- * Orphans -instance IsPlutusScriptLanguage lang => ToJSON (PlutusScript lang) where - toJSON = toJSON . serialiseToTextEnvelope Nothing - -instance IsPlutusScriptLanguage lang => FromJSON (PlutusScript lang) where - parseJSON v = do - env <- parseJSON v - case deserialiseFromTextEnvelope (proxyToAsType Proxy) env of - Left e -> fail $ show e - Right a -> pure a - instance Arbitrary (PlutusScript lang) where arbitrary = PlutusScriptSerialised . SBS.pack <$> listOf arbitrary diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs index 50478c263a2..5d4406e732d 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs @@ -6,11 +6,7 @@ import Hydra.Cardano.Api.Prelude hiding (left) import Cardano.Ledger.Era qualified as Ledger import Cardano.Ledger.Plutus.Data qualified as Ledger -import Codec.Serialise (deserialiseOrFail, serialise) -import Control.Arrow (left) -import Data.Aeson (Value (String), withText) import Data.ByteString qualified as BS -import Data.ByteString.Base16 qualified as Base16 import PlutusLedgerApi.V3 qualified as Plutus import Test.QuickCheck (arbitrarySizedNatural, choose, oneof, scale, sized, vector) @@ -58,22 +54,6 @@ toLedgerData = -- * Orphans -instance ToJSON ScriptData where - toJSON = - String - . decodeUtf8 - . Base16.encode - . toStrict - . serialise - . toPlutusData - -instance FromJSON ScriptData where - parseJSON v = do - text :: Text <- parseJSON v - either fail (pure . fromPlutusData) $ do - bytes <- Base16.decode (encodeUtf8 text) - left show $ deserialiseOrFail $ fromStrict bytes - instance Arbitrary ScriptData where arbitrary = scale (`div` 2) $ @@ -88,15 +68,6 @@ instance Arbitrary ScriptData where arbitraryBS = sized $ \n -> BS.pack <$> (choose (0, min n 64) >>= vector) -instance ToJSON HashableScriptData where - toJSON = String . decodeUtf8 . Base16.encode . serialiseToCBOR - -instance FromJSON HashableScriptData where - parseJSON = - withText "HashableScriptData" $ \text -> do - bytes <- either (fail . show) pure $ Base16.decode $ encodeUtf8 text - either (fail . show) pure $ deserialiseFromCBOR (proxyToAsType Proxy) bytes - instance Arbitrary HashableScriptData where arbitrary = -- NOTE: Safe to use here as the data was not available in serialized form. diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/VerificationKey.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/VerificationKey.hs deleted file mode 100644 index 1e6b7493d89..00000000000 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/VerificationKey.hs +++ /dev/null @@ -1,19 +0,0 @@ -{-# OPTIONS_GHC -Wno-orphans #-} - -module Hydra.Cardano.Api.VerificationKey where - -import Hydra.Cardano.Api.Prelude - --- * Orphans - --- XXX: This is quite specific to payment keys - -instance ToJSON (VerificationKey PaymentKey) where - toJSON = toJSON . serialiseToTextEnvelope Nothing - -instance FromJSON (VerificationKey PaymentKey) where - parseJSON v = do - env <- parseJSON v - case deserialiseFromTextEnvelope (AsVerificationKey AsPaymentKey) env of - Left e -> fail $ show e - Right a -> pure a diff --git a/hydra-chain-observer/src/Hydra/ChainObserver/NodeClient.hs b/hydra-chain-observer/src/Hydra/ChainObserver/NodeClient.hs index ecf87a10391..4d034a70122 100644 --- a/hydra-chain-observer/src/Hydra/ChainObserver/NodeClient.hs +++ b/hydra-chain-observer/src/Hydra/ChainObserver/NodeClient.hs @@ -36,9 +36,6 @@ data ChainObservation } deriving stock (Eq, Show, Generic) -instance Arbitrary ChainObservation where - arbitrary = genericArbitrary - defaultObserverHandler :: Applicative m => ObserverHandler m defaultObserverHandler = const $ pure () diff --git a/hydra-cluster/bench/Bench/EndToEnd.hs b/hydra-cluster/bench/Bench/EndToEnd.hs index a4e3318d997..d0b03de04ee 100644 --- a/hydra-cluster/bench/Bench/EndToEnd.hs +++ b/hydra-cluster/bench/Bench/EndToEnd.hs @@ -333,7 +333,6 @@ data Event = Event , confirmedAt :: Maybe UTCTime } deriving stock (Generic, Eq, Show) - deriving anyclass (ToJSON) processTransactions :: [HydraClient] -> [ClientDataset] -> IO (Map.Map TxId Event) processTransactions clients clientDatasets = do diff --git a/hydra-cluster/bench/Bench/Summary.hs b/hydra-cluster/bench/Bench/Summary.hs index 8ee2ff8af2d..cc980c4f59a 100644 --- a/hydra-cluster/bench/Bench/Summary.hs +++ b/hydra-cluster/bench/Bench/Summary.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DuplicateRecordFields #-} module Bench.Summary where @@ -29,7 +28,6 @@ data Summary = Summary , quantiles :: Vector Double } deriving stock (Generic, Eq, Show) - deriving anyclass (ToJSON) errorSummary :: Dataset -> HUnitFailure -> Summary errorSummary Dataset{title, clientDatasets} (HUnitFailure sourceLocation reason) = diff --git a/hydra-cluster/hydra-cluster.cabal b/hydra-cluster/hydra-cluster.cabal index 66d6c9c4f18..06d1ec3d491 100644 --- a/hydra-cluster/hydra-cluster.cabal +++ b/hydra-cluster/hydra-cluster.cabal @@ -101,7 +101,6 @@ library , hydra-tx , hydra-tx:testlib , io-classes - , iohk-monitoring , lens , lens-aeson , optparse-applicative diff --git a/hydra-cluster/src/CardanoNode.hs b/hydra-cluster/src/CardanoNode.hs index b975d63378a..8ff976d7b2d 100644 --- a/hydra-cluster/src/CardanoNode.hs +++ b/hydra-cluster/src/CardanoNode.hs @@ -50,12 +50,12 @@ data NodeLog | MsgSynchronizing {percentDone :: Centi} | MsgQueryGenesisParametersFailed {err :: Text} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) type Port = Int newtype NodeId = NodeId Int - deriving newtype (Eq, Show, Num, ToJSON, FromJSON) + deriving newtype (Eq, Show, Num) -- | Configuration parameters for a single node devnet data DevnetConfig = DevnetConfig @@ -67,7 +67,6 @@ data DevnetConfig = DevnetConfig -- ^ A list of port } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) -- | Arguments given to the 'cardano-node' command-line to run a node. data CardanoNodeArgs = CardanoNodeArgs @@ -115,7 +114,6 @@ data PortsConfig = PortsConfig -- ^ Other peers TCP ports. } deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) getCardanoNodeVersion :: IO String getCardanoNodeVersion = @@ -461,8 +459,6 @@ mkTopology peers = data ProcessHasExited = ProcessHasExited Text ExitCode deriving stock (Show) -instance Exception ProcessHasExited - -- | Cardano-cli wrapper to query protocol parameters. While we have also client -- functions in Hydra.Chain.CardanoClient and Hydra.Cluster.CardanoClient, -- sometimes we deliberately want to use the cardano-cli to ensure diff --git a/hydra-cluster/src/Hydra/Cluster/Faucet.hs b/hydra-cluster/src/Hydra/Cluster/Faucet.hs index 07f5676a545..6ddb3ff56a2 100644 --- a/hydra-cluster/src/Hydra/Cluster/Faucet.hs +++ b/hydra-cluster/src/Hydra/Cluster/Faucet.hs @@ -40,7 +40,7 @@ data FaucetLog = TraceResourceExhaustedHandled Text | ReturnedFunds {returnAmount :: Coin} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) -- | Create a specially marked "seed" UTXO containing requested 'Lovelace' by -- redeeming funds available to the well-known faucet. diff --git a/hydra-cluster/src/Hydra/Cluster/Fixture.hs b/hydra-cluster/src/Hydra/Cluster/Fixture.hs index c8763cd715a..38bd6665a4c 100644 --- a/hydra-cluster/src/Hydra/Cluster/Fixture.hs +++ b/hydra-cluster/src/Hydra/Cluster/Fixture.hs @@ -73,7 +73,7 @@ data KnownNetwork | Mainnet | Sanchonet deriving stock (Generic, Show, Eq, Enum, Bounded) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) toNetworkId :: KnownNetwork -> NetworkId toNetworkId = \case diff --git a/hydra-cluster/src/Hydra/Cluster/Mithril.hs b/hydra-cluster/src/Hydra/Cluster/Mithril.hs index 886fffc4495..b0340ba7d2d 100644 --- a/hydra-cluster/src/Hydra/Cluster/Mithril.hs +++ b/hydra-cluster/src/Hydra/Cluster/Mithril.hs @@ -17,7 +17,7 @@ data MithrilLog | -- | Output captured directly from mithril-client stderr. StdErr {output :: Value} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) -- | Downloads and unpacks latest snapshot for given network in db/ of given -- directory. diff --git a/hydra-cluster/src/Hydra/Cluster/Options.hs b/hydra-cluster/src/Hydra/Cluster/Options.hs index 0c907392019..5e2763f9c6d 100644 --- a/hydra-cluster/src/Hydra/Cluster/Options.hs +++ b/hydra-cluster/src/Hydra/Cluster/Options.hs @@ -18,19 +18,19 @@ data Options = Options , scenario :: Scenario } deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) data PublishOrReuse = Publish | Reuse [TxId] deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) data UseMithril = NotUseMithril | UseMithril deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) data Scenario = Idle | RespendUTxO deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) parseOptions :: Parser Options parseOptions = diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index 210d5d6c238..583e2c588e9 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -129,7 +129,7 @@ data EndToEndLog | UsingHydraScriptsAt {hydraScriptsTxId :: [TxId]} | CreatedKey {keyPath :: FilePath} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) restartedNodeCanObserveCommitTx :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO () restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do diff --git a/hydra-cluster/src/HydraNode.hs b/hydra-cluster/src/HydraNode.hs index c5bd60b1375..c3d8537b698 100644 --- a/hydra-cluster/src/HydraNode.hs +++ b/hydra-cluster/src/HydraNode.hs @@ -5,7 +5,6 @@ module HydraNode where import Hydra.Cardano.Api import Hydra.Prelude hiding (delete) -import Cardano.BM.Tracing (ToObject) import CardanoNode (cliQueryProtocolParameters) import Control.Concurrent.Async (forConcurrently_) import Control.Concurrent.Class.MonadSTM (modifyTVar', newTVarIO, readTVarIO) @@ -470,4 +469,4 @@ data HydraNodeLog | ReceivedMessage {nodeId :: Int, message :: Aeson.Value} | EndWaiting {nodeId :: Int} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON, ToObject) + deriving anyclass (ToJSON) diff --git a/hydra-node/hydra-node.cabal b/hydra-node/hydra-node.cabal index 8baf427fdff..64c785888aa 100644 --- a/hydra-node/hydra-node.cabal +++ b/hydra-node/hydra-node.cabal @@ -101,7 +101,6 @@ library build-depends: , aeson , base - , base16-bytestring , bytestring , cardano-api:internal , cardano-binary diff --git a/hydra-node/src/Hydra/API/APIServerLog.hs b/hydra-node/src/Hydra/API/APIServerLog.hs index 0d966cac774..be60d689b67 100644 --- a/hydra-node/src/Hydra/API/APIServerLog.hs +++ b/hydra-node/src/Hydra/API/APIServerLog.hs @@ -20,7 +20,7 @@ data APIServerLog , path :: PathInfo } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary APIServerLog where arbitrary = @@ -50,10 +50,6 @@ instance ToJSON PathInfo where toJSON (PathInfo bytes) = Aeson.String $ decodeUtf8 bytes -instance FromJSON PathInfo where - parseJSON = Aeson.withText "PathInfo" $ \t -> - pure . PathInfo $ encodeUtf8 t - -- | New type wrapper to define JSON instances. -- -- NOTE: We are not using http-types 'StdMethod' as we do not want to be @@ -67,7 +63,3 @@ instance Arbitrary Method where instance ToJSON Method where toJSON (Method bytes) = Aeson.String $ decodeUtf8 bytes - -instance FromJSON Method where - parseJSON = Aeson.withText "Method" $ \t -> - pure . Method $ encodeUtf8 t diff --git a/hydra-node/src/Hydra/Chain.hs b/hydra-node/src/Hydra/Chain.hs index df19aaa9022..3d660de55d3 100644 --- a/hydra-node/src/Hydra/Chain.hs +++ b/hydra-node/src/Hydra/Chain.hs @@ -158,7 +158,6 @@ data OnChainTx tx deriving stock instance IsTx tx => Eq (OnChainTx tx) deriving stock instance IsTx tx => Show (OnChainTx tx) deriving anyclass instance IsTx tx => ToJSON (OnChainTx tx) -deriving anyclass instance IsTx tx => FromJSON (OnChainTx tx) instance ArbitraryIsTx tx => Arbitrary (OnChainTx tx) where arbitrary = genericArbitrary @@ -243,8 +242,6 @@ rollbackHistory rollbackChainSlot h@UnsafeChainStateHistory{history, defaultChai deriving stock instance Eq (ChainStateType tx) => Eq (ChainStateHistory tx) deriving stock instance Show (ChainStateType tx) => Show (ChainStateHistory tx) -deriving anyclass instance ToJSON (ChainStateType tx) => ToJSON (ChainStateHistory tx) -deriving anyclass instance FromJSON (ChainStateType tx) => FromJSON (ChainStateHistory tx) instance Arbitrary (ChainStateType tx) => Arbitrary (ChainStateHistory tx) where arbitrary = genericArbitrary @@ -312,7 +309,6 @@ data ChainEvent tx deriving stock instance (IsTx tx, IsChainState tx) => Eq (ChainEvent tx) deriving stock instance (IsTx tx, IsChainState tx) => Show (ChainEvent tx) deriving anyclass instance (IsTx tx, IsChainState tx) => ToJSON (ChainEvent tx) -deriving anyclass instance (IsTx tx, IsChainState tx) => FromJSON (ChainEvent tx) instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (ChainEvent tx) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Chain/CardanoClient.hs b/hydra-node/src/Hydra/Chain/CardanoClient.hs index b3af797f409..28a638f0b96 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -13,7 +13,6 @@ import Data.Aeson (eitherDecode', encode) import Data.Set qualified as Set import Data.Text qualified as Text import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) -import Test.QuickCheck (oneof) import Text.Printf (printf) -- XXX: This should be re-exported by cardano-api @@ -198,17 +197,6 @@ awaitTransaction networkId socket tx = data QueryPoint = QueryTip | QueryAt ChainPoint deriving stock (Eq, Show, Generic) -deriving anyclass instance ToJSON QueryPoint - -instance Arbitrary QueryPoint where - -- XXX: This is not complete as we lack an 'Arbitrary ChainPoint' and we have - -- not bothered about it yet. - arbitrary = - oneof - [ pure QueryTip - , pure $ QueryAt ChainPointAtGenesis - ] - -- | Query the latest chain point aka "the tip". queryTip :: NetworkId -> SocketPath -> IO ChainPoint queryTip networkId socket = diff --git a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs index 338f3e6118b..ac65fd07512 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs @@ -460,7 +460,7 @@ data DirectChainLog | RolledBackward {point :: ChainPoint} | Wallet TinyWalletLog deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary DirectChainLog where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index 287a1b78e63..302de9f1195 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -190,11 +190,6 @@ data ChainState | Open OpenState | Closed ClosedState deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary ChainState where - arbitrary = genChainState - shrink = genericShrink instance HasKnownUTxO ChainState where getKnownUTxO :: ChainState -> UTxO @@ -221,7 +216,6 @@ data ChainContext = ChainContext , scriptRegistry :: ScriptRegistry } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) instance HasKnownUTxO ChainContext where getKnownUTxO ChainContext{scriptRegistry} = registryUTxO scriptRegistry @@ -249,14 +243,6 @@ data InitialState = InitialState , seedTxIn :: TxIn } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary InitialState where - arbitrary = do - ctx <- genHydraContext maxGenParties - snd <$> genStInitial ctx - - shrink = genericShrink instance HasKnownUTxO InitialState where getKnownUTxO st = @@ -277,7 +263,6 @@ data OpenState = OpenState , openUtxoHash :: UTxOHash } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) instance Arbitrary OpenState where arbitrary = do @@ -300,15 +285,6 @@ data ClosedState = ClosedState , seedTxIn :: TxIn } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary ClosedState where - arbitrary = do - -- XXX: Untangle the whole generator mess here - (_, st, _, _) <- genFanoutTx maxGenParties - pure st - - shrink = genericShrink instance HasKnownUTxO ClosedState where getKnownUTxO st = @@ -927,16 +903,6 @@ observeClose st tx = do maxGenParties :: Int maxGenParties = 3 --- | Generate a 'ChainState' within known limits above. -genChainState :: Gen ChainState -genChainState = - oneof - [ pure Idle - , Initial <$> arbitrary - , Open <$> arbitrary - , Closed <$> arbitrary - ] - -- | Generate a 'ChainContext' and 'ChainState' within the known limits above, along with a -- transaction that results in a transition away from it. genChainStateWithTx :: Gen (ChainContext, ChainState, UTxO, Tx, ChainTransition) diff --git a/hydra-node/src/Hydra/Chain/Direct/Tx.hs b/hydra-node/src/Hydra/Chain/Direct/Tx.hs index bcfe8f765fb..e7692028a8d 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -17,7 +17,6 @@ import Hydra.Prelude hiding (toList) import Cardano.Api.UTxO qualified as UTxO import Data.Aeson qualified as Aeson import Data.ByteString qualified as BS -import Data.ByteString.Base16 qualified as Base16 import GHC.IsList (IsList (..)) import Hydra.Contract.Commit qualified as Commit import Hydra.Contract.Deposit qualified as Deposit @@ -59,16 +58,6 @@ type UTxOWithScript = (TxIn, TxOut CtxUTxO, HashableScriptData) newtype UTxOHash = UTxOHash ByteString deriving stock (Eq, Show, Generic) -instance ToJSON UTxOHash where - toJSON (UTxOHash bytes) = - Aeson.String . decodeUtf8 $ Base16.encode bytes - -instance FromJSON UTxOHash where - parseJSON = Aeson.withText "UTxOHash" $ \cborText -> - case Base16.decode $ encodeUtf8 cborText of - Left e -> fail e - Right bs -> pure $ UTxOHash bs - instance Arbitrary UTxOHash where arbitrary = UTxOHash . BS.pack <$> vectorOf 32 arbitrary @@ -79,11 +68,6 @@ data InitialThreadOutput = InitialThreadOutput , initialParties :: [OnChain.Party] } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary InitialThreadOutput where - arbitrary = genericArbitrary - shrink = genericShrink -- * Observe Hydra Head transactions @@ -103,9 +87,6 @@ data HeadObservation | Fanout FanoutObservation deriving stock (Eq, Show, Generic) -instance Arbitrary HeadObservation where - arbitrary = genericArbitrary - -- | Observe any Hydra head transaction. observeHeadTx :: NetworkId -> UTxO -> Tx -> HeadObservation observeHeadTx networkId utxo tx = @@ -138,19 +119,12 @@ data InitObservation = InitObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary InitObservation where - arbitrary = genericArbitrary - data NotAnInitReason = NoHeadOutput | NotAHeadDatum | NoSTFound | NotAHeadPolicy deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary NotAnInitReason where - arbitrary = genericArbitrary -- | Identify a init tx by checking the output value for holding tokens that are -- valid head tokens (checked by seed + policy). @@ -230,9 +204,6 @@ data CommitObservation = CommitObservation } deriving stock (Eq, Show, Generic) -instance Arbitrary CommitObservation where - arbitrary = genericArbitrary - -- | Identify a commit tx by: -- -- - Check that its spending from the init validator, @@ -304,9 +275,6 @@ data CollectComObservation = CollectComObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary CollectComObservation where - arbitrary = genericArbitrary - -- | Identify a collectCom tx by lookup up the input spending the Head output -- and decoding its redeemer. observeCollectComTx :: @@ -352,9 +320,6 @@ data IncrementObservation = IncrementObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary IncrementObservation where - arbitrary = genericArbitrary - observeIncrementTx :: UTxO -> Tx -> @@ -395,9 +360,6 @@ data DecrementObservation = DecrementObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary DecrementObservation where - arbitrary = genericArbitrary - observeDecrementTx :: UTxO -> Tx -> @@ -436,9 +398,6 @@ data CloseObservation = CloseObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary CloseObservation where - arbitrary = genericArbitrary - -- | Identify a close tx by lookup up the input spending the Head output and -- decoding its redeemer. observeCloseTx :: @@ -486,9 +445,6 @@ data ContestObservation = ContestObservation } deriving stock (Show, Eq, Generic) -instance Arbitrary ContestObservation where - arbitrary = genericArbitrary - -- | Identify a close tx by lookup up the input spending the Head output and -- decoding its redeemer. observeContestTx :: @@ -528,9 +484,6 @@ observeContestTx utxo tx = do newtype FanoutObservation = FanoutObservation {headId :: HeadId} deriving stock (Eq, Show, Generic) -instance Arbitrary FanoutObservation where - arbitrary = genericArbitrary - -- | Identify a fanout tx by lookup up the input spending the Head output and -- decoding its redeemer. observeFanoutTx :: @@ -551,9 +504,6 @@ observeFanoutTx utxo tx = do newtype AbortObservation = AbortObservation {headId :: HeadId} deriving stock (Eq, Show, Generic) -instance Arbitrary AbortObservation where - arbitrary = genericArbitrary - -- | Identify an abort tx by looking up the input spending the Head output and -- decoding its redeemer. observeAbortTx :: diff --git a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs index 541e94f7bca..83319786608 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs @@ -456,7 +456,6 @@ data TinyWalletLog deriving stock (Eq, Generic, Show) deriving anyclass instance ToJSON TinyWalletLog -deriving anyclass instance FromJSON TinyWalletLog instance Arbitrary TinyWalletLog where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Events.hs b/hydra-node/src/Hydra/Events.hs index 9276a9ccac6..cb14bf52e26 100644 --- a/hydra-node/src/Hydra/Events.hs +++ b/hydra-node/src/Hydra/Events.hs @@ -18,16 +18,12 @@ import Hydra.Prelude import Hydra.Chain.ChainState (IsChainState) import Hydra.HeadLogic.Outcome (StateChanged) import Hydra.Tx.IsTx (ArbitraryIsTx) -import Test.QuickCheck.Arbitrary.ADT (ToADTArbitrary) type EventId = Word64 class HasEventId a where getEventId :: a -> EventId -instance HasEventId (EventId, a) where - getEventId = fst - newtype EventSource e m = EventSource { getEvents :: HasEventId e => m [e] -- ^ Retrieve all events from the event source. @@ -67,7 +63,5 @@ instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (StateEvent tx) where arbitrary = arbitrary >>= genStateEvent shrink = genericShrink -instance (ArbitraryIsTx tx, IsChainState tx) => ToADTArbitrary (StateEvent tx) - genStateEvent :: StateChanged tx -> Gen (StateEvent tx) genStateEvent sc = StateEvent <$> arbitrary <*> pure sc diff --git a/hydra-node/src/Hydra/HeadLogic/Error.hs b/hydra-node/src/Hydra/HeadLogic/Error.hs index 07d4096362d..bbd5f0d025f 100644 --- a/hydra-node/src/Hydra/HeadLogic/Error.hs +++ b/hydra-node/src/Hydra/HeadLogic/Error.hs @@ -24,8 +24,6 @@ data LogicError tx | NotOurHead {ourHeadId :: HeadId, otherHeadId :: HeadId} deriving stock (Generic) -instance (Typeable tx, Show (Input tx), Show (HeadState tx), Show (RequirementFailure tx)) => Exception (LogicError tx) - instance (Arbitrary (Input tx), Arbitrary (HeadState tx), Arbitrary (RequirementFailure tx)) => Arbitrary (LogicError tx) where arbitrary = genericArbitrary shrink = genericShrink @@ -33,7 +31,6 @@ instance (Arbitrary (Input tx), Arbitrary (HeadState tx), Arbitrary (Requirement deriving stock instance (Eq (HeadState tx), Eq (Input tx), Eq (RequirementFailure tx)) => Eq (LogicError tx) deriving stock instance (Show (HeadState tx), Show (Input tx), Show (RequirementFailure tx)) => Show (LogicError tx) deriving anyclass instance (ToJSON (HeadState tx), ToJSON (Input tx), ToJSON (RequirementFailure tx)) => ToJSON (LogicError tx) -deriving anyclass instance (FromJSON (HeadState tx), FromJSON (Input tx), FromJSON (RequirementFailure tx)) => FromJSON (LogicError tx) data RequirementFailure tx = ReqSnNumberInvalid {requestedSn :: SnapshotNumber, lastSeenSn :: SnapshotNumber} @@ -51,7 +48,6 @@ data RequirementFailure tx deriving stock instance Eq (TxIdType tx) => Eq (RequirementFailure tx) deriving stock instance Show (TxIdType tx) => Show (RequirementFailure tx) deriving anyclass instance ToJSON (TxIdType tx) => ToJSON (RequirementFailure tx) -deriving anyclass instance FromJSON (TxIdType tx) => FromJSON (RequirementFailure tx) instance Arbitrary (TxIdType tx) => Arbitrary (RequirementFailure tx) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/HeadLogic/Input.hs b/hydra-node/src/Hydra/HeadLogic/Input.hs index 14291998e57..157283ca52e 100644 --- a/hydra-node/src/Hydra/HeadLogic/Input.hs +++ b/hydra-node/src/Hydra/HeadLogic/Input.hs @@ -30,7 +30,6 @@ data Input tx deriving stock instance IsChainState tx => Eq (Input tx) deriving stock instance IsChainState tx => Show (Input tx) deriving anyclass instance IsChainState tx => ToJSON (Input tx) -deriving anyclass instance IsChainState tx => FromJSON (Input tx) instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (Input tx) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/HeadLogic/Outcome.hs b/hydra-node/src/Hydra/HeadLogic/Outcome.hs index f4cd89bfce4..3fa5b577b4c 100644 --- a/hydra-node/src/Hydra/HeadLogic/Outcome.hs +++ b/hydra-node/src/Hydra/HeadLogic/Outcome.hs @@ -46,7 +46,6 @@ data Effect tx deriving stock instance IsChainState tx => Eq (Effect tx) deriving stock instance IsChainState tx => Show (Effect tx) deriving anyclass instance IsChainState tx => ToJSON (Effect tx) -deriving anyclass instance IsChainState tx => FromJSON (Effect tx) instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (Effect tx) where arbitrary = genericArbitrary @@ -151,7 +150,6 @@ instance Semigroup (Outcome tx) where deriving stock instance IsChainState tx => Eq (Outcome tx) deriving stock instance IsChainState tx => Show (Outcome tx) deriving anyclass instance IsChainState tx => ToJSON (Outcome tx) -deriving anyclass instance IsChainState tx => FromJSON (Outcome tx) instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (Outcome tx) where arbitrary = genericArbitrary @@ -187,7 +185,6 @@ data WaitReason tx deriving stock instance IsTx tx => Eq (WaitReason tx) deriving stock instance IsTx tx => Show (WaitReason tx) deriving anyclass instance IsTx tx => ToJSON (WaitReason tx) -deriving anyclass instance IsTx tx => FromJSON (WaitReason tx) instance ArbitraryIsTx tx => Arbitrary (WaitReason tx) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Ledger.hs b/hydra-node/src/Hydra/Ledger.hs index 5461732af28..da32735ea1b 100644 --- a/hydra-node/src/Hydra/Ledger.hs +++ b/hydra-node/src/Hydra/Ledger.hs @@ -50,7 +50,6 @@ data ValidationResult = Valid | Invalid ValidationError deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) newtype ValidationError = ValidationError {reason :: Text} deriving stock (Eq, Show, Generic) diff --git a/hydra-node/src/Hydra/Logging.hs b/hydra-node/src/Hydra/Logging.hs index 987d94b3f6b..cc011dbfad5 100644 --- a/hydra-node/src/Hydra/Logging.hs +++ b/hydra-node/src/Hydra/Logging.hs @@ -66,7 +66,6 @@ data Envelope a = Envelope , message :: a } deriving stock (Eq, Show, Generic) - deriving anyclass (FromJSON) instance ToJSON a => ToJSON (Envelope a) where toEncoding Envelope{timestamp, threadId, namespace, message} = diff --git a/hydra-node/src/Hydra/Logging/Messages.hs b/hydra-node/src/Hydra/Logging/Messages.hs index 47cf23a0215..b0465e57bcd 100644 --- a/hydra-node/src/Hydra/Logging/Messages.hs +++ b/hydra-node/src/Hydra/Logging/Messages.hs @@ -30,7 +30,6 @@ data HydraLog tx net deriving stock instance (Eq net, Eq (HydraNodeLog tx)) => Eq (HydraLog tx net) deriving stock instance (Show net, Show (HydraNodeLog tx)) => Show (HydraLog tx net) deriving anyclass instance (ToJSON net, ToJSON (HydraNodeLog tx)) => ToJSON (HydraLog tx net) -deriving anyclass instance (FromJSON net, FromJSON (HydraNodeLog tx)) => FromJSON (HydraLog tx net) instance (Arbitrary net, Arbitrary (HydraNodeLog tx)) => Arbitrary (HydraLog tx net) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Network.hs b/hydra-node/src/Hydra/Network.hs index 66240440999..a1edb7f49aa 100644 --- a/hydra-node/src/Hydra/Network.hs +++ b/hydra-node/src/Hydra/Network.hs @@ -47,9 +47,6 @@ newtype Network m msg = Network -- ^ Send a `msg` to the whole configured hydra network including ourselves. } -instance Contravariant (Network m) where - contramap f (Network bcast) = Network $ \msg -> bcast (f msg) - -- | Interface from network layer to the application. -- XXX: Reliably delivering a message in the crash-recovery fault model is -- tricky. According to "Introduction to Reliable and Secure Distributed @@ -78,12 +75,6 @@ instance FromJSON PortNumber where instance Arbitrary PortNumber where arbitrary = fromIntegral @Word16 <$> arbitrary -instance ToCBOR PortNumber where - toCBOR = toCBOR . toInteger - -instance FromCBOR PortNumber where - fromCBOR = fmap fromInteger fromCBOR - newtype NodeId = NodeId {nodeId :: Text} deriving newtype (Eq, Show, IsString, Read, Ord, ToJSON, FromJSON) @@ -122,19 +113,6 @@ instance Arbitrary Host where ip <- toIPv4w <$> arbitrary Host (toText $ show ip) <$> arbitrary -instance ToCBOR Host where - toCBOR Host{hostname, port} = - mconcat - [ toCBOR hostname - , toCBOR port - ] - -instance FromCBOR Host where - fromCBOR = - Host - <$> fromCBOR - <*> (fromInteger <$> fromCBOR) - showHost :: Host -> String showHost Host{hostname, port} = unpack hostname <> ":" <> show port diff --git a/hydra-node/src/Hydra/Network/Authenticate.hs b/hydra-node/src/Hydra/Network/Authenticate.hs index f65c84fbfe9..5839407525a 100644 --- a/hydra-node/src/Hydra/Network/Authenticate.hs +++ b/hydra-node/src/Hydra/Network/Authenticate.hs @@ -27,14 +27,13 @@ data Signed msg = Signed , party :: Party } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) data Authenticated msg = Authenticated { payload :: msg , party :: Party } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) instance (Arbitrary msg, SignableRepresentation msg) => Arbitrary (Signed msg) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Network/Message.hs b/hydra-node/src/Hydra/Network/Message.hs index 6e7e26628ac..dfcfa3aacc7 100644 --- a/hydra-node/src/Hydra/Network/Message.hs +++ b/hydra-node/src/Hydra/Network/Message.hs @@ -22,7 +22,7 @@ data NetworkEvent msg = ConnectivityEvent Connectivity | ReceivedMessage {sender :: Party, msg :: msg} deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary msg => Arbitrary (NetworkEvent msg) where arbitrary = genericArbitrary @@ -30,7 +30,7 @@ instance Arbitrary msg => Arbitrary (NetworkEvent msg) where type HydraVersionedProtocolNumber :: Type newtype HydraVersionedProtocolNumber = MkHydraVersionedProtocolNumber {hydraVersionedProtocolNumber :: Natural} deriving stock (Eq, Show, Generic, Ord) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary HydraVersionedProtocolNumber where arbitrary = genericArbitrary @@ -40,7 +40,7 @@ data KnownHydraVersions = KnownHydraVersions {fromKnownHydraVersions :: [HydraVersionedProtocolNumber]} | NoKnownHydraVersions deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary KnownHydraVersions where arbitrary = genericArbitrary @@ -52,10 +52,6 @@ data HydraHandshakeRefused = HydraHandshakeRefused , theirVersions :: KnownHydraVersions } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) - -instance Arbitrary HydraHandshakeRefused where - arbitrary = genericArbitrary data Connectivity = Connected {nodeId :: NodeId} @@ -66,7 +62,7 @@ data Connectivity , theirVersions :: KnownHydraVersions } deriving stock (Generic, Eq, Show) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary Connectivity where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Network/Ouroboros.hs b/hydra-node/src/Hydra/Network/Ouroboros.hs index 52e3738eabc..1a517c6faa6 100644 --- a/hydra-node/src/Hydra/Network/Ouroboros.hs +++ b/hydra-node/src/Hydra/Network/Ouroboros.hs @@ -27,7 +27,7 @@ import Control.Concurrent.STM ( writeTChan, ) import Control.Exception (IOException) -import Data.Aeson (object, withObject, (.:), (.=)) +import Data.Aeson (object, (.=)) import Data.Aeson qualified as Aeson import Data.Aeson.Types qualified as Aeson import Data.Map.Strict as Map @@ -372,12 +372,6 @@ instance ToJSON trace => ToJSON (WithHost trace) where , "data" .= tr ] -instance FromJSON trace => FromJSON (WithHost trace) where - parseJSON = withObject "WithHost" $ \obj -> - WithHost - <$> (obj .: "host") - <*> (obj .: "data") - data TraceOuroborosNetwork msg = TraceSubscriptions (WithIPList (SubscriptionTrace SockAddr)) | TraceErrorPolicy (WithAddr SockAddr ErrorPolicyTrace) diff --git a/hydra-node/src/Hydra/Network/Reliability.hs b/hydra-node/src/Hydra/Network/Reliability.hs index 231906b7cf5..36beac9dd4b 100644 --- a/hydra-node/src/Hydra/Network/Reliability.hs +++ b/hydra-node/src/Hydra/Network/Reliability.hs @@ -122,7 +122,7 @@ data ReliableMsg msg = ReliableMsg , payload :: msg } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance ToCBOR msg => ToCBOR (ReliableMsg msg) where toCBOR ReliableMsg{knownMessageIds, payload} = toCBOR knownMessageIds <> toCBOR payload @@ -156,7 +156,7 @@ data ReliabilityLog , numberOfParties :: Int } deriving stock (Show, Eq, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary ReliabilityLog where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Node.hs b/hydra-node/src/Hydra/Node.hs index 4482fe76fba..596d0696ef2 100644 --- a/hydra-node/src/Hydra/Node.hs +++ b/hydra-node/src/Hydra/Node.hs @@ -234,9 +234,6 @@ data HydraNode tx m = HydraNode , server :: Server tx m } -instance HasParty (HydraNode tx m) where - getParty HydraNode{env} = getParty env - runHydraNode :: ( MonadCatch m , MonadAsync m @@ -391,7 +388,6 @@ data HydraNodeLog tx deriving stock instance IsChainState tx => Eq (HydraNodeLog tx) deriving stock instance IsChainState tx => Show (HydraNodeLog tx) deriving anyclass instance IsChainState tx => ToJSON (HydraNodeLog tx) -deriving anyclass instance IsChainState tx => FromJSON (HydraNodeLog tx) instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (HydraNodeLog tx) where arbitrary = genericArbitrary diff --git a/hydra-node/src/Hydra/Node/ParameterMismatch.hs b/hydra-node/src/Hydra/Node/ParameterMismatch.hs index 3efd2c21053..60bf96e75ae 100644 --- a/hydra-node/src/Hydra/Node/ParameterMismatch.hs +++ b/hydra-node/src/Hydra/Node/ParameterMismatch.hs @@ -20,7 +20,7 @@ data ParamMismatch | PartiesMismatch {loadedParties :: [Party], configuredParties :: [Party]} | SavedNetworkPartiesInconsistent {numberOfParties :: Int} deriving stock (Generic, Eq, Show) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON) instance Arbitrary ParamMismatch where arbitrary = genericArbitrary diff --git a/hydra-node/test/Hydra/BehaviorSpec.hs b/hydra-node/test/Hydra/BehaviorSpec.hs index 09ff9ed70ea..1541075c7da 100644 --- a/hydra-node/test/Hydra/BehaviorSpec.hs +++ b/hydra-node/test/Hydra/BehaviorSpec.hs @@ -23,7 +23,7 @@ import Data.List qualified as List import Hydra.API.ClientInput import Hydra.API.Server (Server (..)) import Hydra.API.ServerOutput (DecommitInvalidReason (..), ServerOutput (..)) -import Hydra.Cardano.Api (ChainPoint (..), SigningKey, SlotNo (SlotNo), Tx) +import Hydra.Cardano.Api (SigningKey) import Hydra.Chain ( Chain (..), ChainEvent (..), @@ -33,7 +33,6 @@ import Hydra.Chain ( ) import Hydra.Chain.ChainState (ChainSlot (ChainSlot), ChainStateType, IsChainState, chainStateSlot) import Hydra.Chain.Direct.Handlers (getLatest, newLocalChainState, pushNew, rollback) -import Hydra.Chain.Direct.State (ChainStateAt (..)) import Hydra.Events.FileBased (eventPairFromPersistenceIncremental) import Hydra.HeadLogic ( Effect (..), @@ -995,15 +994,6 @@ class IsChainState a => IsChainStateTest a where instance IsChainStateTest SimpleTx where advanceSlot SimpleChainState{slot} = SimpleChainState{slot = nextChainSlot slot} -instance IsChainStateTest Tx where - advanceSlot cs@ChainStateAt{recordedAt} = - let newChainPoint = case recordedAt of - Just (ChainPoint (SlotNo slotNo) bh) -> - ChainPoint (SlotNo slotNo + 1) bh - _NothingOrGenesis -> - ChainPoint (SlotNo 1) (error "should not use block header hash in tests") - in cs{recordedAt = Just newChainPoint} - -- | Creates a simulated chain and network to which 'HydraNode's can be -- connected to using 'connectNode'. NOTE: The 'tickThread' needs to be -- 'cancel'ed after use. Use 'withSimulatedChainAndNetwork' instead where diff --git a/hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs b/hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs index f4f40d74f63..c36635b6914 100644 --- a/hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs @@ -258,11 +258,6 @@ instance Num ModelSnapshot where , toDecommit = mempty } -instance Arbitrary ModelSnapshot where - arbitrary = genericArbitrary - - shrink = genericShrink - data State = Open | Closed diff --git a/hydra-node/test/Hydra/Model/Payment.hs b/hydra-node/test/Hydra/Model/Payment.hs index 275d06aa6d0..aaa2d715275 100644 --- a/hydra-node/test/Hydra/Model/Payment.hs +++ b/hydra-node/test/Hydra/Model/Payment.hs @@ -16,8 +16,6 @@ import Hydra.Tx.IsTx (IsTx (..)) import Test.Hydra.Tx.Fixture (testNetworkId) import Test.Hydra.Tx.Gen (genKeyPair) import Test.QuickCheck (choose) -import Test.QuickCheck.StateModel (HasVariables) -import Test.QuickCheck.StateModel.Variables (HasVariables (..)) import Prelude qualified -- NOTE: New type wrapper to add Ord and Eq instances to signing keys @@ -72,18 +70,12 @@ instance Show Payment where <> show value <> " }" -instance Arbitrary Payment where - arbitrary = error "don't use" - instance ToCBOR Payment where toCBOR = error "don't use" instance FromCBOR Payment where fromCBOR = error "don't use" -instance HasVariables Payment where - getAllVariables _ = mempty - -- | Making `Payment` an instance of `IsTx` allows us to use it with `HeadLogic'`s messages. instance IsTx Payment where type TxIdType Payment = Int diff --git a/hydra-node/test/Hydra/Node/InputQueueSpec.hs b/hydra-node/test/Hydra/Node/InputQueueSpec.hs index c14c2a9bf3b..74ec0b096dd 100644 --- a/hydra-node/test/Hydra/Node/InputQueueSpec.hs +++ b/hydra-node/test/Hydra/Node/InputQueueSpec.hs @@ -14,7 +14,7 @@ spec = prop "adds sequential id to all enqueued items" prop_identify_enqueued_items newtype DummyInput = DummyInput Int - deriving newtype (Eq, Show, Arbitrary) + deriving newtype (Eq, Show) prop_identify_enqueued_items :: NonEmptyList Int -> Property prop_identify_enqueued_items (NonEmpty inputs) = diff --git a/hydra-plutus-extras/hydra-plutus-extras.cabal b/hydra-plutus-extras/hydra-plutus-extras.cabal index 429394ce918..42217fa97d3 100644 --- a/hydra-plutus-extras/hydra-plutus-extras.cabal +++ b/hydra-plutus-extras/hydra-plutus-extras.cabal @@ -50,12 +50,10 @@ library , aeson , base , base16-bytestring - , bytestring , cardano-api , hydra-prelude , plutus-ledger-api >=1.1.1.0 , plutus-tx >=1.1.1.0 - , QuickCheck , quickcheck-instances , time diff --git a/hydra-plutus-extras/src/Hydra/Plutus/Orphans.hs b/hydra-plutus-extras/src/Hydra/Plutus/Orphans.hs index bf4d2514fa0..c77f508ecb4 100644 --- a/hydra-plutus-extras/src/Hydra/Plutus/Orphans.hs +++ b/hydra-plutus-extras/src/Hydra/Plutus/Orphans.hs @@ -8,44 +8,21 @@ import Hydra.Prelude import Data.Aeson (object, withObject, (.:), (.=)) import Data.Aeson qualified as Aeson -import Data.ByteString qualified as BS import Data.ByteString.Base16 qualified as Base16 -import PlutusLedgerApi.V3 (CurrencySymbol, POSIXTime (..), PubKeyHash (..), TokenName, TxId (..), TxOutRef (..), UpperBound, Value, upperBound) -import PlutusTx.AssocMap qualified as AssocMap -import PlutusTx.Prelude (BuiltinByteString, Eq, fromBuiltin, toBuiltin) -import Test.QuickCheck (choose, vectorOf) +import PlutusLedgerApi.V3 (CurrencySymbol, POSIXTime (..), PubKeyHash (..)) +import PlutusTx.Prelude (BuiltinByteString, fromBuiltin, toBuiltin) import Test.QuickCheck.Instances.ByteString () instance Arbitrary BuiltinByteString where arbitrary = toBuiltin <$> (arbitrary :: Gen ByteString) -instance Arbitrary TokenName where - arbitrary = genericArbitrary - shrink = genericShrink - instance Arbitrary CurrencySymbol where arbitrary = genericArbitrary shrink = genericShrink -instance Arbitrary Value where - arbitrary = genericArbitrary - shrink = genericShrink - -instance (PlutusTx.Prelude.Eq k, Arbitrary k, Arbitrary v) => Arbitrary (AssocMap.Map k v) where - arbitrary = AssocMap.safeFromList <$> arbitrary - instance Arbitrary POSIXTime where arbitrary = POSIXTime <$> arbitrary -instance ToJSON POSIXTime where - toJSON (POSIXTime ms) = toJSON ms - -instance FromJSON POSIXTime where - parseJSON = fmap POSIXTime . parseJSON - -instance Arbitrary a => Arbitrary (UpperBound a) where - arbitrary = upperBound <$> arbitrary - instance ToJSON PubKeyHash where toJSON kh = object @@ -66,9 +43,3 @@ instance FromJSON PubKeyHash where instance Arbitrary PubKeyHash where arbitrary = genericArbitrary - -instance Arbitrary TxOutRef where - arbitrary = do - txId <- TxId . toBuiltin . BS.pack <$> vectorOf 32 arbitrary - txIx <- choose (0, 99) - pure $ TxOutRef txId txIx diff --git a/hydra-plutus/src/Hydra/Data/ContestationPeriod.hs b/hydra-plutus/src/Hydra/Data/ContestationPeriod.hs index 222746fb1d6..083507445c6 100644 --- a/hydra-plutus/src/Hydra/Data/ContestationPeriod.hs +++ b/hydra-plutus/src/Hydra/Data/ContestationPeriod.hs @@ -21,14 +21,6 @@ PlutusTx.unstableMakeIsData ''ContestationPeriod instance Arbitrary ContestationPeriod where arbitrary = fromInteger <$> arbitrary -instance FromJSON ContestationPeriod where - parseJSON = - fmap (UnsafeContestationPeriod . fromInteger) . parseJSON - -instance ToJSON ContestationPeriod where - toJSON = - toJSON . toInteger . milliseconds - contestationPeriodFromDiffTime :: NominalDiffTime -> ContestationPeriod contestationPeriodFromDiffTime = UnsafeContestationPeriod . truncate . (* 1000) . nominalDiffTimeToSeconds diff --git a/hydra-plutus/src/Hydra/Data/Party.hs b/hydra-plutus/src/Hydra/Data/Party.hs index 99245df7130..3bec0282503 100644 --- a/hydra-plutus/src/Hydra/Data/Party.hs +++ b/hydra-plutus/src/Hydra/Data/Party.hs @@ -2,9 +2,7 @@ module Hydra.Data.Party where import Hydra.Prelude hiding (init) -import Data.Aeson (Value (String), object, withObject, (.:), (.=)) import Data.ByteString qualified as BS -import Data.ByteString.Base16 qualified as Base16 import PlutusTx qualified import PlutusTx.Builtins (BuiltinByteString, fromBuiltin, toBuiltin) import PlutusTx.IsData @@ -36,18 +34,6 @@ instance PlutusTx.FromData Party where instance PlutusTx.UnsafeFromData Party where unsafeFromBuiltinData = UnsafeParty . unsafeFromBuiltinData -instance ToJSON Party where - toJSON (UnsafeParty bytes) = - object ["vkey" .= String (decodeUtf8 $ Base16.encode $ fromBuiltin bytes)] - -instance FromJSON Party where - parseJSON = - withObject "Party" $ \o -> do - hexText :: Text <- o .: "vkey" - case Base16.decode $ encodeUtf8 hexText of - Left e -> fail e - Right bs -> pure UnsafeParty{vkey = toBuiltin bs} - -- | Create an on-chain 'Party' from some verification key bytes. partyFromVerificationKeyBytes :: ByteString -> Party partyFromVerificationKeyBytes = diff --git a/hydra-tx/src/Hydra/Tx/Close.hs b/hydra-tx/src/Hydra/Tx/Close.hs index c0938a0f279..76339b6421b 100644 --- a/hydra-tx/src/Hydra/Tx/Close.hs +++ b/hydra-tx/src/Hydra/Tx/Close.hs @@ -44,7 +44,6 @@ data OpenThreadOutput = OpenThreadOutput , openParties :: [OnChain.Party] } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) -- | Create a transaction closing a head with either the initial snapshot or -- with a multi-signed confirmed snapshot. diff --git a/hydra-tx/src/Hydra/Tx/Contest.hs b/hydra-tx/src/Hydra/Tx/Contest.hs index d0d1be156ba..202179c5473 100644 --- a/hydra-tx/src/Hydra/Tx/Contest.hs +++ b/hydra-tx/src/Hydra/Tx/Contest.hs @@ -37,7 +37,6 @@ data ClosedThreadOutput = ClosedThreadOutput , closedContesters :: [Plutus.PubKeyHash] } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) -- XXX: This function is VERY similar to the 'closeTx' function (only notable -- difference being the redeemer, which is in itself also the same structure as diff --git a/hydra-tx/src/Hydra/Tx/Crypto.hs b/hydra-tx/src/Hydra/Tx/Crypto.hs index 8c15582972b..57e59f7be98 100644 --- a/hydra-tx/src/Hydra/Tx/Crypto.hs +++ b/hydra-tx/src/Hydra/Tx/Crypto.hs @@ -31,10 +31,8 @@ import Cardano.Crypto.DSIGN ( genKeyDSIGN, hashVerKeyDSIGN, rawDeserialiseSigDSIGN, - rawDeserialiseSignKeyDSIGN, rawDeserialiseVerKeyDSIGN, rawSerialiseSigDSIGN, - rawSerialiseSignKeyDSIGN, rawSerialiseVerKeyDSIGN, seedSizeDSIGN, signDSIGN, @@ -51,7 +49,7 @@ import Data.ByteString qualified as BS import Data.ByteString.Base16 qualified as Base16 import Data.Map qualified as Map import Hydra.Cardano.Api ( - AsType (AsHash, AsSigningKey, AsVerificationKey), + AsType (AsHash, AsVerificationKey), HasTextEnvelope (..), HasTypeProxy (..), Hash, @@ -129,13 +127,6 @@ instance Key HydraKey where instance Arbitrary (SigningKey HydraKey) where arbitrary = generateSigningKey . BS.pack <$> vectorOf 32 arbitrary -instance SerialiseAsRawBytes (SigningKey HydraKey) where - serialiseToRawBytes (HydraSigningKey sk) = - rawSerialiseSignKeyDSIGN sk - - deserialiseFromRawBytes (AsSigningKey AsHydraKey) bs = - maybe (error "TODO: SerialiseAsRawBytesError, but constructor not exported") (Right . HydraSigningKey) (rawDeserialiseSignKeyDSIGN bs) - instance HasTextEnvelope (SigningKey HydraKey) where textEnvelopeType _ = "HydraSigningKey_" @@ -278,7 +269,6 @@ data Verified | FailedKeys {failedKeys :: [VerificationKey HydraKey]} | KeyNumberMismatch deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) -- | Verify a given 'MultiSignature a' and value 'a' provided a list of -- 'VerificationKey'. diff --git a/hydra-tx/src/Hydra/Tx/HeadId.hs b/hydra-tx/src/Hydra/Tx/HeadId.hs index c12e86ddf50..2ef6ad91c5b 100644 --- a/hydra-tx/src/Hydra/Tx/HeadId.hs +++ b/hydra-tx/src/Hydra/Tx/HeadId.hs @@ -21,7 +21,6 @@ import Test.QuickCheck.Instances.Time () newtype HeadId = UnsafeHeadId ByteString deriving stock (Show, Eq, Ord, Generic) deriving (ToJSON, FromJSON) via (UsingRawBytesHex HeadId) - deriving newtype (FromCBOR, ToCBOR) instance SerialiseAsRawBytes HeadId where serialiseToRawBytes (UnsafeHeadId bytes) = bytes diff --git a/hydra-tx/src/Hydra/Tx/ScriptRegistry.hs b/hydra-tx/src/Hydra/Tx/ScriptRegistry.hs index 72e4400f1d9..8f9f5247fe4 100644 --- a/hydra-tx/src/Hydra/Tx/ScriptRegistry.hs +++ b/hydra-tx/src/Hydra/Tx/ScriptRegistry.hs @@ -26,7 +26,6 @@ data ScriptRegistry = ScriptRegistry , headReference :: (TxIn, TxOut CtxUTxO) } deriving stock (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) data NewScriptRegistryException = MissingScript { scriptName :: Text diff --git a/hydra-tx/src/Hydra/Tx/Snapshot.hs b/hydra-tx/src/Hydra/Tx/Snapshot.hs index 3b174956f94..67617b18799 100644 --- a/hydra-tx/src/Hydra/Tx/Snapshot.hs +++ b/hydra-tx/src/Hydra/Tx/Snapshot.hs @@ -113,27 +113,6 @@ instance IsTx tx => FromJSON (Snapshot tx) where (Just utxo) -> pure utxo ) -instance (Typeable tx, ToCBOR tx, ToCBOR (UTxOType tx)) => ToCBOR (Snapshot tx) where - toCBOR Snapshot{headId, number, utxo, confirmed, utxoToCommit, utxoToDecommit, version} = - toCBOR headId - <> toCBOR version - <> toCBOR number - <> toCBOR confirmed - <> toCBOR utxo - <> toCBOR utxoToCommit - <> toCBOR utxoToDecommit - -instance (Typeable tx, FromCBOR tx, FromCBOR (UTxOType tx)) => FromCBOR (Snapshot tx) where - fromCBOR = - Snapshot - <$> fromCBOR - <*> fromCBOR - <*> fromCBOR - <*> fromCBOR - <*> fromCBOR - <*> fromCBOR - <*> fromCBOR - instance (Arbitrary tx, Arbitrary (UTxOType tx)) => Arbitrary (Snapshot tx) where arbitrary = genericArbitrary diff --git a/hydra-tx/testlib/Test/Hydra/Tx/Gen.hs b/hydra-tx/testlib/Test/Hydra/Tx/Gen.hs index 1dbc42bae3b..9f96f541908 100644 --- a/hydra-tx/testlib/Test/Hydra/Tx/Gen.hs +++ b/hydra-tx/testlib/Test/Hydra/Tx/Gen.hs @@ -23,11 +23,8 @@ import Hydra.Contract.Util (hydraHeadV1) import Hydra.Plutus (commitValidatorScript, initialValidatorScript) import Hydra.Tx (ScriptRegistry (..)) import Hydra.Tx.Close (OpenThreadOutput) -import Hydra.Tx.Contest (ClosedThreadOutput) import Hydra.Tx.Crypto (Hash (..)) -import Hydra.Tx.Deposit (DepositObservation) import Hydra.Tx.Party (Party (..)) -import Hydra.Tx.Recover (RecoverObservation) import PlutusTx.Builtins (fromBuiltin) import Test.Cardano.Ledger.Conway.Arbitrary () import Test.Hydra.Tx.Fixture qualified as Fixtures @@ -264,16 +261,6 @@ instance Arbitrary OpenThreadOutput where arbitrary = genericArbitrary shrink = genericShrink -instance Arbitrary ClosedThreadOutput where - arbitrary = genericArbitrary - shrink = genericShrink - -instance Arbitrary DepositObservation where - arbitrary = genericArbitrary - -instance Arbitrary RecoverObservation where - arbitrary = genericArbitrary - instance Arbitrary Tx where -- TODO: shrinker! arbitrary = fromLedgerTx <$> arbitrary diff --git a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs index dec711e0a5e..61f92a22041 100644 --- a/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs +++ b/hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs @@ -507,30 +507,6 @@ deriving stock instance Eq Head.DecrementRedeemer deriving stock instance Eq Head.CloseRedeemer deriving stock instance Eq Head.ContestRedeemer -instance Arbitrary Head.IncrementRedeemer where - arbitrary = genericArbitrary - -instance Arbitrary Head.DecrementRedeemer where - arbitrary = genericArbitrary - -instance Arbitrary Head.CloseRedeemer where - arbitrary = genericArbitrary - -instance Arbitrary Head.ContestRedeemer where - arbitrary = genericArbitrary - -instance Arbitrary Head.Input where - arbitrary = genericArbitrary - -instance Arbitrary Head.OpenDatum where - arbitrary = genericArbitrary - -instance Arbitrary Head.ClosedDatum where - arbitrary = genericArbitrary - -instance Arbitrary Head.State where - arbitrary = genericArbitrary - -- * Helpers -- | Identify Head script's output. diff --git a/weeder.toml b/weeder.toml index 75709b4eb11..379b7f034e5 100644 --- a/weeder.toml +++ b/weeder.toml @@ -1,4 +1,5 @@ -roots = [ "^Main.main$" +roots = [ + "^Main.main$" , "^Spec.main$" , "^main$" , "validatorHash$" @@ -11,4 +12,31 @@ roots = [ "^Main.main$" , "showFromAction$" , "redeemer$" ] -type-class-roots = true +root-instances = [ + # Stock instances are treated as roots. + { class = '\.Eq$' } + , { class = '\.Show$' } + , { class = '\.Read$' } + , { class = '\.Enum$' } + , { class = '\.Bounded$' } + , { class = '\.Generic$' } + , { class = '\.Ord$' } + , { class = '\.Num$' } + , { class = '\.Real$' } + , { class = '\.Integral$' } + # unstableMakeIsData creates all Data instances at once, some are unused and + # so are treated as roots. + , { module = "Hydra.Contract.Commit", instance = "UnsafeFromData Commit" } + , { module = "Hydra.Contract.Commit", instance = "FromData RedeemerType" } + , { module = "Hydra.Contract.Commit", instance = "UnsafeFromData RedeemerType" } + , { module = "Hydra.Contract.Deposit", instance = "FromData DepositRedeemer" } + , { module = "Hydra.Contract.MintAction", instance = "FromData MintAction" } + # This one is odd. + , { module = "Hydra.Network.Ouroboros.Type", instance = "Protocol" } + # TODO: Remove this + , { module = "Hydra.Model.Payment", instance = "IsTx" } + # These are used for debugging. + , { module = "Hydra.Chain.Direct.TxTraceSpec", instance = "HasVariables" } + , { module = "Hydra.Chain.Direct.TxTraceSpec", instance = "MonadFail AppM" } + , { module = "Hydra.Chain.Direct.TxTraceSpec", instance = "MonadThrow AppM" } + ]