Skip to content

Commit 0004d02

Browse files
committed
wip - submitTx test
1 parent 724d4b4 commit 0004d02

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Rpc/Query.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,6 @@ hprop_rpc_query_pparams = integrationRetryWorkspace 2 "rpc-query-pparams" $ \tem
177177
-- Test readUtxos response
178178
--------------------------
179179

180-
H.noteShowPretty $ utxos
181-
H.noteShowPretty $ utxosResponse
180+
_ <- H.noteShowPretty $ utxos
181+
_ <- H.noteShowPretty $ utxosResponse
182182
H.failure

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Rpc/Transaction.hs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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

911
module Cardano.Testnet.Test.Rpc.Transaction
1012
( hprop_rpc_transaction
@@ -20,22 +22,27 @@ import qualified Cardano.Ledger.Binary.Version as L
2022
import qualified Cardano.Ledger.Conway.Core as L
2123
import qualified Cardano.Ledger.Conway.PParams as L
2224
import qualified Cardano.Ledger.Plutus as L
25+
import Cardano.Rpc.Client (Proto)
2326
import qualified Cardano.Rpc.Client as Rpc
2427
import qualified Cardano.Rpc.Proto.Api.UtxoRpc.Query as UtxoRpc
2528
import Cardano.Rpc.Server.Internal.UtxoRpc.Query ()
2629
import Cardano.Testnet
2730

2831
import Prelude
2932

33+
import Control.Monad
3034
import qualified Data.ByteString.Short as SBS
3135
import Data.Default.Class
3236
import qualified Data.Map.Strict as M
37+
import qualified Data.Text.Encoding as T
38+
import GHC.Stack
3339
import Lens.Micro
3440

3541
import Testnet.Components.Query
3642
import Testnet.Process.Run
3743
import Testnet.Property.Util (integrationRetryWorkspace)
3844
import Testnet.Start.Types
45+
import Testnet.Types
3946

4047
import Hedgehog
4148
import 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

Comments
 (0)