11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE NamedFieldPuns #-}
3+ {-# LANGUAGE NumericUnderscores #-}
34{-# LANGUAGE OverloadedLabels #-}
45{-# LANGUAGE OverloadedLists #-}
56{-# LANGUAGE OverloadedStrings #-}
67{-# LANGUAGE ScopedTypeVariables #-}
78{-# LANGUAGE TypeApplications #-}
9+ {-# LANGUAGE TypeOperators #-}
810
911module Cardano.Testnet.Test.Rpc.Transaction
1012 ( hprop_rpc_transaction
@@ -20,22 +22,27 @@ import qualified Cardano.Ledger.Binary.Version as L
2022import qualified Cardano.Ledger.Conway.Core as L
2123import qualified Cardano.Ledger.Conway.PParams as L
2224import qualified Cardano.Ledger.Plutus as L
25+ import Cardano.Rpc.Client (Proto )
2326import qualified Cardano.Rpc.Client as Rpc
2427import qualified Cardano.Rpc.Proto.Api.UtxoRpc.Query as UtxoRpc
2528import Cardano.Rpc.Server.Internal.UtxoRpc.Query ()
2629import Cardano.Testnet
2730
2831import Prelude
2932
33+ import Control.Monad
3034import qualified Data.ByteString.Short as SBS
3135import Data.Default.Class
3236import qualified Data.Map.Strict as M
37+ import qualified Data.Text.Encoding as T
38+ import GHC.Stack
3339import Lens.Micro
3440
3541import Testnet.Components.Query
3642import Testnet.Process.Run
3743import Testnet.Property.Util (integrationRetryWorkspace )
3844import Testnet.Start.Types
45+ import Testnet.Types
3946
4047import Hedgehog
4148import qualified Hedgehog as H
@@ -47,7 +54,8 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
4754 conf@ Conf {tempAbsPath} <- mkConf tempAbsBasePath'
4855 let tempAbsPath' = unTmpAbsPath tempAbsPath
4956
50- let ceo = ConwayEraOnwardsConway
57+ let (ceo, eraProxy) =
58+ (conwayBasedEra, asType) :: era ~ ConwayEra => (ConwayEraOnwards era , AsType era )
5159 sbe = convert ceo
5260 eraName = eraToString sbe
5361 options = def{cardanoNodeEra = AnyShelleyBasedEra sbe, cardanoEnableRpc = True }
@@ -56,17 +64,32 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
5664 { testnetMagic
5765 , configurationFile
5866 , testnetNodes = node0@ TestnetNode {nodeSprocket} : _
67+ , wallets = wallet0@ (PaymentKeyInfo _ addrTxt0) : (PaymentKeyInfo _ addrTxt1) : _
5968 } <-
6069 createAndRunTestnet options def conf
6170
6271 execConfig <- mkExecConfig tempAbsPath' nodeSprocket testnetMagic
6372 epochStateView <- getEpochStateView configurationFile (nodeSocketPath node0)
64- pparams <- unLedgerProtocolParameters <$> getProtocolParams epochStateView ceo
73+
6574 -- H.noteShowPretty_ pparams
6675 utxos <- findAllUtxos epochStateView sbe
6776 H. noteShowPretty_ utxos
6877 rpcSocket <- H. note . unFile $ nodeRpcSocketPath node0
6978
79+ -- prepare tx inputs and output address
80+ H. noteShow_ addrTxt0
81+ addr0 <- H. nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt0
82+
83+ H. noteShow_ addrTxt1
84+ addr1 <- H. nothingFail $ deserialiseAddress (AsAddressInEra eraProxy) addrTxt1
85+
86+ -- read key witnesses
87+ wit0 :: ShelleyWitnessSigningKey <-
88+ H. leftFailM . H. evalIO $
89+ readFileTextEnvelopeAnyOf
90+ [FromSomeType asType WitnessGenesisUTxOKey ]
91+ (signingKey $ paymentKeyInfoPair wallet0)
92+
7093 --------------
7194 -- RPC queries
7295 --------------
@@ -77,8 +100,31 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
77100 Rpc. nonStreaming conn (Rpc. rpc @ (Rpc. Protobuf UtxoRpc. QueryService " readParams" )) req
78101
79102 utxos' <- do
80- let req = Rpc. defMessage
103+ let req = Rpc. defMessage & # addresses . # items .~ [ T. encodeUtf8 addrTxt0]
81104 Rpc. nonStreaming conn (Rpc. rpc @ (Rpc. Protobuf UtxoRpc. QueryService " readUtxos" )) req
82105 pure (pparams', utxos')
83106
107+ txIn0: _ <- mapM (txoRefToTxIn . (^. # txoRef)) $ utxosResponse ^. # items
108+
109+
110+ let txOut = TxOut addr1 (lovelaceToTxOutValue sbe 200_000_000 ) TxOutDatumNone ReferenceScriptNone
111+ content =
112+ defaultTxBodyContent sbe
113+ & setTxIns [(txIn0, pure $ KeyWitness KeyWitnessForSpending )]
114+ & setTxFee (TxFeeExplicit sbe 500 )
115+ & setTxOuts [txOut]
116+ & setTxProtocolParams (pure $ pure undefined )
117+
118+ txBody <- H. leftFail $ createTransactionBody sbe content
119+
120+ let signedTx = signShelleyTransaction sbe txBody [wit0]
121+ txId <- H. noteShow . getTxId $ getTxBody signedTx
122+
123+ H. noteShowPretty_ utxosResponse
124+
84125 H. failure
126+
127+ txoRefToTxIn :: (HasCallStack , MonadTest m ) => Proto UtxoRpc. TxoRef -> m TxIn
128+ txoRefToTxIn r = withFrozenCallStack $ do
129+ txId' <- H. leftFail $ deserialiseFromRawBytes AsTxId $ r ^. # hash
130+ pure $ TxIn txId' (TxIx . fromIntegral $ r ^. # index)
0 commit comments