1
1
{-# LANGUAGE DataKinds #-}
2
2
{-# LANGUAGE NamedFieldPuns #-}
3
+ {-# LANGUAGE NumericUnderscores #-}
3
4
{-# LANGUAGE OverloadedLabels #-}
4
5
{-# LANGUAGE OverloadedLists #-}
5
6
{-# LANGUAGE OverloadedStrings #-}
6
7
{-# LANGUAGE ScopedTypeVariables #-}
7
8
{-# LANGUAGE TypeApplications #-}
9
+ {-# LANGUAGE TypeOperators #-}
8
10
9
11
module Cardano.Testnet.Test.Rpc.Transaction
10
12
( hprop_rpc_transaction
@@ -20,22 +22,27 @@ import qualified Cardano.Ledger.Binary.Version as L
20
22
import qualified Cardano.Ledger.Conway.Core as L
21
23
import qualified Cardano.Ledger.Conway.PParams as L
22
24
import qualified Cardano.Ledger.Plutus as L
25
+ import Cardano.Rpc.Client (Proto )
23
26
import qualified Cardano.Rpc.Client as Rpc
24
27
import qualified Cardano.Rpc.Proto.Api.UtxoRpc.Query as UtxoRpc
25
28
import Cardano.Rpc.Server.Internal.UtxoRpc.Query ()
26
29
import Cardano.Testnet
27
30
28
31
import Prelude
29
32
33
+ import Control.Monad
30
34
import qualified Data.ByteString.Short as SBS
31
35
import Data.Default.Class
32
36
import qualified Data.Map.Strict as M
37
+ import qualified Data.Text.Encoding as T
38
+ import GHC.Stack
33
39
import Lens.Micro
34
40
35
41
import Testnet.Components.Query
36
42
import Testnet.Process.Run
37
43
import Testnet.Property.Util (integrationRetryWorkspace )
38
44
import Testnet.Start.Types
45
+ import Testnet.Types
39
46
40
47
import Hedgehog
41
48
import qualified Hedgehog as H
@@ -47,7 +54,8 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
47
54
conf@ Conf {tempAbsPath} <- mkConf tempAbsBasePath'
48
55
let tempAbsPath' = unTmpAbsPath tempAbsPath
49
56
50
- let ceo = ConwayEraOnwardsConway
57
+ let (ceo, eraProxy) =
58
+ (conwayBasedEra, asType) :: era ~ ConwayEra => (ConwayEraOnwards era , AsType era )
51
59
sbe = convert ceo
52
60
eraName = eraToString sbe
53
61
options = def{cardanoNodeEra = AnyShelleyBasedEra sbe, cardanoEnableRpc = True }
@@ -56,17 +64,32 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
56
64
{ testnetMagic
57
65
, configurationFile
58
66
, testnetNodes = node0@ TestnetNode {nodeSprocket} : _
67
+ , wallets = wallet0@ (PaymentKeyInfo _ addrTxt0) : (PaymentKeyInfo _ addrTxt1) : _
59
68
} <-
60
69
createAndRunTestnet options def conf
61
70
62
71
execConfig <- mkExecConfig tempAbsPath' nodeSprocket testnetMagic
63
72
epochStateView <- getEpochStateView configurationFile (nodeSocketPath node0)
64
- pparams <- unLedgerProtocolParameters <$> getProtocolParams epochStateView ceo
73
+
65
74
-- H.noteShowPretty_ pparams
66
75
utxos <- findAllUtxos epochStateView sbe
67
76
H. noteShowPretty_ utxos
68
77
rpcSocket <- H. note . unFile $ nodeRpcSocketPath node0
69
78
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
+
70
93
--------------
71
94
-- RPC queries
72
95
--------------
@@ -77,8 +100,31 @@ hprop_rpc_transaction = integrationRetryWorkspace 2 "rpc-tx" $ \tempAbsBasePath'
77
100
Rpc. nonStreaming conn (Rpc. rpc @ (Rpc. Protobuf UtxoRpc. QueryService " readParams" )) req
78
101
79
102
utxos' <- do
80
- let req = Rpc. defMessage
103
+ let req = Rpc. defMessage & # addresses . # items .~ [ T. encodeUtf8 addrTxt0]
81
104
Rpc. nonStreaming conn (Rpc. rpc @ (Rpc. Protobuf UtxoRpc. QueryService " readUtxos" )) req
82
105
pure (pparams', utxos')
83
106
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
+
84
125
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