Skip to content

Commit

Permalink
Fix code following dependencies upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-iohk committed Oct 12, 2021
1 parent ae9b5f7 commit 6971aff
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion cabal.project
@@ -1,4 +1,4 @@
index-state: 2021-07-07T00:00:00Z
index-state: 2021-08-14T00:00:00Z

packages:
local-cluster
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions hydra-node/hydra-node.cabal
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions 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
Expand Down Expand Up @@ -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 (..),
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions hydra-node/src/Hydra/Chain/ExternalPAB.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions hydra-node/src/Hydra/Ledger/Cardano.hs
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/TxSpec.hs
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions hydra-plutus/hydra-plutus.cabal
Expand Up @@ -95,6 +95,7 @@ library
, freer-simple
, hydra-prelude
, lens
, openapi3
, playground-common
, plutus-chain-index
, plutus-contract
Expand Down
3 changes: 2 additions & 1 deletion hydra-plutus/src/Hydra/PAB.hs
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions hydra-plutus/test/Hydra/ContractModelTest.hs
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions hydra-plutus/test/Hydra/ContractTest.hs
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/test/Test/EndToEndSpec.hs
Expand Up @@ -255,7 +255,7 @@ txAlicePaysHerself =
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = BuildTxWith TxScriptValidityNone
, txScriptValidity = TxScriptValidityNone
}

txIn = TxIn someTxId (toEnum 0)
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Expand Up @@ -32,6 +32,7 @@ let
pkgs.systemd
pkgs.zlib
pkgs.zeromq
pkgs.lzma
];

tools = [
Expand Down

0 comments on commit 6971aff

Please sign in to comment.