Skip to content

Commit 72e96a7

Browse files
committed
wip
1 parent 8aaa929 commit 72e96a7

File tree

5 files changed

+139
-4
lines changed

5 files changed

+139
-4
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ test-suite cardano-testnet-test
185185

186186
main-is: cardano-testnet-test.hs
187187

188-
other-modules: Cardano.Testnet.Test.Cli.Conway.Plutus
188+
other-modules:
189+
Cardano.Testnet.Test.Api.TxSupplementalDatum
190+
Cardano.Testnet.Test.Cli.Conway.Plutus
189191
Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
190192
Cardano.Testnet.Test.Cli.KesPeriodInfo
191193
Cardano.Testnet.Test.Cli.LeadershipSchedule

cardano-testnet/src/Testnet/Components/Query.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ module Testnet.Components.Query
3636
, checkDRepsNumber
3737
, checkDRepState
3838
, assertNewEpochState
39+
, getProtocolParams
3940
, getGovActionLifetime
4041
, getKeyDeposit
4142
, getDelegationState
4243
) where
4344

4445
import Cardano.Api as Api
4546
import Cardano.Api.Ledger (Credential, DRepState, EpochInterval (..), KeyRole (DRepRole))
46-
import Cardano.Api.Shelley (ShelleyLedgerEra, fromShelleyTxIn, fromShelleyTxOut)
47+
import Cardano.Api.Shelley (LedgerProtocolParameters (..), ShelleyLedgerEra,
48+
fromShelleyTxIn, fromShelleyTxOut)
4749

4850
import Cardano.Ledger.Api (ConwayGovState)
4951
import qualified Cardano.Ledger.Api as L
@@ -566,6 +568,15 @@ assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallSta
566568
Refl <- H.leftFail $ assertErasEqual sbe actualEra
567569
pure $ newEpochState ^. lens
568570

571+
-- | Return current protocol parameters from the governance state
572+
getProtocolParams :: (H.MonadAssertion m, MonadTest m, MonadIO m)
573+
=> EpochStateView
574+
-> ConwayEraOnwards era
575+
-> m (LedgerProtocolParameters era)
576+
getProtocolParams epochStateView ceo = conwayEraOnwardsConstraints ceo $ do
577+
govState :: ConwayGovState era <- getGovState epochStateView ceo
578+
pure . LedgerProtocolParameters $ govState ^. L.cgsCurPParamsL
579+
569580

570581
-- | Obtains the @govActionLifetime@ from the protocol parameters.
571582
-- The @govActionLifetime@ or governance action maximum lifetime in epochs is

cardano-testnet/src/Testnet/Types.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Testnet.Types
2121
, testnetSprockets
2222
, TestnetNode(..)
2323
, nodeSocketPath
24+
, node0ConnectionInfo
2425
, isTestnetNodeSpo
2526
, SpoNodeKeys(..)
2627
, Delegator(..)
@@ -72,7 +73,9 @@ import qualified System.Process as IO
7273

7374
import Testnet.Start.Types
7475

76+
import Hedgehog (MonadTest)
7577
import qualified Hedgehog as H
78+
import qualified Hedgehog.Extras as H
7679
import qualified Hedgehog.Extras.Stock as H
7780
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
7881

@@ -114,7 +117,7 @@ data SKey k
114117
data TestnetRuntime = TestnetRuntime
115118
{ configurationFile :: !(NodeConfigFile In)
116119
, shelleyGenesisFile :: !FilePath
117-
, testnetMagic :: !Int
120+
, testnetMagic :: !Int -- TODO change to Word32
118121
, testnetNodes :: ![TestnetNode]
119122
, wallets :: ![PaymentKeyInfo]
120123
, delegators :: ![Delegator]
@@ -147,6 +150,18 @@ isTestnetNodeSpo = isJust . poolKeys
147150
nodeSocketPath :: TestnetNode -> SocketPath
148151
nodeSocketPath = File . H.sprocketSystemName . nodeSprocket
149152

153+
-- | Connection data for the first node in the testnet
154+
node0ConnectionInfo :: MonadTest m => TestnetRuntime -> m LocalNodeConnectInfo
155+
node0ConnectionInfo TestnetRuntime{testnetMagic, testnetNodes} = do
156+
case testnetNodes of
157+
[] -> H.note_ "There are no nodes in the testnet" >> H.failure
158+
node0:_ -> do
159+
pure LocalNodeConnectInfo
160+
{ localNodeSocketPath= nodeSocketPath node0
161+
, localNodeNetworkId=Testnet (NetworkMagic $ fromIntegral testnetMagic)
162+
, localConsensusModeParams=CardanoModeParams $ EpochSlots 21600}
163+
164+
150165
data StakingKey
151166
data SpoColdKey
152167

@@ -189,7 +204,7 @@ getStartTime
189204
=> HasCallStack
190205
=> FilePath
191206
-> TestnetRuntime
192-
-> m UTCTime
207+
-> m UTCTime -- TODO change to SystemStart
193208
getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do
194209
byronGenesisFile <-
195210
decodeNodeConfiguration configurationFile >>= \case
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{-# LANGUAGE NamedFieldPuns #-}
2+
{-# LANGUAGE NumericUnderscores #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
6+
module Cardano.Testnet.Test.Api.TxSupplementalDatum
7+
( hprop_tx_supp_datum
8+
)
9+
where
10+
11+
import Cardano.Api
12+
import qualified Cardano.Api.Ledger as L
13+
import qualified Cardano.Api.Network as Net
14+
import Cardano.Api.Shelley
15+
16+
import Cardano.CLI.Type.Common
17+
import Cardano.Crypto.Hash.Class (hashToStringAsHex)
18+
import qualified Cardano.Ledger.Core as L
19+
import Cardano.Testnet
20+
21+
import Prelude
22+
23+
import Control.Monad
24+
import Data.Default.Class
25+
import qualified Data.Text as Text
26+
import GHC.Exts (IsList (..))
27+
import Lens.Micro
28+
import System.FilePath ((</>))
29+
import qualified System.Info as SYS
30+
31+
import Testnet.Components.Configuration
32+
import Testnet.Components.Query
33+
import Testnet.Components.Query (findLargestUtxoWithAddress, findUtxosWithAddress,
34+
getEpochStateView, waitForBlocks)
35+
import Testnet.Process.Run
36+
import Testnet.Property.Util (integrationRetryWorkspace)
37+
import Testnet.Types
38+
39+
import Hedgehog (Property, (===))
40+
import qualified Hedgehog as H
41+
import qualified Hedgehog.Extras.Test.Base as H
42+
import qualified Hedgehog.Extras.Test.File as H
43+
import qualified Hedgehog.Extras.Test.TestWatchdog as H
44+
45+
hprop_tx_supp_datum :: Property
46+
hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
47+
conf@Conf{tempAbsPath} <- mkConf tempAbsBasePath'
48+
let tempAbsPath' = unTmpAbsPath tempAbsPath
49+
work <- H.createDirectoryIfMissing $ tempAbsPath' </> "work"
50+
51+
let ceo = ConwayEraOnwardsConway
52+
sbe = convert ceo
53+
era = toCardanoEra sbe
54+
cEra = AnyCardanoEra era
55+
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
56+
options = def{cardanoNodeEra = AnyShelleyBasedEra sbe}
57+
58+
tr@TestnetRuntime
59+
{ configurationFile
60+
, testnetMagic
61+
, testnetNodes=node0:_
62+
, wallets = wallet0 : _
63+
} <-
64+
cardanoTestnetDefault options def conf
65+
66+
systemStart <- fmap SystemStart . H.noteShowM $ getStartTime tempAbsPath' tr
67+
epochStateView <- getEpochStateView configurationFile (nodeSocketPath node0)
68+
connectionInfo <- node0ConnectionInfo tr
69+
pparams <- getProtocolParams epochStateView ceo
70+
71+
eraHistory <- (H.leftFail <=< H.leftFailM) . H.evalIO $ executeLocalStateQueryExpr connectionInfo Net.VolatileTip $
72+
queryEraHistory
73+
let epochInfo = toLedgerEpochInfo eraHistory
74+
75+
H.failure
76+
77+
let witnesses = undefined
78+
79+
let content =
80+
defaultTxBodyContent sbe
81+
& setTxIns undefined
82+
& setTxOuts undefined
83+
& setTxProtocolParams (pure $ pure pparams)
84+
85+
BalancedTxBody _ txBody _ _ <-
86+
H.leftFail $
87+
makeTransactionBodyAutoBalance
88+
sbe
89+
systemStart
90+
epochInfo
91+
pparams
92+
mempty
93+
mempty
94+
mempty
95+
undefined -- UTXO
96+
content
97+
undefined -- changeaddr
98+
Nothing -- keys override
99+
100+
let tx = makeSignedTransaction witnesses txBody
101+
102+
submitTxToNodeLocal connectionInfo (TxInMode sbe tx)
103+
104+
H.failure

cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Main
55
) where
66

77
import qualified Cardano.Crypto.Init as Crypto
8+
import qualified Cardano.Testnet.Test.Api.TxSupplementalDatum
89
import qualified Cardano.Testnet.Test.Cli.Conway.Plutus
910
import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo
1011
import qualified Cardano.Testnet.Test.Cli.Query
@@ -74,6 +75,8 @@ tests = do
7475
, T.testGroup "Plutus"
7576
[ ignoreOnWindows "PlutusV3" Cardano.Testnet.Test.Cli.Conway.Plutus.hprop_plutus_v3]
7677
]
78+
, T.testGroup "API"
79+
[ignoreOnWindows "transaction with supplemental datum" Cardano.Testnet.Test.Api.TxSupplementalDatum.hprop_tx_supp_datum]
7780
, T.testGroup "CLI"
7881
[ ignoreOnWindows "Shutdown" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdown
7982
-- ShutdownOnSigint fails on Mac with

0 commit comments

Comments
 (0)