From 6971aff9cd73002789a0e0add8b4549a2117c147 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 12 Oct 2021 09:35:59 +0000 Subject: [PATCH] Fix code following dependencies upgrade --- cabal.project | 3 ++- hydra-node/hydra-node.cabal | 1 + hydra-node/src/Hydra/Chain/Direct/Wallet.hs | 6 +++--- hydra-node/src/Hydra/Chain/ExternalPAB.hs | 6 +++--- hydra-node/src/Hydra/Ledger/Cardano.hs | 8 ++++---- hydra-node/test/Hydra/Chain/Direct/TxSpec.hs | 18 ++++++++++++++++-- hydra-plutus/hydra-plutus.cabal | 1 + hydra-plutus/src/Hydra/PAB.hs | 3 ++- hydra-plutus/test/Hydra/ContractModelTest.hs | 6 +++--- hydra-plutus/test/Hydra/ContractTest.hs | 5 +++-- local-cluster/test/Test/EndToEndSpec.hs | 2 +- shell.nix | 1 + 12 files changed, 40 insertions(+), 20 deletions(-) diff --git a/cabal.project b/cabal.project index c36c74f9664..4b56cdbc7d9 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,4 @@ -index-state: 2021-07-07T00:00:00Z +index-state: 2021-08-14T00:00:00Z packages: local-cluster @@ -201,6 +201,7 @@ source-repository-package cardano-protocol-tpraos alonzo/impl alonzo/test + cardano-ledger-test -- A lot of plutus dependencies have to be synchronized with the dependencies of -- cardano-node. If you update cardano-node, please make sure that all dependencies diff --git a/hydra-node/hydra-node.cabal b/hydra-node/hydra-node.cabal index 8a7ac7fe55f..88371615be9 100644 --- a/hydra-node/hydra-node.cabal +++ b/hydra-node/hydra-node.cabal @@ -238,6 +238,7 @@ test-suite tests , cardano-ledger-core , cardano-ledger-shelley-ma , cardano-ledger-shelley-ma-test + , cardano-ledger-test , cardano-slotting , cborg , containers diff --git a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs index cd13943d10f..92965ec41a0 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs @@ -1,5 +1,5 @@ {-# LANGUAGE PatternSynonyms #-} - +{-# OPTIONS_GHC -Wno-unused-imports #-} -- | Companion tiny-wallet for the direct chain component. This module provide -- some useful utilities to tracking the wallet's UTXO, and accessing it module Hydra.Chain.Direct.Wallet where @@ -46,7 +46,7 @@ import Ouroboros.Consensus.Ledger.Query (Query (..)) import Ouroboros.Consensus.Network.NodeToClient (Codecs' (..)) import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock (..), ShelleyHash (..)) import Ouroboros.Consensus.Shelley.Ledger.Query (BlockQuery (..)) -import Ouroboros.Network.Block (Point (..), Tip (..), castPoint, genesisPoint) +import Ouroboros.Network.Block (Point (..), Tip (..), castPoint, blockPoint, genesisPoint) import Ouroboros.Network.Magic (NetworkMagic (..)) import Ouroboros.Network.Mux ( MuxMode (..), @@ -75,7 +75,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Client ( ) import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as LSQ import qualified Shelley.Spec.Ledger.API as Ledger hiding (TxBody, TxOut) -import Shelley.Spec.Ledger.BlockChain (HashHeader (..)) +import Shelley.Spec.Ledger.BlockChain (HashHeader) import Shelley.Spec.Ledger.TxBody (TxId (..), pattern TxIn) import Test.QuickCheck (generate) diff --git a/hydra-node/src/Hydra/Chain/ExternalPAB.hs b/hydra-node/src/Hydra/Chain/ExternalPAB.hs index e9413d884b9..3e0b2716cb3 100644 --- a/hydra-node/src/Hydra/Chain/ExternalPAB.hs +++ b/hydra-node/src/Hydra/Chain/ExternalPAB.hs @@ -43,7 +43,7 @@ import Network.HTTP.Req ( import Network.WebSockets (receiveData) import Network.WebSockets.Client (runClient) import Plutus.PAB.Webserver.Types (InstanceStatusToClient (NewObservableState)) -import Wallet.Emulator.Types (Wallet (..), walletPubKey) +import Wallet.Emulator.Types (Wallet (..), knownWallet, walletPubKey) import Wallet.Types (ContractInstanceId (..)) data ExternalPabLog = ExternalPabLog @@ -83,10 +83,10 @@ withExternalPab walletId _tracer callback action = do Just tt -> postAbortTx @tx wallet tt utxo tx -> error $ "should post " <> show tx - wallet = Wallet walletId + wallet = knownWallet walletId -- TODO(SN): Parameterize this - allWallets = [Wallet 1, Wallet 2, Wallet 3] + allWallets = map knownWallet [1, 2, 3] pubKeys = map walletPubKey allWallets activateContract :: PabContract -> Wallet -> IO ContractInstanceId diff --git a/hydra-node/src/Hydra/Ledger/Cardano.hs b/hydra-node/src/Hydra/Ledger/Cardano.hs index ee17e2b1f1b..faa42cf3809 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano.hs @@ -485,7 +485,7 @@ instance Crypto crypto => FromJSON (Cardano.TxOut (MaryEra crypto)) where (p, Just _) -> fail $ "invalid bech32 prefix: " <> show p (_, Nothing) -> fail "failed to decode data part" -instance ToJSON (Cardano.Value crypto) where +instance Crypto crypto => ToJSON (Cardano.Value crypto) where toJSON (Cardano.Value lovelace assets) = object $ [ "lovelace" .= lovelace @@ -498,13 +498,13 @@ instance Crypto crypto => FromJSON (Cardano.Value crypto) where parseJSON = withObject "Value" $ \o -> Cardano.Value <$> o .: "lovelace" <*> o .:? "assets" .!= mempty -instance ToJSON (Cardano.PolicyID crypto) where +instance Crypto crypto => ToJSON (Cardano.PolicyID crypto) where toJSON (Cardano.PolicyID h) = toJSON h instance Crypto crypto => FromJSON (Cardano.PolicyID crypto) where parseJSON v = Cardano.PolicyID <$> parseJSON v -instance ToJSONKey (Cardano.PolicyID crypto) where +instance Crypto crypto => ToJSONKey (Cardano.PolicyID crypto) where toJSONKey = contramap (\(Cardano.PolicyID h) -> h) toJSONKey instance Crypto crypto => FromJSONKey (Cardano.PolicyID crypto) where @@ -664,7 +664,7 @@ instance FromJSON (Cardano.Timelock StandardCrypto) where Left err -> fail $ show err Right v -> pure v -instance ToJSONKey (Cardano.ScriptHash crypto) where +instance Crypto crypto => ToJSONKey (Cardano.ScriptHash crypto) where toJSONKey = toJSONKeyText (\(Cardano.ScriptHash h) -> decodeUtf8 $ Base16.encode (Crypto.hashToBytes h)) instance Crypto crypto => FromJSONKey (Cardano.ScriptHash crypto) where diff --git a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs index 367ff0802b2..1b9f83b3cf6 100644 --- a/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/TxSpec.hs @@ -8,11 +8,14 @@ module Hydra.Chain.Direct.TxSpec where import Hydra.Prelude import Test.Hydra.Prelude +import Test.Cardano.Ledger.Generic.Updaters hiding (vkey) +import Test.Cardano.Ledger.Generic.Proof import Cardano.Binary (serialize, serialize') import Cardano.Ledger.Alonzo (TxOut) import Cardano.Ledger.Alonzo.Data (Data (Data), hashData) import Cardano.Ledger.Alonzo.Language (Language (PlutusV1)) -import Cardano.Ledger.Alonzo.Scripts (ExUnits) +import Cardano.Ledger.Alonzo.PParams (PParams, ProtVer (..)) +import Cardano.Ledger.Alonzo.Scripts (ExUnits(..)) import Cardano.Ledger.Alonzo.Tools (ScriptFailure, evaluateTransactionExecutionUnits) import Cardano.Ledger.Alonzo.Tx (ValidatedTx (ValidatedTx, body, wits)) import Cardano.Ledger.Alonzo.TxBody (TxOut (TxOut)) @@ -151,7 +154,7 @@ validateTxScriptsUnlimited :: UTxO Era -> Map RdmrPtr (Either (ScriptFailure StandardCrypto) ExUnits) validateTxScriptsUnlimited tx utxo = - runIdentity $ evaluateTransactionExecutionUnits tx utxo epochInfo systemStart costmodels + runIdentity $ evaluateTransactionExecutionUnits pparams tx utxo epochInfo systemStart costmodels where -- REVIEW(SN): taken from 'testGlobals' epochInfo = fixedEpochInfo (EpochSize 100) (mkSlotLength 1) @@ -160,6 +163,17 @@ validateTxScriptsUnlimited tx utxo = -- NOTE(SN): copied from Test.Cardano.Ledger.Alonzo.Tools as not exported costmodels = array (PlutusV1, PlutusV1) [(PlutusV1, fromJust defaultCostModel)] +pparams :: PParams Era +pparams = + newPParams + (Alonzo Standard) + [ Costmdls $ Map.singleton PlutusV1 $ fromJust defaultCostModel, + MaxValSize 1000000000, + MaxTxExUnits $ ExUnits 100000000 100000000, + MaxBlockExUnits $ ExUnits 100000000 100000000, + ProtocolVersion $ ProtVer 5 0 + ] + -- | Extract NFT candidates. any single quantity assets not being ADA is a -- candidate. txOutNFT :: TxOut Era -> [(PolicyID StandardCrypto, AssetName)] diff --git a/hydra-plutus/hydra-plutus.cabal b/hydra-plutus/hydra-plutus.cabal index f97d082eb24..f9824446b31 100644 --- a/hydra-plutus/hydra-plutus.cabal +++ b/hydra-plutus/hydra-plutus.cabal @@ -95,6 +95,7 @@ library , freer-simple , hydra-prelude , lens + , openapi3 , playground-common , plutus-chain-index , plutus-contract diff --git a/hydra-plutus/src/Hydra/PAB.hs b/hydra-plutus/src/Hydra/PAB.hs index 69598ff5e32..c857b800558 100644 --- a/hydra-plutus/src/Hydra/PAB.hs +++ b/hydra-plutus/src/Hydra/PAB.hs @@ -50,6 +50,7 @@ import qualified Plutus.Contract.StateMachine as SM import Plutus.Contract.Types (Promise (..)) import qualified Plutus.Contracts.Currency as Currency import Plutus.PAB.Effects.Contract.Builtin (HasDefinitions (..), SomeBuiltin (..)) +import Data.OpenApi.Internal.Schema(ToSchema) -- | Hard-coded port used between hydra-node and the PAB server. pabPort :: Int @@ -63,7 +64,7 @@ data PabContract | WatchInit | WatchHead deriving (Eq, Show, Generic) - deriving anyclass (ToJSON, FromJSON) + deriving anyclass (ToJSON, FromJSON, ToSchema) instance Pretty PabContract where pretty = viaShow diff --git a/hydra-plutus/test/Hydra/ContractModelTest.hs b/hydra-plutus/test/Hydra/ContractModelTest.hs index dcb15c53039..10e645a8936 100644 --- a/hydra-plutus/test/Hydra/ContractModelTest.hs +++ b/hydra-plutus/test/Hydra/ContractModelTest.hs @@ -12,16 +12,16 @@ import Ledger (pubKeyHash) import Ledger.Ada as Ada import Ledger.Typed.Scripts (MintingPolicy) import Plutus.Contract (Contract) -import Plutus.Contract.Test (Wallet, walletPubKey) +import Plutus.Contract.Test (Wallet(..), walletPubKey) +import Wallet.Emulator.Wallet(knownWallet) import Plutus.Contract.Test.ContractModel -import Plutus.Contract.Trace (Wallet (Wallet)) import Plutus.Contract.Types (ContractError) import Test.QuickCheck (Property, Testable (property)) import Test.Tasty (TestTree, testGroup) import Test.Tasty.QuickCheck (testProperty) w1, w2, w3 :: Wallet -[w1, w2, w3] = map Wallet [1, 2, 3] +[w1, w2, w3] = map knownWallet [1, 2, 3] wallets :: [Wallet] wallets = [w1, w2, w3] diff --git a/hydra-plutus/test/Hydra/ContractTest.hs b/hydra-plutus/test/Hydra/ContractTest.hs index fb2df9406c1..7ce59413946 100644 --- a/hydra-plutus/test/Hydra/ContractTest.hs +++ b/hydra-plutus/test/Hydra/ContractTest.hs @@ -29,6 +29,7 @@ import Plutus.Trace.Emulator.Types (walletInstanceTag) import PlutusTx.Monoid (inv) import Test.Tasty (TestTree, testGroup) import Wallet.Types (ContractError (..)) +import Wallet.Emulator.Wallet(knownWallet) import qualified Control.Monad.Freer.Extras.Log as Trace import qualified Data.Map.Strict as Map @@ -43,10 +44,10 @@ import qualified Prelude -- alice :: Wallet -alice = Wallet 1 +alice = knownWallet 1 bob :: Wallet -bob = Wallet 2 +bob = knownWallet 2 testPolicy :: MintingPolicy testPolicy = OnChain.hydraMintingPolicy 42 diff --git a/local-cluster/test/Test/EndToEndSpec.hs b/local-cluster/test/Test/EndToEndSpec.hs index 29f4fd45a76..71d80cdad92 100644 --- a/local-cluster/test/Test/EndToEndSpec.hs +++ b/local-cluster/test/Test/EndToEndSpec.hs @@ -255,7 +255,7 @@ txAlicePaysHerself = , txCertificates = TxCertificatesNone , txUpdateProposal = TxUpdateProposalNone , txMintValue = TxMintNone - , txScriptValidity = BuildTxWith TxScriptValidityNone + , txScriptValidity = TxScriptValidityNone } txIn = TxIn someTxId (toEnum 0) diff --git a/shell.nix b/shell.nix index 893bfe8e258..b8de953d004 100644 --- a/shell.nix +++ b/shell.nix @@ -32,6 +32,7 @@ let pkgs.systemd pkgs.zlib pkgs.zeromq + pkgs.lzma ]; tools = [