Skip to content

cardano-testnet | Add test submitting transaction with reference inputs and actual datums #6174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ test-suite cardano-testnet-test

main-is: cardano-testnet-test.hs

other-modules: Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
other-modules: Cardano.Testnet.Test.Api.TxReferenceInputDatum
Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
Cardano.Testnet.Test.Cli.KesPeriodInfo
Cardano.Testnet.Test.Cli.LeadershipSchedule
Cardano.Testnet.Test.Cli.Query
Expand Down
24 changes: 17 additions & 7 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Testnet.Components.Query
, checkDRepsNumber
, checkDRepState
, assertNewEpochState
, getProtocolParams
, getGovActionLifetime
, getKeyDeposit
, getDelegationState
Expand All @@ -44,8 +45,9 @@ module Testnet.Components.Query

import Cardano.Api as Api
import Cardano.Api.Ledger (Credential, DRepState, EpochInterval (..), KeyRole (DRepRole))
import Cardano.Api.Shelley (ShelleyLedgerEra)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (LedgerProtocolParameters (..), ShelleyLedgerEra)
import qualified Cardano.Api.Tx.UTxO as Utxo

import Cardano.Crypto.Hash (hashToStringAsHex)
import Cardano.Ledger.Api (ConwayGovState)
Expand All @@ -65,7 +67,6 @@ import Data.IORef
import Data.List (sortOn)
import qualified Data.Map as Map
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Ord (Down (..))
import Data.Text (Text)
Expand Down Expand Up @@ -301,11 +302,11 @@ findAllUtxos
=> MonadTest m
=> EpochStateView
-> ShelleyBasedEra era
-> m (Map TxIn (TxOut CtxUTxO era))
-> m (UTxO era)
findAllUtxos epochStateView sbe = withFrozenCallStack $ do
AnyNewEpochState sbe' _ tbs <- getEpochState epochStateView
Refl <- H.leftFail $ assertErasEqual sbe sbe'
pure $ getLedgerTablesUTxOValues sbe' tbs
pure . UTxO $ getLedgerTablesUTxOValues sbe' tbs

-- | Retrieve utxos from the epoch state view for an address.
findUtxosWithAddress
Expand All @@ -316,7 +317,7 @@ findUtxosWithAddress
=> EpochStateView
-> ShelleyBasedEra era
-> Text -- ^ Address
-> m (Map TxIn (TxOut CtxUTxO era))
-> m (UTxO era)
findUtxosWithAddress epochStateView sbe address = withFrozenCallStack $ do
utxos <- findAllUtxos epochStateView sbe
H.note_ $ "Finding UTxOs for " <> T.unpack address
Expand All @@ -327,7 +328,7 @@ findUtxosWithAddress epochStateView sbe address = withFrozenCallStack $ do
maybeToEither ("Could not deserialize address: " <> T.unpack address)
(deserialiseAddress AsAddressAny address)

let utxos' = M.filter (\(TxOut txAddr _ _ _) -> txAddr == address') utxos
let utxos' = Utxo.filter (\(TxOut txAddr _ _ _) -> txAddr == address') utxos
H.note_ $ unlines (map show $ toList utxos')
pure utxos'
where
Expand All @@ -344,7 +345,7 @@ findLargestUtxoWithAddress
-> Text -- ^ Address
-> m (Maybe (TxIn, TxOut CtxUTxO era))
findLargestUtxoWithAddress epochStateView sbe address = withFrozenCallStack $ do
utxos <- M.assocs <$> findUtxosWithAddress epochStateView sbe address
utxos <- toList <$> findUtxosWithAddress epochStateView sbe address
pure
. listToMaybe
$ sortOn (\(_, TxOut _ txOutValue _ _) -> Down $ txOutValueToLovelace txOutValue) utxos
Expand Down Expand Up @@ -558,6 +559,15 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta
Refl <- H.leftFail $ assertErasEqual sbe actualEra
pure $ newEpochState ^. lens

-- | Return current protocol parameters from the governance state
getProtocolParams :: (H.MonadAssertion m, MonadTest m, MonadIO m)
=> EpochStateView
-> ConwayEraOnwards era
-> m (LedgerProtocolParameters era)
getProtocolParams epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
govState :: ConwayGovState era <- getGovState epochStateView ceo
pure . LedgerProtocolParameters $ govState ^. L.cgsCurPParamsL


-- | Obtains the @govActionLifetime@ from the protocol parameters.
-- The @govActionLifetime@ or governance action maximum lifetime in epochs is
Expand Down
28 changes: 24 additions & 4 deletions cardano-testnet/src/Testnet/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Testnet.Types
, testnetSprockets
, TestnetNode(..)
, nodeSocketPath
, nodeConnectionInfo
, isTestnetNodeSpo
, SpoNodeKeys(..)
, Delegator(..)
Expand Down Expand Up @@ -62,18 +63,20 @@ import Data.List (intercalate)
import Data.Maybe
import Data.MonoTraversable (Element, MonoFunctor (..))
import Data.Text (Text)
import Data.Time.Clock (UTCTime)
import GHC.Exts (IsString (..))
import GHC.Generics (Generic)
import qualified GHC.IO.Handle as IO
import GHC.Stack
import Lens.Micro (ix, (^?))
import Network.Socket (HostAddress, PortNumber, hostAddressToTuple, tupleToHostAddress)
import System.FilePath
import qualified System.Process as IO

import Testnet.Start.Types

import Hedgehog (MonadTest)
import qualified Hedgehog as H
import qualified Hedgehog.Extras as H
import qualified Hedgehog.Extras.Stock as H
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))

Expand Down Expand Up @@ -115,7 +118,7 @@ data SKey k
data TestnetRuntime = TestnetRuntime
{ configurationFile :: !(NodeConfigFile In)
, shelleyGenesisFile :: !FilePath
, testnetMagic :: !Int
, testnetMagic :: !Int -- TODO change to Word32
, testnetNodes :: ![TestnetNode]
, wallets :: ![PaymentKeyInfo]
, delegators :: ![Delegator]
Expand Down Expand Up @@ -148,6 +151,23 @@ isTestnetNodeSpo = isJust . poolKeys
nodeSocketPath :: TestnetNode -> SocketPath
nodeSocketPath = File . H.sprocketSystemName . nodeSprocket

-- | Connection data for a node in the testnet
nodeConnectionInfo :: MonadTest m
=> TestnetRuntime
-> Int -- ^ node index, starting from 0
-> m LocalNodeConnectInfo -- ^ fails when there's no node with requested index
nodeConnectionInfo TestnetRuntime{testnetMagic, testnetNodes} index =
case testnetNodes ^? ix index of
Nothing -> do
H.note_ $ "There is no node in the testnet with index: " <> show index <> ". Number of nodes: " <> show (length testnetNodes)
H.failure
Just node ->
pure LocalNodeConnectInfo
{ localNodeSocketPath= nodeSocketPath node
, localNodeNetworkId=Testnet (NetworkMagic $ fromIntegral testnetMagic)
, localConsensusModeParams=CardanoModeParams $ EpochSlots 21600}


data SpoNodeKeys = SpoNodeKeys
{ poolNodeKeysCold :: KeyPair StakePoolKey
, poolNodeKeysVrf :: KeyPair VrfKey
Expand Down Expand Up @@ -187,14 +207,14 @@ getStartTime
=> HasCallStack
=> FilePath
-> TestnetRuntime
-> m UTCTime
-> m SystemStart
getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do
byronGenesisFile <-
decodeNodeConfiguration configurationFile >>= \case
NodeProtocolConfigurationCardano NodeByronProtocolConfiguration{npcByronGenesisFile} _ _ _ _ _ ->
pure $ unGenesisFile npcByronGenesisFile
let byronGenesisFilePath = tempRootPath </> byronGenesisFile
G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath
SystemStart . G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath
where
decodeNodeConfiguration :: File NodeConfig In -> ExceptT String IO NodeProtocolConfiguration
decodeNodeConfiguration (File file) = do
Expand Down
Loading
Loading