diff --git a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs index e6b75ba0318..24b24b5951c 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs @@ -150,7 +150,7 @@ readLeaderCredentialsSingleton shelleyKESFile = Just kesFile } = do vrfSKey <- - firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsVrfKey) (File vrfFile)) + firstExceptT FileError (newExceptT $ readFileTextEnvelope (File vrfFile)) (opCert, kesSKey) <- opCertKesKeyCheck (File kesFile) (File opCertFile) @@ -172,9 +172,9 @@ opCertKesKeyCheck -> ExceptT PraosLeaderCredentialsError IO (OperationalCertificate, SigningKey KesKey) opCertKesKeyCheck kesFile certFile = do opCert <- - firstExceptT FileError (newExceptT $ readFileTextEnvelope AsOperationalCertificate certFile) + firstExceptT FileError (newExceptT $ readFileTextEnvelope certFile) kesSKey <- - firstExceptT FileError (newExceptT $ readFileTextEnvelope (AsSigningKey AsKesKey) kesFile) + firstExceptT FileError (newExceptT $ readFileTextEnvelope kesFile) let opCertSpecifiedKesKeyhash = verificationKeyHash $ getHotKey opCert suppliedKesKeyHash = verificationKeyHash $ getVerificationKey kesSKey -- Specified KES key in operational certificate should match the one @@ -201,9 +201,9 @@ readLeaderCredentialsBulk ProtocolFilepaths { shelleyBulkCredsFile = mfp } = -> ExceptT PraosLeaderCredentialsError IO (ShelleyLeaderCredentials StandardCrypto) parseShelleyCredentials ShelleyCredentials { scCert, scVrf, scKes } = do mkPraosLeaderCredentials - <$> parseEnvelope AsOperationalCertificate scCert - <*> parseEnvelope (AsSigningKey AsVrfKey) scVrf - <*> parseEnvelope (AsSigningKey AsKesKey) scKes + <$> parseEnvelope scCert + <*> parseEnvelope scVrf + <*> parseEnvelope scKes readBulkFile :: Maybe FilePath @@ -246,12 +246,11 @@ mkPraosLeaderCredentials parseEnvelope :: HasTextEnvelope a - => AsType a - -> (TextEnvelope, String) + => (TextEnvelope, String) -> ExceptT PraosLeaderCredentialsError IO a -parseEnvelope as (te, loc) = +parseEnvelope (te, loc) = firstExceptT (FileError . Api.FileError loc) . hoistEither $ - deserialiseFromTextEnvelope as te + deserialiseFromTextEnvelope te ------------------------------------------------------------------------------ diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index d3cfa2a3977..c0921f7bf35 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -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.TxSupplementalDatum + Cardano.Testnet.Test.Cli.Conway.StakeSnapshot Cardano.Testnet.Test.Cli.KesPeriodInfo Cardano.Testnet.Test.Cli.LeadershipSchedule Cardano.Testnet.Test.Cli.Query diff --git a/cardano-testnet/src/Testnet/Components/Query.hs b/cardano-testnet/src/Testnet/Components/Query.hs index 4ebcfd4bf1d..a41ddbd1d7f 100644 --- a/cardano-testnet/src/Testnet/Components/Query.hs +++ b/cardano-testnet/src/Testnet/Components/Query.hs @@ -36,6 +36,7 @@ module Testnet.Components.Query , checkDRepsNumber , checkDRepState , assertNewEpochState + , getProtocolParams , getGovActionLifetime , getKeyDeposit , getDelegationState @@ -44,7 +45,8 @@ module Testnet.Components.Query import Cardano.Api as Api import Cardano.Api.Ledger (Credential, DRepState, EpochInterval (..), KeyRole (DRepRole)) -import Cardano.Api.Shelley (ShelleyLedgerEra) +import Cardano.Api.Shelley (LedgerProtocolParameters (..), ShelleyLedgerEra, + fromShelleyTxIn, fromShelleyTxOut) import qualified Cardano.Api.Ledger as L import Cardano.Crypto.Hash (hashToStringAsHex) @@ -558,6 +560,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 diff --git a/cardano-testnet/src/Testnet/Types.hs b/cardano-testnet/src/Testnet/Types.hs index 8c17af6e04e..2c9eef065fb 100644 --- a/cardano-testnet/src/Testnet/Types.hs +++ b/cardano-testnet/src/Testnet/Types.hs @@ -21,6 +21,7 @@ module Testnet.Types , testnetSprockets , TestnetNode(..) , nodeSocketPath + , node0ConnectionInfo , isTestnetNodeSpo , SpoNodeKeys(..) , Delegator(..) @@ -62,7 +63,6 @@ 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 @@ -73,7 +73,9 @@ 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 (..)) @@ -115,7 +117,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] @@ -148,6 +150,18 @@ isTestnetNodeSpo = isJust . poolKeys nodeSocketPath :: TestnetNode -> SocketPath nodeSocketPath = File . H.sprocketSystemName . nodeSprocket +-- | Connection data for the first node in the testnet +node0ConnectionInfo :: MonadTest m => TestnetRuntime -> m LocalNodeConnectInfo +node0ConnectionInfo TestnetRuntime{testnetMagic, testnetNodes} = do + case testnetNodes of + [] -> H.note_ "There are no nodes in the testnet" >> H.failure + node0:_ -> do + pure LocalNodeConnectInfo + { localNodeSocketPath= nodeSocketPath node0 + , localNodeNetworkId=Testnet (NetworkMagic $ fromIntegral testnetMagic) + , localConsensusModeParams=CardanoModeParams $ EpochSlots 21600} + + data SpoNodeKeys = SpoNodeKeys { poolNodeKeysCold :: KeyPair StakePoolKey , poolNodeKeysVrf :: KeyPair VrfKey @@ -187,14 +201,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 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxSupplementalDatum.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxSupplementalDatum.hs new file mode 100644 index 00000000000..d1a385440da --- /dev/null +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxSupplementalDatum.hs @@ -0,0 +1,233 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Cardano.Testnet.Test.Api.TxSupplementalDatum + ( hprop_tx_supp_datum + ) +where + +import Cardano.Api +import qualified Cardano.Api.Ledger as L +import qualified Cardano.Api.Network as Net +import qualified Cardano.Api.Network as Net.Tx +import Cardano.Api.Shelley + +import Cardano.Testnet + +import Prelude + +import Control.Monad +import Data.Bifunctor (second) +import Data.Default.Class +import qualified Data.Map.Strict as M +import Data.Proxy +import Data.Set (Set) +import GHC.Exts (IsList (..)) +import GHC.Stack +import Lens.Micro + +import Testnet.Components.Query +import Testnet.Property.Util (integrationRetryWorkspace) +import Testnet.Types + +import Hedgehog +import qualified Hedgehog as H +import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.TestWatchdog as H + +hprop_tx_supp_datum :: Property +hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do + conf@Conf{tempAbsPath} <- mkConf tempAbsBasePath' + let tempAbsPath' = unTmpAbsPath tempAbsPath + + let ceo = ConwayEraOnwardsConway + beo = convert ceo + sbe = convert ceo + eraProxy = proxyToAsType Proxy + options = def{cardanoNodeEra = AnyShelleyBasedEra sbe} + + tr@TestnetRuntime + { configurationFile + , testnetNodes = node0 : _ + , wallets = wallet0@(PaymentKeyInfo _ addrTxt0) : wallet1 : _ + } <- + cardanoTestnetDefault options def conf + + systemStart <- H.noteShowM $ getStartTime tempAbsPath' tr + epochStateView <- getEpochStateView configurationFile (nodeSocketPath node0) + connectionInfo <- node0ConnectionInfo tr + pparams <- getProtocolParams epochStateView ceo + + -- prepare tx inputs and output address + H.noteShow_ addrTxt0 + addr0 <- H.nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt0 + + let (PaymentKeyInfo _ addrTxt1) = wallet1 + H.noteShow_ addrTxt1 + addr1 <- H.nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt1 + + -- read key witnesses + [wit0, wit1] :: [ShelleyWitnessSigningKey] <- + forM [wallet0, wallet1] $ \wallet -> + H.leftFailM . H.evalIO $ + readFileTextEnvelopeAnyOf + [FromSomeType (proxyToAsType Proxy) WitnessGenesisUTxOKey] + (signingKey $ paymentKeyInfoPair wallet) + + -- query node for era history + epochInfo <- + (H.leftFail <=< H.leftFailM) . H.evalIO $ + executeLocalStateQueryExpr connectionInfo Net.VolatileTip $ + fmap toLedgerEpochInfo <$> queryEraHistory + + let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes "CAFEBABE" + scriptData2 = unsafeHashableScriptData $ ScriptDataBytes "DEADBEEF" + scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "FEEDCOFFEE" + -- 4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23 + H.noteShow_ $ hashScriptDataBytes scriptData1 + -- 24f56ef6459a29416df2e89d8df944e29591220283f198d39f7873917b8fa7c1 + H.noteShow_ $ hashScriptDataBytes scriptData2 + -- 5e47eaf4f0a604fcc939076f74ce7ed59d1503738973522e4d9cb99db703dcb8 + H.noteShow_ $ hashScriptDataBytes scriptData3 + let txDatum1 = + TxOutDatumHash + (convert beo) + (hashScriptDataBytes scriptData1) + txDatum2 = TxOutDatumInline beo scriptData2 + txDatum3 = TxOutSupplementalDatum (convert beo) scriptData3 + + -- Build a first transaction with txout supplemental data + tx1Utxo <- do + txIn <- findLargestUtxoForPaymentKey epochStateView sbe wallet0 + + -- prepare txout + let txOutValue = lovelaceToTxOutValue sbe 100_000_000 + txOuts = + [ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone + , TxOut addr1 txOutValue txDatum2 ReferenceScriptNone + , TxOut addr1 txOutValue txDatum3 ReferenceScriptNone + ] + + -- build a transaction + content = + defaultTxBodyContent sbe + & setTxIns [(txIn, pure $ KeyWitness KeyWitnessForSpending)] + & setTxOuts txOuts + & setTxProtocolParams (pure $ pure pparams) + + utxo <- UTxO <$> findAllUtxos epochStateView sbe + + BalancedTxBody _ txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) _ fee <- + H.leftFail $ + makeTransactionBodyAutoBalance + sbe + systemStart + epochInfo + pparams + mempty + mempty + mempty + utxo + content + addr0 + Nothing -- keys override + H.noteShow_ fee + + H.noteShowPretty_ lbody + + let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData + -- TODO: only inline datum gets included here, but should be all of them + -- TODO what's the actual purpose of TxSupplementalDatum - can we remove it? + -- TODO adding all datums breaks script integrity hash, might have to manually compute it? + -- https://github.com/tweag/cooked-validators/blob/9cb80810d982c9eccd3f7710a996d20f944a95ec/src/Cooked/MockChain/GenerateTx/Body.hs#L127 + -- + -- TODO getDataHashBabbageTxOut excludes inline datums - WHY IT HAPPENS ONLY HERE BUT NOT WHEN CALLING CLI? + + -- TODO add scriptData1 when datum can be provided to transaction building + -- [ scriptData2 + -- , scriptData3 + -- ] + -- === bodyScriptData + + let tx = signShelleyTransaction sbe txBody [wit0] + txId <- H.noteShow . getTxId $ getTxBody tx + + H.noteShowPretty_ tx + + submitTx sbe connectionInfo tx + + -- wait till transaction gets included in the block + _ <- waitForBlocks epochStateView 1 + + -- test if it's in UTxO set + utxo1 <- findAllUtxos epochStateView sbe + txUtxo <- H.noteShowPretty $ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + (length txOuts + 1) === length txUtxo + + let chainTxOuts = + reverse + . drop 1 + . reverse + . map snd + . toList + $ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + + (toCtxUTxOTxOut <$> txOuts) === chainTxOuts + + pure txUtxo + + do + [(txIn1, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo + -- H.noteShowPretty_ tx1Utxo + [(txIn2, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo + + let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE" + txDatum = TxOutDatumInline beo scriptData4 + txOutValue = lovelaceToTxOutValue sbe 99_999_500 + txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone + + let content = + defaultTxBodyContent sbe + & setTxIns [(txIn1, pure $ KeyWitness KeyWitnessForSpending)] + & setTxInsReference (TxInsReference beo [txIn2]) + & setTxFee (TxFeeExplicit sbe 500) + & setTxOuts [txOut] + + txBody@(ShelleyTxBody _ _ _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) <- + H.leftFail $ createTransactionBody sbe content + let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData + [scriptData1, scriptData2, scriptData3] === bodyScriptData + + let tx = signShelleyTransaction sbe txBody [wit1] + -- H.noteShowPretty_ tx + txId <- H.noteShow . getTxId $ getTxBody tx + + submitTx sbe connectionInfo tx + + -- wait till transaction gets included in the block + _ <- waitForBlocks epochStateView 1 + + -- test if it's in UTxO set + utxo1 <- findAllUtxos epochStateView sbe + let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1 + [toCtxUTxOTxOut txOut] === M.elems txUtxo + + H.failure + +submitTx + :: MonadTest m + => MonadIO m + => HasCallStack + => ShelleyBasedEra era + -> LocalNodeConnectInfo + -> Tx era + -> m () +submitTx sbe connectionInfo tx = + withFrozenCallStack $ + H.evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \case + Net.Tx.SubmitFail reason -> H.noteShowPretty_ reason >> H.failure + Net.Tx.SubmitSuccess -> H.success diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs index 8b45d8078a4..3fa3bd47dd1 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Query.hs @@ -128,7 +128,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H. -- leadership-schedule do let spoKeys = Defaults.defaultSpoKeys 1 - spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work $ verificationKey $ poolNodeKeysCold spoKeys + spoVerificationKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work $ verificationKey $ poolNodeKeysCold spoKeys H.noteM_ $ execCli' execConfig [ eraName, "query", "leadership-schedule" , "--genesis", shelleyGeneisFile , "--stake-pool-verification-key", T.unpack $ serialiseToBech32 spoVerificationKey @@ -244,7 +244,7 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H. fileQueryAmount <- H.evalMaybe $ fileQueryResult ^? Aeson.nth 0 . Aeson.nth 1 . Aeson._Number -- Query individual SPO using SPOs bech32 of key and compare to previous result - delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile AsStakePoolKey work spoKey + delegatorVKey :: VerificationKey StakePoolKey <- readVerificationKeyFromFile work spoKey keyQueryResult :: Aeson.Value <- execCliStdoutToJson execConfig [ eraName, "query", "spo-stake-distribution" , "--spo-verification-key", T.unpack $ serialiseToBech32 delegatorVKey ] @@ -449,6 +449,10 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H. -- TODO @cardano-cli team pure () + TestQueryEraHistoryCmd -> do + -- TODO @cardano-cli team + pure () + where -- | Wait for the part of the epoch when futurePParams are known waitForFuturePParamsToStabilise @@ -482,13 +486,19 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H. minSlotInThisEpochToWaitTo = firstSlotOfEpoch + slotsInEpochToWaitOut + 1 in slotNo >= minSlotInThisEpochToWaitTo - readVerificationKeyFromFile :: (HasCallStack, MonadIO m, MonadCatch m, MonadTest m, HasTextEnvelope (VerificationKey keyrole), SerialiseAsBech32 (VerificationKey keyrole)) - => AsType keyrole - -> FilePath + readVerificationKeyFromFile + :: ( HasCallStack + , MonadIO m + , MonadCatch m + , MonadTest m + , HasTextEnvelope (VerificationKey keyrole) + , SerialiseAsBech32 (VerificationKey keyrole) + ) + => FilePath -> File content direction -> m (VerificationKey keyrole) - readVerificationKeyFromFile asKey work = - H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile asKey . VerificationKeyFilePath . File . (work ) . unFile + readVerificationKeyFromFile work = + H.evalEitherM . liftIO . runExceptT . readVerificationKeyOrFile . VerificationKeyFilePath . File . (work ) . unFile _verificationStakeKeyToStakeAddress :: Int -> VerificationKey StakeKey -> StakeAddress _verificationStakeKeyToStakeAddress testnetMagic delegatorVKey = diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs index d7903e05c0f..bcd31bd142e 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/QuerySlotNumber.hs @@ -14,6 +14,7 @@ module Cardano.Testnet.Test.Cli.QuerySlotNumber import Cardano.Ledger.Shelley.Genesis (fromNominalDiffTimeMicro) import Cardano.Slotting.Slot +import Cardano.Slotting.Time (SystemStart (..)) import Cardano.Testnet import Prelude @@ -47,7 +48,7 @@ hprop_querySlotNumber = integrationRetryWorkspace 2 "query-slot-number" $ \tempA , testnetNodes } <- cardanoTestnetDefault def def conf ShelleyGenesis{sgSlotLength, sgEpochLength} <- H.noteShowM $ shelleyGenesis tr - startTime <- H.noteShowM $ getStartTime tempAbsBasePath' tr + SystemStart startTime <- H.noteShowM $ getStartTime tempAbsBasePath' tr let slotLength = fromNominalDiffTimeMicro sgSlotLength -- how many slots can the checked value differ from diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs index 8a00b95f47b..eb848e32342 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Transaction.hs @@ -52,7 +52,6 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te let sbe = ShelleyBasedEraConway - txEra = AsConwayEra era = toCardanoEra sbe cEra = AnyCardanoEra era tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath' @@ -84,24 +83,31 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te (txin1, TxOut _addr outValue _datum _refScript) <- H.nothingFailM $ findLargestUtxoWithAddress epochStateView sbe (paymentKeyInfoAddr wallet0) let (L.Coin initialAmount) = txOutValueToLovelace outValue + -- TODO those three datums are going into the TX - do we need three different flags? + let transferAmount = 5_000_001 void $ execCli' execConfig [ anyEraToString cEra, "transaction", "build" , "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0 , "--tx-in", Text.unpack $ renderTxIn txin1 , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-datum-hash" ,"4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23" + , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-datum-embed-value" ,"\"EMBEDVALUE\"" + , "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount + , "--tx-out-inline-datum-value" ,"\"INLINEVALUE\"" , "--out-file", txbodyFp ] cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp - apiTx <- H.evalEither $ deserialiseFromTextEnvelope (AsTx txEra) cddlUnwitnessedTx - let txFee = L.unCoin $ extractTxFee apiTx + apiTx <- H.evalEither $ deserialiseFromTextEnvelope cddlUnwitnessedTx + let txFee = L.unCoin $ extractTxFee sbe apiTx -- This is the current calculated fee. -- It's a sanity check to see if anything has -- changed regarding fee calculation. -- 8.10 changed fee from 228 -> 330 -- 9.2 changed fee from 330 -> 336 - 336 === txFee + -- 336 === txFee void $ execCli' execConfig [ anyEraToString cEra, "transaction", "sign" @@ -133,6 +139,6 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te txOutValue :: TxOut ctx era -> TxOutValue era txOutValue (TxOut _ v _ _) = v -extractTxFee :: Tx era -> L.Coin -extractTxFee (ShelleyTx sbe ledgerTx) = +extractTxFee :: ShelleyBasedEra era -> Tx era -> L.Coin +extractTxFee _ (ShelleyTx sbe ledgerTx) = shelleyBasedEraConstraints sbe $ ledgerTx ^. (L.bodyTxL . L.feeTxBodyL) diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs index b2252c3fb29..df6a6e7b6e9 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs @@ -97,7 +97,7 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat CommitteeColdKeyHash comKeyHash1 <- H.evalEither - $ deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) + $ deserialiseFromRawBytesHex $ BSC.pack comKeyHash1Str let comKeyCred1 = L.KeyHashObj comKeyHash1 diff --git a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs index cb67051f18a..2c828dcb2c9 100644 --- a/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs +++ b/cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DisambiguateRecordFields #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} diff --git a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs index 96b53a18fb3..263061e8b58 100644 --- a/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs +++ b/cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs @@ -5,6 +5,7 @@ module Main ) where import qualified Cardano.Crypto.Init as Crypto +import qualified Cardano.Testnet.Test.Api.TxSupplementalDatum import qualified Cardano.Testnet.Test.Cli.KesPeriodInfo import qualified Cardano.Testnet.Test.Cli.Query import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber @@ -82,6 +83,8 @@ tests = do ] ] ] + , T.testGroup "API" + [ignoreOnWindows "transaction with supplemental datum" Cardano.Testnet.Test.Api.TxSupplementalDatum.hprop_tx_supp_datum] , T.testGroup "CLI" [ ignoreOnWindows "Shutdown" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdown -- ShutdownOnSigint fails on Mac with